-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreen.cpp
127 lines (103 loc) · 2.94 KB
/
screen.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "screen.h"
Screen::Screen() :
lcd(LiquidCrystal_I2C(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)), printedTrip1Distance(0), printedTrip2Distance(0), printedTankDistance(0) {
}
void Screen::setupScreen() {
lcd.begin(20, 4);
lcd.setCursor(0,0);
lcd.print("Crappy Tripmaster");
}
void Screen::registerTripMaster(TripMaster* _tripMaster) {
tripMaster = _tripMaster;
}
void Screen::updateScreenDirection() {
bool up = false;
bool down = false;
if(tripMaster->currentDirection == forward) {
up = true;
}
else if(tripMaster->currentDirection == backward) {
down = true;
}
lcd.setCursor(0,0);
up ? lcd.print("X") : lcd.print(".");
lcd.setCursor(0,1);
down ? lcd.print("X") : lcd.print(".");
}
void Screen::updateScreenTrips() {
if(tripMaster->trip1->tripDistance - printedTrip1Distance > 0.1 || printedTrip1Distance - tripMaster->trip1->tripDistance > 0.1)
{
int printableTrip1_pre = (int) tripMaster->trip1->tripDistance;
int printableTrip1_after = (int) ((tripMaster->trip1->tripDistance - printableTrip1_pre)*10);
lcd.setCursor(0,2);
lcd.print(printableTrip1_pre);
lcd.setCursor(0,5);
lcd.print(".");
lcd.setCursor(0,6);
lcd.print(printableTrip1_after);
}
if(tripMaster->trip2->tripDistance - printedTrip2Distance > 0.1 || printedTrip2Distance - tripMaster->trip2->tripDistance > 0.1)
{
int printableTrip2_pre = (int) tripMaster->trip2->tripDistance;
int printableTrip2_after = (int) ((tripMaster->trip2->tripDistance - printableTrip2_pre)*10);
lcd.setCursor(0,14);
lcd.print(printableTrip2_pre);
lcd.setCursor(0,17);
lcd.print(".");
lcd.setCursor(0,18);
lcd.print(printableTrip2_after);
}
if(tripMaster->tank->tripDistance - printedTankDistance > 0.1 || printedTankDistance - tripMaster->tank->tripDistance > 0.1)
{
int printableTank_pre = (int) tripMaster->tank->tripDistance;
int printableTank_after = (int) ((tripMaster->tank->tripDistance - printableTank_pre)*10);
lcd.setCursor(3,8);
lcd.print(printableTank_pre);
lcd.setCursor(3,11);
lcd.print(".");
lcd.setCursor(3,12);
lcd.print(printableTank_after);
}
}
void Screen::updateTime() {
//time_t t = now()
//if(minute(t) == printedTime)
//{
//}
lcd.setCursor(3,14);
lcd.print("HH");
lcd.setCursor(3,16);
lcd.print(":");
lcd.setCursor(3,17);
lcd.print("MM");
}
void Screen::updateScreenShowTrip() {
updateTime();
updateScreenTrips();
updateScreenDirection();
}
void Screen::updateScreenShowMenu() {
lcd.setCursor(0,0);
lcd.print("THIS IS THE MENU");
lcd.setCursor(3,0);
lcd.print("NOTHING MUCH BUT W/E") ;
}
void Screen::updateScreen(Event e) {
switch(e) {
case updatedirection:
updateScreenDirection();
break;
case updatetrip:
updateScreenTrips();
break;
case togglemenu:
updateScreenShowMenu();
break;
case initdone:
//clearScreen();
updateScreenShowTrip();
break;
default:
;
}
}