-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_enviroment.cpp
More file actions
44 lines (31 loc) · 1.31 KB
/
Copy pathpage_enviroment.cpp
File metadata and controls
44 lines (31 loc) · 1.31 KB
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
#include "environment.h"
#include "structure.h"
namespace PageEnviroment {
Page page;
void on_environment_event(float temperature, float humidity) {
int temperature_whole = (int)temperature;
int temperature_fraction = (int)((temperature - temperature_whole) * 10);
int humidity_whole = (int)humidity;
int humidity_fraction = (int)((humidity - humidity_whole) * 10);
int value_buffer_size = sizeof(page.value);
snprintf(
page.value,
value_buffer_size,
"T:%d.%dC H:%d.%d% ",
temperature_whole,
temperature_fraction,
humidity_whole,
humidity_fraction
);
page.value[sizeof(page.value) - 1] = '\0'; // add the terminator at the end
// mark the page for update
page.schedul_update = true;
}
void init() {
strncpy(page.title, "< ENVIROMNET >", sizeof(page.title));
page.title[sizeof(page.title) - 1] = '\0'; // add the terminator at the end
memset(page.value, ' ', sizeof(page.value)); // make it empty at the start
page.value[sizeof(page.value) - 1] = '\0'; // add the terminator at the end
Environment::register_environment_callback(on_environment_event);
}
}