muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
|
The muwerk namespace. More...
Classes | |
class | Astro |
mupplet helper for some astronomical calculations: sunrise and sunset More... | |
class | DigitalOut |
mupplet-core DigitalOut class More... | |
class | FrequencyCounter |
class | HomeAssistant |
class | Light |
mupplet-core GPIO Light class More... | |
class | LightController |
The Light Controller Class. More... | |
class | LightsPCA9685 |
mupplet-core PCA 9685 Light class More... | |
class | Switch |
mupplet-core GPIO Switch class More... | |
Functions | |
int8_t | parseBoolean (String arg) |
int16_t | parseToken (String arg, const char **tokenList, int16_t defaultVal=-1) |
long | parseLong (String arg, long defaultVal) |
long | parseRangedLong (String arg, long minVal, long maxVal, long minDefaultVal, long maxDefaultVal) |
double | parseUnitLevel (String arg) |
uint16_t | countChars (String txt, char c) |
bool | parseColor (String arg, uint8_t *pr, uint8_t *pg, uint8_t *pb, uint8_t *pw=nullptr, uint8_t *pww=nullptr) |
bool | isAscii (String utf8string) |
mupplet-core string encoding utilities More... | |
bool | isNumber (String string, bool integer=false) |
bool | isNumber (const char *value, bool integer=false) |
String | utf8ToLatin (String utf8string, char invalid_char='_') |
String | latinToUtf8 (String latin) |
Variables | |
const double | C_PI = 3.1415926535897932384626433 |
PI. | |
const double | C_D2R = C_PI / 180.0 |
degree -> radians conversion | |
const double | C_R2D = 180.0 / C_PI |
radians -> degrees | |
const double | C_AU = 149597870700.0 |
astronomical unit, meter | |
const double | C_C = 299792458.0 |
speed of light, m/s | |
const double | C_CAUD = C_C * 60 * 60 * 24 / C_AU |
AUs per day, approx 173. | |
const double | C_MJD = 2400000.5 |
MJD = JD - C_MJD. | |
The muwerk namespace.
uint16_t ustd::countChars | ( | String | txt, |
char | c | ||
) |
Count number of occurences of c in txt
bool ustd::isAscii | ( | String | utf8string | ) |
mupplet-core string encoding utilities
Encoding of UTF-8 strings:
| Number of bytes | First code point | Last code point | Byte 1 | Byte 2 | Byte 3 | Byte 4 | ------------— | -------------— | ------------— | -----— | -----— | -----— | -----— | 1 | U+0000 | U+007F | 0xxxxxxx | | | | 2 | U+0080 | U+07FF | 110xxxxx | 10xxxxxx | | | 3 | U+0800 | U+FFFF | 1110xxxx | 10xxxxxx | 10xxxxxx | | 4 | U+10000 | U+10FFFF | 11110xxx | 10xxxxxx | 10xxxxxx | 10xxxxxx
Mapping between UTF-8 and latin1 ISO 8859-1
https://www.utf8-chartable.de/
Check, if an arbitrary UTF-8 string only consists of ASCII characters
utf8string | The string to check |
true
, if ASCII compliantbool ustd::isNumber | ( | const char * | value, |
bool | integer = false |
||
) |
Check, if an arbitrary string contains a numerical value or not.
value | The string to check |
integer | If true , the routine checks if the string contains an integer value (default: false ) |
true
if the supplied string is a number or an integer valuebool ustd::isNumber | ( | String | string, |
bool | integer = false |
||
) |
Check, if an arbitrary string contains a numerical value or not.
string | The string to check |
integer | If true , the routine checks if the string contains an integer value (default: false ) |
true
if the supplied string is a number or an integer valueString ustd::latinToUtf8 | ( | String | latin | ) |
Convert a latin1 (ISO 8859-1) string into UTF-8
See utf8ToLatin() for the opposite conversion.
latin | ISO 8869-1 (latin1) encoded string |
int8_t ustd::parseBoolean | ( | String | arg | ) |
Parses a string argument for a boolean value
The parser is not case sensistive. The words on
and true
are interpreted as true
, off
and false
as false
. If the argument contains a numeric value, 0 is considered as false
, all other values as true
If the argument contains anything different, -1 is returned.
arg | The argument to parse |
0
if false
, 1
if true
, -1
if invalidbool ustd::parseColor | ( | String | arg, |
uint8_t * | pr, | ||
uint8_t * | pg, | ||
uint8_t * | pb, | ||
uint8_t * | pw = nullptr , |
||
uint8_t * | pww = nullptr |
||
) |
Parse and split a 24-bit, 32-bit or 40-bit RGB, RGBW or RGBWW color values into r,g,b and optionally w [,ww] components
If 24bits are given (RGB), the color value can be either represented as 0x010203
or #010203
or 1,2,3
in decimal, comma separated. It is split into the components r=1, b=2 and g=3. Input order is RGB.
If 32bits are given (RGBW), the color value can be either represented as 0x11010203
or #11010203
or 17,1,2,3
in decimal, comma separated. It is split into the components r=1, b=2, g=3 and w=17. Input order is WRGB.
If 40bits are given (RGBWW), the color value can be either represented as 0x2211010203
or #2211010203
or 34,17,1,2,3
in decimal, comma separated. It is split into the components r=1, b=2, g=3, w=17, ww=34. Input order is WW W R G B.
arg | String to parse, order [W[W]]RGB, either 0x[22][78]123456 (hex) or #[22][78]123456 (hex) or [34,][120,]18,52,86 (dec) |
pr | pointer that receives the red-part (1st, 2nd or 3rd two digits of hex string) |
pg | pointer that receives the green-part (2,3, or 4th two digits of hex string) |
pb | pointer that receives the blue-part (end of hex string) |
pw | Optional pointer that received the white-part (start or 2nd part of string) for 32bit values. |
pww | Optional pointer that received the warm-white-part (start of string) for 32bit values. |
long ustd::parseLong | ( | String | arg, |
long | defaultVal | ||
) |
Parses a string argument for a valid integer value
The parser checks if the parsed value is an interger number and returns eitherthe entered value or the supplied default value.
arg | The argument to parse |
defaultVal | The default value to return in case the entered argument is invalid |
long ustd::parseRangedLong | ( | String | arg, |
long | minVal, | ||
long | maxVal, | ||
long | minDefaultVal, | ||
long | maxDefaultVal | ||
) |
Parses a string argument for a valid integer value
The parser checks if the parsed value stays between the defined boundaries and returns either the entered value or one the defaults depending upon the entered value beeing lower than the minimum value or higher than the maximum value.
arg | The argument to parse |
minVal | The minimum acceptable value |
maxVal | The maximum acceptable value |
minDefaultVal | The default value to return in case the enetered value is lower than minVal or not a number |
maxDefaultVal | The default value to return in case the enetered value is higher than maxVal |
int16_t ustd::parseToken | ( | String | arg, |
const char ** | tokenList, | ||
int16_t | defaultVal = -1 |
||
) |
Parses a string argument against a token list
The parser is not case sensistive and returns the index of the detected token. If no token matches the parser returns -1
arg | The argument to parse |
tokenList | An array of constant zero terminated char string pointers containing the tokens. The tokens must be lowercase. The last token in the list must be null pointer. |
defaultVal | The default value to return in case the entered argument is invalid (default: -1) |
double ustd::parseUnitLevel | ( | String | arg | ) |
Parses a string argument for a valid unit level
A unit level (like a light) can be set fully on or off with on
or true
and off
or false
. A fractional brightness of 0.34
(within interval [0.0, 1.0]) can be sent as either as pct 34
, or 0.34
, or 34%
.
arg | The argument to parse |
String ustd::utf8ToLatin | ( | String | utf8string, |
char | invalid_char = '_' |
||
) |
Convert an arbitrary UTF-8 string into latin1 (ISO 8859-1)
The function isAscii() can be used to check if a conversion is necessary at all. (No conversion is necessary, if the UTF-8 string only consists of ASCII chars, in that case both encodings are identical.)
See latinToUtf8() for the opposite conversion.
Note: This converts arbitrary multibyte utf-8 strings to latin1 on best-effort basis. Characters that are not in the target code-page are replaced by invalid_char. The conversion is aborted, if an invalid UTF8-encoding is encountered.
utf8string | utf8-encoded string |
invalid_char | character that is used for to replace characters that are not in latin1 |