Drawing functions | |
void | sdtools_generic_rotate (serdisp_t *dd) |
rotates the display buffer More... | |
void | sdtools_generic_setsdpixel (serdisp_t *dd, int x, int y, SDCol sdcol) |
changes a pixel into the display buffer More... | |
SDCol | sdtools_generic_getsdpixel (serdisp_t *dd, int x, int y) |
gets a pixel from the display buffer More... | |
void | sdtools_generic_setsdpixel_greyhoriz (serdisp_t *dd, int x, int y, SDCol sdcol) |
changes a pixel into the display buffer (horizontally organised w/o pages) More... | |
SDCol | sdtools_generic_getsdpixel_greyhoriz (serdisp_t *dd, int x, int y) |
gets a pixel from the display buffer (horizontally organised w/o pages) More... | |
System functions | |
void | sdtools_nsleep (long ns) |
sleeps for the specified number of nanoseconds More... | |
void * | sdtools_malloc (size_t size) |
zero-byte save malloc More... | |
byte | sdtools_reversebits (byte b) |
swaps bits in a byte More... | |
Conversion functions | |
int | sdtools_contrast_norm2hw (serdisp_t *dd, int normval) |
convert normalised contrast value to hardware contrast value More... | |
int | sdtools_contrast_hw2norm (serdisp_t *dd, int hwval) |
convert hardware contrast value to normalised contrast value More... | |
int | sdtools_rotate_deg2intern (serdisp_t *dd, int degval) |
convert rotation radius in degrees to rotation value in internal representation More... | |
int | sdtools_rotate_intern2deg (serdisp_t *dd, int irepval) |
convert rotation value in internal representation to radius value in degrees More... | |
byte | sdtools_dec2bcd (byte num) |
convert a decimal number to BCD representation More... | |
String processing | |
char * | sdtools_strncpy (char *dest, const char *src, size_t n) |
workaround for error-prone strncpy More... | |
char * | sdtools_strlefttrim (const char *str) |
trims a string More... | |
int | sdtools_isinelemlist (const char *elemlist, const char *str, int len) |
tests of a string is part of a comma-separated list More... | |
char * | sdtools_nextpattern (const char *str, char delim, int *len, int *border) |
searches next pattern in a string More... | |
int | sdtools_ismatching (const char *str1, int len1, const char *str2, int len2) |
compares two strings if they're matching More... | |
int | sdtools_strtrimmedlen (const char *str, int len) |
length of a string without trailing spaces or tabulators More... | |
int | sdtools_strtol (const char *str, char delim, int base, long *value) |
reads a long value until delimiter or end of string More... | |
int | sdtools_strtosd (const char *str, char delim, double *value) |
reads a simple double value until delimiter or end of string More... | |
Calculation functions | |
void | sdtools_init_bbox (serdisp_t *dd, int value) |
initialises or sets the bounding box data More... | |
int | sdtools_calc_bbox (serdisp_t *dd, int *xt, int *yt, int *xb, int *yb) |
calculates bounding box containing changed display information More... | |
Math function replacements which do not require math.h nor -lm | |
double | sdtools_exp (double x) |
base-e exponential function More... | |
double | sdtools_log (double x) |
calculates the natural logarithm of x More... | |
double | sdtools_logN (double x, double base) |
calculates the logarithm of x to base y More... | |
double | sdtools_pow (double x, double y) |
power function More... | |
serdisp_tools.h provides common routines that are used in different parts of serdisplib.
int sdtools_calc_bbox | ( | serdisp_t * | dd, |
int * | xt, | ||
int * | yt, | ||
int * | xb, | ||
int * | yb | ||
) |
dd | device descriptor |
xt | x top-left |
yt | y top-left |
xb | x bottom-left |
yb | y bottom-left |
0 | no changed display information found in current bounding box |
1 | changes detected, new bbox calculated |
int sdtools_contrast_hw2norm | ( | serdisp_t * | dd, |
int | hwval | ||
) |
dd | device descriptor |
hwval | contrast value used by the hardware (in [min_contrast, max_contrast]) |
int sdtools_contrast_norm2hw | ( | serdisp_t * | dd, |
int | normval | ||
) |
dd | device descriptor |
normval | normalised contrast value (in [0,MAX_CONTRASTSTEP]) |
byte sdtools_dec2bcd | ( | byte | num | ) |
num | decimal number (in [0, 99]) |
double sdtools_exp | ( | double | x | ) |
calculates the value of e raised to the power of x without requiring math.h nor libm.
x | value |
SDCol sdtools_generic_getsdpixel | ( | serdisp_t * | dd, |
int | x, | ||
int | y | ||
) |
dd | device descriptor |
x | x-position |
y | y-position |
SDCol sdtools_generic_getsdpixel_greyhoriz | ( | serdisp_t * | dd, |
int | x, | ||
int | y | ||
) |
dd | device descriptor |
x | x-position |
y | y-position |
void sdtools_generic_rotate | ( | serdisp_t * | dd | ) |
rotates the display buffer (and updates the display)
dd | device descriptor |
void sdtools_generic_setsdpixel | ( | serdisp_t * | dd, |
int | x, | ||
int | y, | ||
SDCol | sdcol | ||
) |
dd | device descriptor |
x | x-position |
y | y-position |
sdcol | monochrome: 0: clear (white), <>0: set (black); else: grey value (supported depths: 1, 2, 4) |
void sdtools_generic_setsdpixel_greyhoriz | ( | serdisp_t * | dd, |
int | x, | ||
int | y, | ||
SDCol | sdcol | ||
) |
dd | device descriptor |
x | x-position |
y | y-position |
sdcol | monochrome: 0: clear (white), <>0: set (black); else: grey value (dependent on display) |
void sdtools_init_bbox | ( | serdisp_t * | dd, |
int | value | ||
) |
dd | device descriptor |
value | 0: clears bounding box, 1: sets whole display area to dirty |
int sdtools_isinelemlist | ( | const char * | elemlist, |
const char * | str, | ||
int | len | ||
) |
tests if string str is part of the comma-separated list elemlist.
leading and trailing spaces and tabs are ignored. commas are interpreted as separators and are NOT valid in elements!
elemlist | comma-separated element list |
str | string to be searched |
len | max. number of characters to be processed (or -1 if unlimited) |
-1 | string str is not part of the element list |
>=0 | str is the n-th element in the element list |
Examples:
sdtools_isinelemlist(" xyz , abc,cde ", "xyz", -1); -> 0 will be returned sdtools_isinelemlist(" xyz , abc,cde ", "abc", -1); -> 1 will be returned sdtools_isinelemlist(" xyz , abc,cde ", " cde", -1); -> 2 will be returned (trailing spaces will be ignored) sdtools_isinelemlist(" xyz , abc,cde ", "ijk", -1); -> -1 will be returned sdtools_isinelemlist(" xyz , abc,cde ", "c,c", -1); -> -1 will be returned (',' is a separator but no valid character)
\since 1.95
int sdtools_ismatching | ( | const char * | str1, |
int | len1, | ||
const char * | str2, | ||
int | len2 | ||
) |
compares two strings whether they match or not. case, leading spaces, and tabs are ignored.
str1 | string 1 |
len1 | length of string 1 (all characters after len1 are ignored) |
str2 | string 2 |
len2 | length of string 2 (all characters after len2 are ignored) |
1 | strings match |
0 | strings don't match |
double sdtools_log | ( | double | x | ) |
calculates the natural logarithm of x in a simple way without requiring math.h nor libm.
x | value |
double sdtools_logN | ( | double | x, |
double | base | ||
) |
calculates the logarithm of x to base y in a simple way without requiring math.h nor libm.
x | value |
base | base of logarithm |
void* sdtools_malloc | ( | size_t | size | ) |
zero-byte save malloc (some versions of malloc are defective when size is zero
size | amount of bytes to allocate |
NULL
if requested memory could not be allocated)char* sdtools_nextpattern | ( | const char * | str, |
char | delim, | ||
int * | len, | ||
int * | border | ||
) |
searches the next pattern delimited with delim or \0
, leading spaces or tabs are ignored.
len will contain the length of this pattern without any trainling spaces or tabs.
for the first pattern, len has to be set to -1
and, if a pattern can be found, will be changed to its length.
border contains the maximum characters to take care of. all characters above border are ignored.
if a new pattern was found, border will be adapted.
[in] | str | string to be searched |
[in] | delim | delimiter (eg: ',' or ';' ) |
[in,out] | len | length of found pattern (w/o leading and trailing spaces or tabulators) |
[in,out] | border | amount of characters that are valid for searching patterns |
NULL | no more patterns available |
!NULL | pointer to the found pattern (with leading spaces and tabulators eliminated) |
Examples:
str = "elem1=val1, elem2= val2 , elem3=val3 ; xyz=abc, def = ghi "; border = 40; -> ';' and all following characters are ignored len = -1; -> start with -1 to get first parameter pattern = sdtools_nextpattern(str, ',', &len, &border); -> pattern will contain "elem1=........", len = 10; border = 40; so pattern => "elem1=val1" pattern = sdtools_nextpattern(str, ',', &len, &border); -> pattern will contain "elem2=........", len = 11; border = 22; so pattern => "elem2= val2" pattern = sdtools_nextpattern(str, ',', &len, &border); -> pattern will contain "elem3=........", len = 10; border = 13; so pattern => "elem3=val3" pattern = sdtools_nextpattern(str, ',', &len, &border); -> pattern will contain 0, because the border was exceeded
\since 1.95
void sdtools_nsleep | ( | long | ns | ) |
ns | amount of nanoseconds to sleep ns = 0: no delay (do nothing) ns = 1: do a simple delay (one call of gettimeofday() ) ns > 1: delay ns nanoseconds |
double sdtools_pow | ( | double | x, |
double | y | ||
) |
calculates x raised to the power of y without requiring math.h nor libm.
x | value |
y | power |
byte sdtools_reversebits | ( | byte | b | ) |
swaps all bits in a byte: bit7 becomes bit0, bit6 becomes bit1 and so on.
a predefined table containing all 256 dupels is used for faster execution.
Source: graphlcd-plugin: glcddrivers/common.c: ReverseBits()
http://projects.vdr-developer.org/projects/graphlcd
b | input byte |
int sdtools_rotate_deg2intern | ( | serdisp_t * | dd, |
int | degval | ||
) |
dd | device descriptor |
degval | radius in degrees (1==180) (or special case degree=2: toggle 0 <-> 180 or 90 <-> 270) |
int sdtools_rotate_intern2deg | ( | serdisp_t * | dd, |
int | irepval | ||
) |
dd | device descriptor |
irepval | rotation value in internal representation |
char* sdtools_strlefttrim | ( | const char * | str | ) |
returns a char-pointer to the first non-space/tabulator character in string str.
if no leading spaces/tabulators: str is returned as is.
no extra memory is allocated.
str | string that should be trimmed |
char* sdtools_strncpy | ( | char * | dest, |
const char * | src, | ||
size_t | n | ||
) |
strncpy with workarounds avoiding strncpy-bugs found on solaris10 and/or glibc-linked programs
dest | destination string |
src | source string |
n | amount of characters to be copied |
int sdtools_strtol | ( | const char * | str, |
char | delim, | ||
int | base, | ||
long * | value | ||
) |
tries to read a long value in a string. reads until end of string or until given delimiter. if the string representation contains invalid characters, the value is invalid.
str | string containing long value |
delim | processing is stopped if delimiter is found |
base | numerical base (10 for decimal, 16 for hexadecimal, 0 for auto) |
value | pointer to value |
1 | value is valid |
0 | value is invalid (contains invalid characters) |
int sdtools_strtosd | ( | const char * | str, |
char | delim, | ||
double * | value | ||
) |
tries to read a simple double value in a string. reads until end of string or until given delimiter. if the string representation contains invalid characters, the value is invalid. if a decimal point character is given it always has to be '.'. no other characters (like ',') are allowed. exponents are NOT supported.
str | string containing long value |
delim | processing is stopped if delimiter is found (delim must not be '.') |
value | pointer to value |
1 | value is valid |
0 | value is invalid (contains invalid characters) |
int sdtools_strtrimmedlen | ( | const char * | str, |
int | len | ||
) |
returns length of string str without any trailing spaces or tabulators (only len characters of str are used for this operation). leading spaces and tabulators are ignored.
if no trailing spaces/tabulators is found: len will be returned.
str | string |
len | max. number of characters to be processed |
Examples:
sdtools_strtimmedlen("test ", 6); -> 4 will be returned sdtools_strtimmedlen(" test ", 6); -> 5 will be returned sdtools_strtimmedlen("test ,xyz", 6); -> 4 will be returned sdtools_strtimmedlen("test ,xyz", 8); -> 8 will be returned