Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
ConfigPar.h
Go to the documentation of this file.
1#ifndef HUMIDISTAT_CONFIGPAR_H
2#define HUMIDISTAT_CONFIGPAR_H
3
4#define XSTR(s) STR(s)
5#define STR(s) #s
6#define WIDTH 7
7#define NUM_DIGITS WIDTH - 2
8#define NUM_DECIMALS 4
9
11class ConfigPar {
12public:
13 enum class ConfigParType {
14 ui8,
15 ui16,
16 d,
17 };
18 // The nested struct is in order to have an overloaded constructor for the type and the union, but avoid
19 // having to strcopy the label
20 struct Var {
22 union {
23 uint8_t *const ui8;
24 uint16_t *const ui16;
25 double *const d;
26 };
27
31 Var(uint8_t *par) : type(ConfigParType::ui16), ui8(par) {}
32 Var(uint16_t *par) : type(ConfigParType::ui16), ui16(par) {}
33 Var(double *par) : type(ConfigParType::d), d(par) {}
35
37 Var() : type(ConfigParType::ui8), ui8(nullptr) {}
38 } var;
39
40 char label[10];
41
44 void adjust(int16_t delta) const;
45
49 char *asprint() const;
50
53 uint8_t magnitude() const;
54};
55
56
57#endif //HUMIDISTAT_CONFIGPAR_H
A class for storing references to variables of various types (uint8_t, uint16_t, or double).
Definition ConfigPar.h:11
uint8_t magnitude() const
Get magnitude (number of digits before the decimal separator) of variable.
Definition ConfigPar.cpp:33
char * asprint() const
Print "label: value" to string. Automatically allocates string on the heap. Make sure to delete it im...
Definition ConfigPar.cpp:22
void adjust(int16_t delta) const
Add delta to the variable.
Definition ConfigPar.cpp:8
struct ConfigPar::Var var
char label[10]
Definition ConfigPar.h:40
Var(double *par)
Definition ConfigPar.h:33
double *const d
Definition ConfigPar.h:25
Var(uint16_t *par)
Definition ConfigPar.h:32
const ConfigParType type
Definition ConfigPar.h:21
uint16_t *const ui16
Definition ConfigPar.h:24
uint8_t *const ui8
Definition ConfigPar.h:23
Var()
Default constructor, initializes with nullptr.
Definition ConfigPar.h:37
Var(uint8_t *par)
Constructor.
Definition ConfigPar.h:31