-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_engine.h
More file actions
49 lines (42 loc) · 893 Bytes
/
Copy pathtimer_engine.h
File metadata and controls
49 lines (42 loc) · 893 Bytes
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
#ifndef TIMER_ENGINE_H
#define TIMER_ENGINE_H
String formatTime(uint32_t seconds)
{
uint32_t minutes = seconds / 60;
uint32_t secs = seconds % 60;
char buffer[8];
snprintf(buffer, sizeof(buffer), "%02lu:%02lu",
static_cast<unsigned long>(minutes),
static_cast<unsigned long>(secs));
return String(buffer);
}
uint16_t selectedMinutes()
{
return selectedSeconds / 60;
}
float remainingRatio()
{
if (selectedSeconds == 0)
{
return 0.0f;
}
float ratio = static_cast<float>(remainingSeconds) / static_cast<float>(selectedSeconds);
if (ratio < 0.0f)
{
return 0.0f;
}
if (ratio > 1.0f)
{
return 1.0f;
}
return ratio;
}
uint8_t remainingPercent()
{
return static_cast<uint8_t>(remainingRatio() * 100.0f);
}
String timerMetaText()
{
return String(selectedMinutes()) + " min / " + String(remainingPercent()) + "%";
}
#endif