-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_alarm.cpp
More file actions
104 lines (60 loc) · 2.59 KB
/
Copy pathpage_alarm.cpp
File metadata and controls
104 lines (60 loc) · 2.59 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
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 "clock.h"
#include "structure.h"
namespace PageAlarm{
Page page;
void alarm_apply_time(){
// same funcality as before but this one sets the alarm
int hours = 0, minutes = 0, seconds = 0;
const char* buf = page.value; // am using buf for simplisty
// simple validation expect format "hh:mm"
// we will check for : values just in case
if (buf[2] == ':') {
hours = (buf[0] - '0') * 10 + (buf[1] - '0');
minutes = (buf[3] - '0') * 10 + (buf[4] - '0');
if (hours >= 0 && hours < 24 &&
minutes >= 0 && minutes < 60)
{
// now hours minutes seconds are ready as integers
Clock::set_alarm(
hours,
minutes
);
}
else {
size_t value_size = sizeof(page.value);
// invalid time dont set and re display the previouse correct time
strncpy(page.value, " ", value_size);
snprintf(page.value,
value_size,
"%02d:%02d ",
Clock::get_alarm_hour(),
Clock::get_alarm_mintues()
); // write time when we start
page.value[value_size - 1] = "\0"; // add the terminator since snprintf doesnt add it for you
// now we can update the screen for the user to see the correct time
//update_page(current_page); // this is outdated schdual and update instead
page.schedul_update = true;
return;
}
}
else {
// invalid format dont set
}
}
void init(){
size_t title_size = sizeof(page.title);
size_t value_size = sizeof(page.value);
strncpy(page.title, "< ALARM TIME >\0", title_size);
// we need to set the time on start we get it from the clock
strncpy(page.value, " \0", value_size);
snprintf(page.value,
value_size,
"%02d:%02d ",
Clock::get_alarm_hour(),
Clock::get_alarm_mintues()
); // write time when we start
page.value[value_size - 1] = "\0"; // add the terminator since snprintf doesnt add it for you
page.is_editable = true;
page.apply_function = alarm_apply_time;
}
}