-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLcdPrintFunctions.cpp
108 lines (93 loc) · 2.2 KB
/
LcdPrintFunctions.cpp
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
105
106
107
108
#include "LcdPrintFunctions.hpp"
#include "Globals.hpp"
#include "Util.hpp"
static void printActiveAlarms(){
const int8_t beginning = 15 - (TOTAL_ALARMS - 1);
lcd.setCursor(beginning - 1, 1);
if (alarms.isAnyActivated()){
lcd.print("A");
for (int8_t i = 0; i < TOTAL_ALARMS; i ++){
if (alarms.isAlarmActivated(i)){
lcd.print(i + 1);
}else{
lcd.print(" ");
}
}
}else{
for (int8_t i = 0; i < TOTAL_ALARMS + 1; i++){
lcd.print(" ");
}
}
}
static void printTemperatureTopRight(float temp){
const int BEGINING = 10;
lcd.setCursor(BEGINING, 0);
int8_t totalLength = 3 + findLongLength(temp);
if (temp < 0){
totalLength++;
}
printTemperature(temp);
for (int i = totalLength + BEGINING; i < LCD_TOTAL_COLUMNS; i++){
lcd.print(" ");
}
}
char intToAscii(int8_t digit){
return char(48 + digit);
}
void displayTime(const Time& time, bool enableSecunds){
printZeroPaddedInt(time.hours, 2);
lcd.print(':');
printZeroPaddedInt(time.minutes, 2);
if (enableSecunds){
lcd.print(':');
printZeroPaddedInt(time.seconds, 2);
}
}
void displayDate(const Date& date){
printZeroPaddedInt(date.day, 2);
lcd.print('.');
printZeroPaddedInt(date.month, 2);
lcd.print('.');
printZeroPaddedInt(date.year, 4);
}
void displayDateTime(const Clock& clk){
lcd.home();
displayTime(clk.getTime(), true);
lcd.setCursor(0, 1);
displayDate(clk.getDate());
}
void printHomePage(const Clock& clk, bool clear){
if (clear){
lcd.clear();
}
displayDateTime(clk);
printActiveAlarms();
printTemperatureTopRight(tempHandler.getTemperature());
}
void printZeroPaddedInt(int32_t val, int8_t totalSymbols){
char buffer[12];
int32_t divider = pow10(totalSymbols);
int offset = 0;
if (val < 0){
buffer[0] = '-';
offset = 1;
val = -val;
}
for (int i = 0; i < totalSymbols; i++){
int8_t tmp = val / divider;
val -= tmp * divider;
buffer[offset + i] = intToAscii(tmp);
divider /= 10;
}
buffer[totalSymbols + offset] = '\0';
lcd.print(buffer);
}
//if previously had minus sign, clear last digit of it
void printZeroPaddedIntClearRight(int32_t val, int8_t totalSymbols){
printZeroPaddedInt(val, totalSymbols);
lcd.print(' ');
}
void printTemperature(float temp){
lcd.print(temp, 2);
lcd.print('C');
}