-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_manager.c
291 lines (245 loc) · 6.57 KB
/
config_manager.c
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "config_manager.h"
#include "clock.h"
#define NRF_LOG_MODULE_NAME "CONF"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "encoder.h"
#include "state.h"
#include "FEPD_2in13.h"
#include "GUI_Paint.h"
#define VERSION 2
#define SN 1
static global_conf_t m_global_conf;
static uint8_t name_len;
void config_manager_init(void)
{
memset(&m_global_conf, 0, sizeof(m_global_conf));
// Config
m_global_conf.flags = CONFIG_CHO_FLAG | CONFIG_INSULIN_FLAG | CONFIG_GLUCOSE_FLAG;
m_global_conf.flags |= CONFIG_COLOR_FLAG;
//m_global_conf.flags |= CONFIG_FLIP_FLAG;
//m_global_conf.flags |= CONFIG_BOLO_FLAG;
m_global_conf.g_portion = 250;
m_global_conf.cho_interval = 5;
m_global_conf.ins_interval = 10;
// Name
const char* tmp = "Topsulin";
strcpy(m_global_conf.name, tmp);
name_len = 8;
// Calc
m_global_conf.calc_low.mantissa = 90;
m_global_conf.calc_low.exponent = -5;
m_global_conf.calc_high.mantissa = 150;
m_global_conf.calc_high.exponent = -5;
m_global_conf.calc_sens = 15;
m_global_conf.calc_corr.mantissa = 50;
m_global_conf.calc_corr.exponent = -5;
// Insulin
m_global_conf.insulin_type = BLE_GLS_CONTEXT_MED_RAPID;
m_global_conf.insulin_total = 300;
m_global_conf.insulin_remaining = 120;
m_global_conf.insulin_start = 30; // 30 min
m_global_conf.insulin_max = 120; // 2 h
m_global_conf.insulin_duration = 360; // 6 h
}
void config_manager_print(void)
{
// Config
uint8_t flags = m_global_conf.flags;
NRF_LOG_INFO("GLU 0x%02X\n",flags & CONFIG_GLUCOSE_FLAG);
NRF_LOG_INFO("INS 0x%02X\n",flags & CONFIG_INSULIN_FLAG);
NRF_LOG_INFO("CHO 0x%02X\n",flags & CONFIG_CHO_FLAG);
if(flags & CONFIG_COLOR_FLAG){
NRF_LOG_INFO("FDO BLANCO\n");
} else {
NRF_LOG_INFO("FDO NEGRO\n");
}
if(flags & CONFIG_UNITS_FLAG){
NRF_LOG_INFO("GLU mol/L\n");
} else {
NRF_LOG_INFO("GLU kg/L\n");
}
NRF_LOG_INFO("CAL 0x%02X\n",flags & CONFIG_BOLO_FLAG);
if(flags & CONFIG_FLIP_FLAG){
NRF_LOG_INFO("DIR ZURDO\n");
} else {
NRF_LOG_INFO("DIR DIESTRO\n");
}
if(flags & CONFIG_PORTION_FLAG){
NRF_LOG_INFO("CHO en PORCIONES (%d g/porcion)\n", m_global_conf.g_portion);
} else {
NRF_LOG_INFO("CHO en g\n");
}
NRF_LOG_FLUSH();
// Name
NRF_LOG_INFO("NME %s\n", (uint32_t)m_global_conf.name);
NRF_LOG_FLUSH();
// Time
struct tm t;
clock_get_time(&t);
char time_buffer[80];
strftime(time_buffer, sizeof(time_buffer), "%x %X", &t);
NRF_LOG_INFO("DTM %s\n", (uint32_t)time_buffer);
NRF_LOG_FLUSH();
// Calculator
NRF_LOG_INFO("CALC LOW %dx10^%d kg/L\n", m_global_conf.calc_low.mantissa, m_global_conf.calc_low.exponent);
NRF_LOG_INFO("CALC HIGH %dx10^%d kg/L\n", m_global_conf.calc_high.mantissa, m_global_conf.calc_high.exponent);
NRF_LOG_INFO("CALC SENS %d g\n", m_global_conf.calc_sens);
NRF_LOG_INFO("CALC CORR %dx10^%d kg/L\n", m_global_conf.calc_corr.mantissa, m_global_conf.calc_corr.exponent);
NRF_LOG_FLUSH();
// Insulin
NRF_LOG_INFO("INS type 0x%02X\n", m_global_conf.insulin_type);
NRF_LOG_INFO("INS total %d U\n", m_global_conf.insulin_total);
NRF_LOG_INFO("INS rem %d U\n", m_global_conf.insulin_remaining);
NRF_LOG_INFO("INS start %d min\n", m_global_conf.insulin_start);
NRF_LOG_INFO("INS max %d min\n", m_global_conf.insulin_max);
NRF_LOG_INFO("INS dur %d min\n", m_global_conf.insulin_duration);
NRF_LOG_FLUSH();
// Device
NRF_LOG_INFO("DEV v %d\n", VERSION);
NRF_LOG_INFO("DEV SN %d\n", SN);
NRF_LOG_FLUSH();
}
void config_manager_set_flags(uint8_t flags)
{
m_global_conf.flags = flags;
encoder_set_direction((config_manager_get_flags() & CONFIG_FLIP_FLAG) == 0);
}
uint8_t config_manager_get_flags(void)
{
return m_global_conf.flags;
}
void config_manager_set_portion(uint16_t portion)
{
m_global_conf.g_portion = portion;
}
uint16_t config_manager_get_portion(void)
{
return m_global_conf.g_portion;
}
void config_manager_set_cho_interval(uint8_t cho_interval)
{
m_global_conf.cho_interval = cho_interval;
}
uint8_t config_manager_get_cho_interval(void)
{
return m_global_conf.cho_interval;
}
void config_manager_set_ins_interval(uint8_t ins_interval)
{
m_global_conf.ins_interval = ins_interval;
}
uint8_t config_manager_get_ins_interval(void)
{
return m_global_conf.ins_interval;
}
void config_manager_set_insulin_type(uint8_t type)
{
m_global_conf.insulin_type = type;
}
uint8_t config_manager_get_insulin_type(void)
{
return m_global_conf.insulin_type;
}
void config_manager_set_insulin_total(uint16_t total)
{
m_global_conf.insulin_total = total;
}
uint16_t config_manager_get_insulin_total(void)
{
return m_global_conf.insulin_total;
}
void config_manager_set_insulin_remaining(uint16_t rem)
{
m_global_conf.insulin_remaining = rem;
}
uint16_t config_manager_get_insulin_remaining(void)
{
return m_global_conf.insulin_remaining;
}
void config_manager_set_insulin_start(uint16_t start)
{
m_global_conf.insulin_start = start;
}
uint16_t config_manager_get_insulin_start(void)
{
return m_global_conf.insulin_start;
}
void config_manager_set_insulin_max(uint16_t max)
{
m_global_conf.insulin_max = max;
}
uint16_t config_manager_get_insulin_max(void)
{
return m_global_conf.insulin_max;
}
void config_manager_set_insulin_duration(uint16_t d)
{
m_global_conf.insulin_duration = d;
}
uint16_t config_manager_get_insulin_duration(void)
{
return m_global_conf.insulin_duration;
}
void config_manager_set_name(uint8_t* data, uint8_t data_len)
{
uint8_t i;
if (data_len > 14) data_len = 14;
for(i = 0; i < 20; i++){
if(i < data_len){
m_global_conf.name[i] = (char)data[i];
} else {
m_global_conf.name[i] = '\0';
}
}
name_len = data_len;
}
uint8_t config_manager_get_name(char* data)
{
uint8_t i;
for(i = 0; i < name_len; i++){
data[i] = (char)m_global_conf.name[i];
}
data[name_len] = '\0';
return name_len;
}
sfloat_t config_manager_get_calc_low(void)
{
return m_global_conf.calc_low;
}
void config_manager_set_calc_low(sfloat_t low)
{
m_global_conf.calc_low = low;
}
sfloat_t config_manager_get_calc_high(void)
{
return m_global_conf.calc_high;
}
void config_manager_set_calc_high(sfloat_t high)
{
m_global_conf.calc_high = high;
}
uint16_t config_manager_get_calc_sens(void)
{
return m_global_conf.calc_sens;
}
void config_manager_set_calc_sens(uint16_t s)
{
m_global_conf.calc_sens = s;
}
sfloat_t config_manager_get_calc_corr(void)
{
return m_global_conf.calc_corr;
}
void config_manager_set_calc_corr(sfloat_t corr)
{
m_global_conf.calc_corr = corr;
}
uint8_t config_manager_get_version()
{
return VERSION;
}
uint16_t config_manager_get_serial_number()
{
return SN;
}