/
easyctrl.cpp
104 lines (85 loc) · 2.18 KB
/
easyctrl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "easyctrl.h"
Easyctrl_Class Easyctrl;
void MonitoredBase::init(const char *name, bool writeable) {
this->name = name;
this->writeable = writeable;
// Add it to the linked list of known monitored variables
this->next = Easyctrl.first;
Easyctrl.first = this;
}
void Easyctrl_Class::writeManifest() {
stream->print(F(".fields "));
stream->println(this->name);
for(MonitoredBase *i = this->first; i != NULL; i = i->next) {
i->describe(*this->stream);
}
stream->println(F(".endfields"));
}
template<>
void Monitored<int>::parse(const char *data) {
this->value = strtol(data, NULL, 0);
}
template<>
void Monitored<int>::printTypeName(Stream &stream) {
stream.print(F("int"));
}
template<>
void Monitored<unsigned int>::parse(const char *data) {
this->value = strtoul(data, NULL, 0);
}
template<>
void Monitored<unsigned int>::printTypeName(Stream &stream) {
stream.print(F("uint"));
}
template<>
void Monitored<long>::parse(const char *data) {
this->value = strtol(data, NULL, 0);
}
template<>
void Monitored<long>::printTypeName(Stream &stream) {
stream.print(F("long"));
}
template<>
void Monitored<unsigned long>::parse(const char *data) {
this->value = strtoul(data, NULL, 0);
}
template<>
void Monitored<unsigned long>::printTypeName(Stream &stream) {
stream.print(F("ulong"));
}
template<>
void Monitored<float>::parse(const char *data) {
this->value = strtod(data, NULL);
}
template<>
void Monitored<float>::printTypeName(Stream &stream) {
stream.print(F("float"));
}
template<>
void Monitored<double>::parse(const char *data) {
this->value = strtod(data, NULL);
}
template<>
void Monitored<double>::printTypeName(Stream &stream) {
stream.print(F("double"));
}
template<>
void Monitored<bool>::format(Stream &stream) {
if(this->value) {
stream.print(F("true"));
} else {
stream.print(F("false"));
}
}
template<>
void Monitored<bool>::parse(const char *data) {
if(strncasecmp_P(data, PSTR("true"), 4) == 0 || atoi(data) != 0) {
this->value = true;
} else {
this->value = false;
}
}
template<>
void Monitored<bool>::printTypeName(Stream &stream) {
stream.print(F("bool"));
}