-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChamberDisplay.cpp
199 lines (170 loc) · 4.5 KB
/
ChamberDisplay.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//Copyright 2014, Alex Khilko.
//This file is part of LifeChamber which is released under MIT.
//See file LICENSE.TXT or go to www.alexkhilko.com for full license details.
#include "Config.h"
#include "ChamberDisplay.h"
#include "ChamberDevices.h"
#include "Preset.h"
#include <stdio.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display(DISPLAY_DC, DISPLAY_CS, DISPLAY_RST);
#define PREZERO(a) if(a < 10) display.print("0");
void ChamberDisplayClass::init()
{
display.begin();
display.setContrast(DISPLAY_CONTRAST);
display.clearDisplay();
display.setRotation(0);
display.setTextSize(1);
display.setTextColor(BLACK);
}
void ChamberDisplayClass::drawMoisture(int at)
{
if (at != -1) display.setCursor(0, at); else at = 0;
display.setTextSize(1);
display.println(F("Moisture:"));
display.drawRoundRect(0, at + 9, LCDWIDTH, 10, 5, BLACK);
display.fillRoundRect(0, at + 9, calcMoistureFillWidth(ChamberDevices.getMoisture()), 10, 5, BLACK);
display.setCursor(map(Preset.getMoistureGoal(), 0, 100, 2, 78), at + 18); //min 2, max 78
display.write(30);
}
void ChamberDisplayClass::drawTemp(int at)
{
if (at != -1) display.setCursor(0, at); else at = 0;
char str[20];
display.print(F("Temp: "));
dtostrf(ChamberDevices.getTemp(), 1, 1, str);
display.print(str);
display.write(9);
display.println("C");
}
void ChamberDisplayClass::drawAge(int at)
{
if (at != -1) display.setCursor(0, at); else at = 0;
DateTime currentTime = ChamberDevices.getTime();
if (currentTime.unixtime() == 0)
{
display.println("Age: Unknown");
return;
} else
display.print("Age: ");
TimeSpan sincePlanted = currentTime - Preset.getPlantTime();
if (sincePlanted.days() > 0)
{
display.print(sincePlanted.days());
display.print(F("d "));
display.print(sincePlanted.hours());
display.println(F("h"));
} else
if (sincePlanted.hours() > 0)
{
display.print(sincePlanted.hours());
display.print(F("h "));
display.print(sincePlanted.minutes());
display.println(F("m"));
} else
{
display.print(sincePlanted.minutes());
display.print(F("m "));
display.print(sincePlanted.seconds());
display.println(F("s"));
}
}
void ChamberDisplayClass::drawLight(int at)
{
if (at != -1) display.setCursor(0, at); else at = 0;
int timeHours = Preset.getLightHours();
display.print(F("Light amount: "));
if (timeHours == LIGHT_MIN)
{
display.println(F(" Always OFF"));
return;
} else
if (timeHours == LIGHT_MAX)
{
display.println(F(" Always ON"));
return;
}
display.print(" ");
display.print(timeHours);
display.println(F("h per day"));
}
void ChamberDisplayClass::drawDateTime(int at)
{
if (at != -1) display.setCursor(0, at); else at = 0;
DateTime dt = ChamberDevices.getTime();
display.print(dt.hour()); display.print(":");
PREZERO(dt.minute()); display.print(dt.minute()); display.print(" ");
PREZERO(dt.day()); display.print(dt.day()); display.print("/");
PREZERO(dt.month()); display.println(dt.month());
}
void ChamberDisplayClass::drawMain()
{
display.clearDisplay();
drawMoisture(0);
drawTemp(25);
drawAge(-1);
drawDateTime(-1);
display.display();
}
int ChamberDisplayClass::calcMoistureFillWidth(int moisture)
{
return map(moisture, 0, 100, 0, LCDWIDTH - 1);
}
void ChamberDisplayClass::drawMoistureConfig()
{
display.clearDisplay();
display.setCursor(0, 0);
drawMoisture(0);
drawChangeInfo(24);
display.display();
}
void ChamberDisplayClass::drawTempConfig()
{
display.clearDisplay();
display.setCursor(0, 0);
drawTemp(0);
display.print(F("Desired: "));
int tempGoal = Preset.getTempGoal();
display.print(tempGoal);
display.print(" ");
display.write(9);
if (tempGoal < 10)
display.println("C");
else
display.print("C");
drawChangeInfo(-1);
display.display();
}
void ChamberDisplayClass::drawLightConfig()
{
display.clearDisplay();
display.setCursor(0, 0);
drawLight(0);
drawChangeInfo(-1);
display.display();
}
void ChamberDisplayClass::drawChangeInfo(int at, bool bothToReset)
{
if (at != -1) display.setCursor(0, at); else at = 0;
display.print(F("--------------"));
display.print(F("Press "));
display.write(17);
display.print(bothToReset == true ? F(" and ") : F(" or "));
display.write(16);
display.println(bothToReset == true ? F(" to reset.") : F(" to change."));
display.write(8);
display.println(F(" to continue."));
}
void ChamberDisplayClass::drawAgeConfig()
{
display.clearDisplay();
display.setCursor(0, 0);
drawAge(0);
display.println("");
drawChangeInfo(-1, true);
display.display();
}
ChamberDisplayClass ChamberDisplay;