-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.cpp
236 lines (175 loc) · 5.67 KB
/
settings.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/// Implementation of user settings
///\file settings.cpp
#include "EEPROMAnything.h"
#define defaultAnnouncementFormat "BAT %V MV ? %V MV"
/// Enable the radio transmitter for 120 ms before transmitting.
const uint32_t radioStartupDelay = 120000;
const uint32_t getRadioStartupDelay() {
return radioStartupDelay;
}
/// Duration of a dit in microseconds
const uint32_t ditMicrosDefault = 100000;
const int32_t lowVoltageThresholdDefault = 2700;
const int32_t getLowVoltageThresholdDefault() {
return lowVoltageThresholdDefault;
}
const int32_t maximumVoltage = 16000;
const int32_t getMaximumVoltage() {
return maximumVoltage;
}
const int32_t highVoltageThresholdDefault = maximumVoltage;
const int32_t getHighVoltageThresholdDefault() {
return highVoltageThresholdDefault;
}
const char* getAnnouncementFormatDefault() {
return defaultAnnouncementFormat;
}
/// Default announcement interval in seconds.
const uint32_t defaultAnnouncementInterval = 600;
/// Default alarm interval in seconds.
const uint32_t defaultAlarmInterval = 30;
/// Default transmission frequency in Hz.
const uint32_t defaultFrequency = 750;
struct {
/// Low-voltage alert threshold in millivolts. Note: if the
/// low-voltage threshold is lower than the transmitter's minimum
/// voltage, or lower than the microprcessor's minimum voltage, the
/// alarm will not be transmitted.
int32_t lowVoltageThreshold = lowVoltageThresholdDefault;
/// High-voltage alert threshold in millivolts. Note: the hardware
/// has been tested briefly at 19.6V, but the design target is a
/// 12V battery. The theoretical maximum input voltage is
/// approximately 34V based on the voltage divider, the ADC
/// maximum input voltage of 3.3V, and the reverse voltage
/// protection diode, but that doesn't account for thermal stress.
///
/// The voltage divider values are 993 KOhm and 107.5 KOhm.
int32_t highVoltageThreshold = highVoltageThresholdDefault;
/// Duration of a 'dit' in microseconds
uint32_t ditMicros = ditMicrosDefault;
/// Format for periodic announcements in an application-specific syntax
char announcementFormat[128] = defaultAnnouncementFormat;
/// Format for periodic announcements when voltage is low
char alarmLowFormat[128] = defaultAnnouncementFormat;
/// Format for periodic announcements when voltage is low
char alarmHighFormat[128] = defaultAnnouncementFormat;
/// Repeat the announcement when the time in seconds is a multiple
/// of this number.
uint32_t announcementInterval = defaultAnnouncementInterval;
/// Repeat the low-voltage alarm when the time in seconds is a
/// multiple of this number.
uint32_t alarmInterval = defaultAlarmInterval;
/// Initial frequency of the 'carrier wave' tones.
uint32_t txHz = defaultFrequency;
} settings;
/// Number of 15-minute intervals since power on. The value gets
/// written to EEPROM when it exceeds 2 (30 minutes) so that it is
/// possible to see how long the previous uptime was.
uint32_t uptime;
size_t getAnnouncementBufferSize() {
return sizeof settings.announcementFormat;
}
char* getAnnouncementBuffer() {
return settings.announcementFormat;
}
size_t getAlarmLowBufferSize() {
return sizeof settings.alarmLowFormat;
}
char* getAlarmLowBuffer() {
return settings.alarmLowFormat;
}
size_t getAlarmHighBufferSize() {
return sizeof settings.alarmHighFormat;
}
char* getAlarmHighBuffer() {
return settings.alarmHighFormat;
}
uint32_t getTxHz() {
return settings.txHz;
}
void setTxHz(uint32_t Hz) {
settings.txHz = Hz;
}
void initSettings() {
(void) EEPROM_readAnything(4, settings);
}
void saveSettings() {
(void) EEPROM_writeAnything(4, settings);
}
bool timeIsSet(false);
bool isTimeSet() {
return timeIsSet;
}
elapsedMicros sinceUptime;
void updateUptime() {
if (15 * 60 * 1000000 <= sinceUptime) {
++uptime;
(void) EEPROM_writeAnything(0, uptime);
sinceUptime = 0;
}
}
void setUptime(uint32_t u, bool initializing) {
timeIsSet = !initializing;
uptime = u;
}
uint32_t getUptime() {
return uptime;
}
void setLowVoltageThreshold(int32_t v) {
settings.lowVoltageThreshold = v;
}
int32_t getLowVoltageThreshold() {
return settings.lowVoltageThreshold;
}
void setHighVoltageThreshold(int32_t v) {
settings.highVoltageThreshold = v;
}
int32_t getHighVoltageThreshold() {
return settings.highVoltageThreshold;
}
//---- Morse Code ----
uint32_t getDitMicrosDefault() {
return ditMicrosDefault;
}
void setDitMicros(uint32_t ms) {
settings.ditMicros = ms;
}
uint32_t getDitMicros() {
return settings.ditMicros;
}
void setAnnouncementFormat(const char* format) {
const size_t n(sizeof settings.announcementFormat);
strncpy(settings.announcementFormat, format, n);
settings.announcementFormat[n - 1] = 0;
}
void setAlarmLowFormat(const char* format) {
const size_t n(sizeof settings.alarmLowFormat);
strncpy(settings.alarmLowFormat, format, n);
settings.alarmLowFormat[n - 1] = 0;
}
void setAlarmHighFormat(const char* format) {
const size_t n(sizeof settings.alarmHighFormat);
strncpy(settings.alarmHighFormat, format, n);
settings.alarmHighFormat[n - 1] = 0;
}
const char* getAnnouncementFormat() {
return settings.announcementFormat;
}
const char* getAlarmLowFormat() {
return settings.alarmLowFormat;
}
const char* getAlarmHighFormat() {
return settings.alarmHighFormat;
}
void setAlarmInterval(uint32_t seconds) {
settings.alarmInterval = seconds;
}
void setAnnouncementInterval(uint32_t seconds) {
settings.announcementInterval = seconds;
}
uint32_t getAnnouncementInterval() {
return settings.announcementInterval;
}
uint32_t getAlarmInterval() {
return settings.alarmInterval;
}