muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
Loading...
Searching...
No Matches
Classes | Functions | Variables
ustd Namespace Reference

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.
 

Detailed Description

The muwerk namespace.

Function Documentation

◆ countChars()

uint16_t ustd::countChars ( String  txt,
char  c 
)

Count number of occurences of c in txt

◆ isAscii()

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

Parameters
utf8stringThe string to check
Returns
true, if ASCII compliant

◆ isNumber() [1/2]

bool ustd::isNumber ( const char *  value,
bool  integer = false 
)

Check, if an arbitrary string contains a numerical value or not.

Parameters
valueThe string to check
integerIf true, the routine checks if the string contains an integer value (default: false)
Returns
true if the supplied string is a number or an integer value

◆ isNumber() [2/2]

bool ustd::isNumber ( String  string,
bool  integer = false 
)

Check, if an arbitrary string contains a numerical value or not.

Parameters
stringThe string to check
integerIf true, the routine checks if the string contains an integer value (default: false)
Returns
true if the supplied string is a number or an integer value

◆ latinToUtf8()

String ustd::latinToUtf8 ( String  latin)

Convert a latin1 (ISO 8859-1) string into UTF-8

See utf8ToLatin() for the opposite conversion.

Parameters
latinISO 8869-1 (latin1) encoded string
Returns
UTF8-encoded string

◆ parseBoolean()

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 falseas 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.

Parameters
argThe argument to parse
Returns
0 if false, 1 if true, -1 if invalid

◆ parseColor()

bool 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.

Parameters
argString to parse, order [W[W]]RGB, either 0x[22][78]123456 (hex) or #[22][78]123456 (hex) or [34,][120,]18,52,86 (dec)
prpointer that receives the red-part (1st, 2nd or 3rd two digits of hex string)
pgpointer that receives the green-part (2,3, or 4th two digits of hex string)
pbpointer that receives the blue-part (end of hex string)
pwOptional pointer that received the white-part (start or 2nd part of string) for 32bit values.
pwwOptional pointer that received the warm-white-part (start of string) for 32bit values.
Returns
true: sucessful conversion, false: wrong format.

◆ parseLong()

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.

Parameters
argThe argument to parse
defaultValThe default value to return in case the entered argument is invalid
Returns
The parsed value

◆ parseRangedLong()

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.

Parameters
argThe argument to parse
minValThe minimum acceptable value
maxValThe maximum acceptable value
minDefaultValThe default value to return in case the enetered value is lower than minVal or not a number
maxDefaultValThe default value to return in case the enetered value is higher than maxVal
Returns
The parsed value

◆ parseToken()

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

Parameters
argThe argument to parse
tokenListAn 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.
defaultValThe default value to return in case the entered argument is invalid (default: -1)
Returns
The index of the found token, or -1 if no token matches.

◆ parseUnitLevel()

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%.

Parameters
argThe argument to parse
Returns
The parsed value (double between 0.00 and 1.00)

◆ utf8ToLatin()

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.

Parameters
utf8stringutf8-encoded string
invalid_charcharacter that is used for to replace characters that are not in latin1
Returns
latin1 (ISO 8859-1) encoded string