forked from shashwat001/hollow_clock_wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock_time.cpp
More file actions
41 lines (33 loc) · 1.33 KB
/
clock_time.cpp
File metadata and controls
41 lines (33 loc) · 1.33 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
#include "clock_time.h"
int calculate_steps_for_time(int hours, int minutes, int steps_per_rotation) {
int total_steps = 0;
total_steps += (hours % 12) * steps_per_rotation;
total_steps += (minutes * steps_per_rotation) / 60;
return total_steps;
}
String format_hhmm_text(int hours, int minutes) {
char buffer[6];
snprintf(buffer, sizeof(buffer), "%02d:%02d", hours, minutes);
return String(buffer);
}
String format_uptime_text(unsigned long millis_value) {
unsigned long total_seconds = millis_value / 1000UL;
unsigned long hours = total_seconds / 3600UL;
unsigned long minutes = (total_seconds % 3600UL) / 60UL;
unsigned long seconds = total_seconds % 60UL;
char buffer[64];
snprintf(buffer, sizeof(buffer), "%lu:%02lu:%02lu (%lu ms)",
hours, minutes, seconds, millis_value);
return String(buffer);
}
void sync_time_state(NTPClient *time_client, String *formatted_time) {
time_client->update();
*formatted_time = time_client->getFormattedTime();
}
int calculate_current_time_steps(NTPClient *time_client, String *formatted_time,
int steps_per_rotation) {
sync_time_state(time_client, formatted_time);
return calculate_steps_for_time(time_client->getHours(),
time_client->getMinutes(),
steps_per_rotation);
}