-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_us_sensor.cpp
More file actions
59 lines (38 loc) · 1.45 KB
/
Copy pathpage_us_sensor.cpp
File metadata and controls
59 lines (38 loc) · 1.45 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "ultrasound.h"
#include "structure.h"
namespace PageUltrasound{
Page page;
void on_ultrasound_distance_event(float distance){
if (page.is_editing){
// this if statment is for redundency we dont need it since
// this page is not editable
return;
}
int whole = (int)distance;
int fraction = (int)((distance - whole) * 10);
int value_buffer_size = sizeof(page.value);
// add the ultra sound data
snprintf(
page.value,
value_buffer_size,
"%d.%d ",
whole,
fraction
);
// add the units
page.value[value_buffer_size - 3] = 'c';
page.value[value_buffer_size - 2] = 'm';
// add ther terminator
page.value[value_buffer_size - 1] = '\0';
// update the page
//update_page(&ultrasuond_sensor_page); // outdated
page.schedul_update = true;
}
void init(){
size_t title_size = sizeof(page.title); // get the size of the string array
size_t value_size = sizeof(page.value); // get the size of the string array
strncpy(page.title, "< US SENSOR >\0", title_size);
strncpy(page.value, " \0", value_size);
Ultrasound::register_ultrasound_callback(on_ultrasound_distance_event);
}
}