From aa4b7f922fa17a75ad42fe0d82c3c71a38577de2 Mon Sep 17 00:00:00 2001 From: marschap Date: Sat, 29 Apr 2006 13:47:56 +0000 Subject: [PATCH] document bignum library; fix and shrink bignum library (both S. Herdler) --- docs/lcdproc-dev/make-driver.docbook | 87 ++++++++++++++++++++++++++++ server/drivers/adv_bignum.c | 34 +++++------ 2 files changed, 104 insertions(+), 17 deletions(-) diff --git a/docs/lcdproc-dev/make-driver.docbook b/docs/lcdproc-dev/make-driver.docbook index 2017bda..1dca2da 100644 --- a/docs/lcdproc-dev/make-driver.docbook +++ b/docs/lcdproc-dev/make-driver.docbook @@ -138,6 +138,93 @@ char status = port_in(0x379); port_deny_multiple(0x378,3); + + + + + + +adv_bignum.h : Write Big-Numbers + +adv_bignum.h is the headerfile for lib_bignum.a (made from adv_bignum.c) which contains everything needed to show big-numbers, including the fonts for the different displays. (All files are located in the server/drivers/ directory.) + +There are only a few requirements to the calling driver: +The displays cellwidth has to be 5 and the cellheight 7 or 8. +The following functions have to be implemented: chr( ); + set_char( )(only if the display has custom-characters) +The custom-characters (if available) have to be at char 0, 1, 2, ..... ,n + +The lib determines the correct font, depending on the displaysize and the number of user-character, itself. So it is easy to integrate into the driver. + + + + +External provided Functions + + + + void lib_adv_bignum + Driver *drvthis + int x + int num + int height + int do_init + int customchars + + + +The main thing the driver has to do is to call this function from its the num( ) function. + +Where num is the number (legal: 0,...9,:) to be written, height the displays hight in characters and customchars the number of available custom-characters. + +x is the x position of the top-left corner of the big-number (the big-numbers don't have a y position). The placing of the characters is done by the client, so the driver only has to forward the position to the lib. The bignumlib has no influence on the placing of the characters. + +If do_init is unequal 0 lib_bignum will set the custom-characters of the display for the big-numbers. +The driver has to check if the custom-characters have to be set or if it is already done and tell it to the lib (using the do_init parameter). +The common way is to use variable called p->ccmode or similar. In the different drivers there are some differences in the naming and handling of this variable. So the responsibility of checking and setting is left at the driver. + + + + +Internal Structure and Functions + +The only function of lib_adv_bignum( ) is to determine the best display-dependent big-number-function for the given display-parameters, and to call it. + + +The display-dependent functions are named adv_bignum_num_N_M( ). +Where N is the display-hight lines and M the number of used user-characters. +The bits of the user-characters are stored in static char bignum (take a look at the source and you will see what I mean). (On a display with a cellheight of 7 the lowest line stored is not shown.) While static char num_map defines the placing in the big number. (A big number is always 3 characters wide and 4 characters high. On a big number for 2 line displays the 2 lower lines are not in use.) +If user-characters have to be set the drivers set_char( ) function will be called once for every user-character. +Now adv_bignum_write_num( ) is called. This function places the 6 or 12 characters the big-number consists of in the framebuffer using the drivers char( ) function. + + + + +Example: +Calling the lib_adv_bignum( ) from a drivers_num function. (from serialVFD.c): + + +MODULE_EXPORT void +serialVFD_num( Driver * drvthis, int x, int num ){ +int do_init=0; +PrivateData *p = drvthis->private_data; + + +if (p->ccmode != CCMODE_BIGNUM){ // Are the custom-characters set up correctly? If not: +do_init=1;// Lib_adv_bignum has to set the custom-characters. +p->ccmode = CCMODE_BIGNUM; // Switch custom-charactermode to bignum. +} +// Lib_adv_bignum does everything needed to show the big-numbers. +lib_adv_bignum(drvthis, x, num, p->height, do_init, p->customchars); +} + + + +All that's left to do is to include the header-file +#include "adv_bignum.h" +and to add libbignum.a to the libs and adv_bignum.h sources of your driver. + + diff --git a/server/drivers/adv_bignum.c b/server/drivers/adv_bignum.c index d6a429c..11e02d9 100644 --- a/server/drivers/adv_bignum.c +++ b/server/drivers/adv_bignum.c @@ -94,7 +94,7 @@ static void adv_bignum_num_4_0 (Driver *drvthis, int x, int num, int height, int static void adv_bignum_num_4_3 (Driver *drvthis, int x, int num, int height, int do_init); static void adv_bignum_num_4_8 (Driver *drvthis, int x, int num, int height, int do_init); -static void adv_bignum_write_num (Driver *drvthis, char write_num_map[][4][4], int x, int num, int height); +static void adv_bignum_write_num (Driver *drvthis, char write_num_map[][4][3], int x, int num, int height); ///////////////////////////////////////////////////////////////////////////////////////////// @@ -145,7 +145,7 @@ int height = drvthis->height(drvthis); ///////////////////////////////////////////////////////////////////////////////////////////// // This function writes the selected type of bignumber by calling the driver's chr function. // It is called by display-depending bignumber functions to write the numbers. -static void adv_bignum_write_num (Driver *drvthis, char write_num_map[][4][4], int x, int num, int height) +static void adv_bignum_write_num (Driver *drvthis, char write_num_map[][4][3], int x, int num, int height) { int y, dx; @@ -174,7 +174,7 @@ static void adv_bignum_write_num (Driver *drvthis, char write_num_map[][4][4], i // (pretty ugly looking) static void adv_bignum_num_2_0 (Driver *drvthis, int x, int num, int height, int do_init) { - static char num_map[][4][4] = { + static char num_map[][4][3] = { { /* 0 */ " ||", " ||", @@ -242,9 +242,9 @@ static void adv_bignum_num_2_0 (Driver *drvthis, int x, int num, int height, int // (not a beauty, but useable) static void adv_bignum_num_2_1 (Driver *drvthis, int x, int num, int height, int do_init) { - static char num_map[][4][4] = { + static char num_map[][4][3] = { { /* 0 */ - {'|' , 0 , '|',0}, + {'|',0,'|'}, {"|_|"}, {" "}, {" "} }, @@ -254,12 +254,12 @@ static void adv_bignum_num_2_1 (Driver *drvthis, int x, int num, int height, int {" "}, {" "} }, { /* 2 */ - {' ',0,']',0}, + {' ',0,']'}, {" [_"}, {" "}, {" "} }, { /* 3 */ - {' ',0,']',0}, + {' ',0,']'}, {" _]"}, {" "}, {" "} }, @@ -269,17 +269,17 @@ static void adv_bignum_num_2_1 (Driver *drvthis, int x, int num, int height, int {" "}, {" "} }, { /* 5 */ - {' ','[',0,0}, + {' ','[',0}, {" _]"}, {" "}, {" " }}, { /* 6 */ - {' ','[',0,0}, + {' ','[',0}, {" []"}, {" "}, {" "} }, { /* 7 */ - {' ',0,'|',0}, + {' ',0,'|'}, {" |"}, {" "}, {" "} }, @@ -325,7 +325,7 @@ static void adv_bignum_num_2_1 (Driver *drvthis, int x, int num, int height, int // (o.k.) static void adv_bignum_num_2_2 (Driver *drvthis, int x, int num, int height, int do_init) { - static char num_map[][4][4] ={ + static char num_map[][4][3] ={ { /* 0 */ {'|',0,'|'}, "|_|", @@ -419,7 +419,7 @@ static void adv_bignum_num_2_2 (Driver *drvthis, int x, int num, int height, int // (nice bignumbers) static void adv_bignum_num_2_5 (Driver *drvthis, int x, int num, int height, int do_init) { - static char num_map[][4][4] = + static char num_map[][4][3] = {{{3 ,0 ,2}, /*0*/ {3 ,1 ,2}, {" "}, @@ -529,7 +529,7 @@ static void adv_bignum_num_2_5 (Driver *drvthis, int x, int num, int height, int // (Wow, allmost graphical) static void adv_bignum_num_2_28 (Driver *drvthis, int x, int num, int height, int do_init) { - static char num_map[][4][4] = + static char num_map[][4][3] = {{{15 ,6 ,2}, /*0*/ {14 ,4 ,5}, {" "}, @@ -849,7 +849,7 @@ static void adv_bignum_num_4_0 (Driver *drvthis, int x, int num, int height, int /* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/ /* Moved to driver.c by Joris Robijn */ // Moved to adv_bignum.c by Stefan Herdler -static char num_map[][4][4] = { +static char num_map[][4][3] = { { /* 0 */ " _ ", "| |", @@ -916,7 +916,7 @@ static char num_map[][4][4] = { // (nice bignumbers) static void adv_bignum_num_4_3 (Driver *drvthis, int x, int num, int height, int do_init) { -static char num_map[][4][4] = +static char num_map[][4][3] = {{{3 ,1 ,3}, /*0*/ {3 ,' ' ,3}, {3 ,' ' ,3}, @@ -931,7 +931,7 @@ static char num_map[][4][4] = {3 ,2 ,' '}}, {{' ' ,1 ,3},/*3*/ {' ' ,2 ,3}, - {' ' ,' ' ,3}, + {' ' ,' ' ,3}, {' ' ,2 ,3}}, {{3 ,' ' ,3},/*4*/ {3 ,2 ,3}, @@ -1008,7 +1008,7 @@ static char num_map[][4][4] = // (nice bignumbers) static void adv_bignum_num_4_8 (Driver *drvthis, int x, int num, int height, int do_init) { -static char num_map[][4][4] = { +static char num_map[][4][3] = { { /* 0: */ { 1, 2, 3 }, { 6, 32, 6 },