-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEPD.ino
160 lines (133 loc) · 3.55 KB
/
EPD.ino
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
#include <LOLIN_EPD.h>
#include <Adafruit_GFX.h>
/*D32 Pro*/
#define EPD_CS 14
#define EPD_DC 27
#define EPD_RST 33 // can set to -1 and share with microcontroller Reset!
#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay)
LOLIN_IL3897 EPD(250, 122, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //hardware SPI
void setupEPD(void)
{
EPD.begin();
EPD.clearBuffer();
EPD.fillScreen(EPD_WHITE);
}
void epdDisplay()
{
EPD.display();
}
void epdDrawLines()
{
EPD.drawFastHLine( 1, 25, 250, EPD_BLACK);
EPD.drawFastHLine( 1, 26, 250, EPD_BLACK);
EPD.drawFastVLine( 83, 27, 80, EPD_BLACK);
EPD.drawFastVLine( 84, 27, 80, EPD_BLACK);
EPD.drawFastVLine(167, 27, 80, EPD_BLACK);
EPD.drawFastVLine(168, 27, 80, EPD_BLACK);
EPD.drawFastHLine( 1, 107, 250, EPD_BLACK);
EPD.drawFastHLine( 1, 108, 250, EPD_BLACK);
}
void epdSetDate(String dateString)
{
EPD.setTextColor(EPD_BLACK);
EPD.setTextSize(2);
EPD.setCursor(125 - (6*dateString.length()), 3);
EPD.println(dateString);
}
void epdDayStatistics(float current, float previous, int delta, float consumed)
{
epdDrawValues(1, current, previous, delta, consumed);
}
void epdMonthStatistics(float current, float previous, int delta, float consumed)
{
epdDrawValues(2, current, previous, delta, consumed);
}
void epdYearStatistics(float current, float previous, int delta, float consumed)
{
epdDrawValues(3, current, previous, delta, consumed);
}
void epdDrawValues( int box, float current, float previous, int delta, float consumption)
{
int x = 0;
int y = 60;
int accuracy = 0;
if ( box == 1 ) {
x = 1;
if ( getOrder(current) < 3 )
accuracy = 1;
} else if ( box == 2 ) {
x = 85;
} else if ( box = 3 ) {
x = 169;
}
EPD.setTextColor(EPD_BLACK);
int fontSize = 3;
EPD.setTextSize(fontSize);
EPD.setCursor(x+41 - (6*fontSize*(getOrder(current)+2*accuracy)-fontSize)/2, y);
EPD.println(current, accuracy);
fontSize = 1;
EPD.setTextSize(fontSize);
EPD.setCursor(x+2, 31);
//EPD.setCursor(x+2, y -(8+20));
EPD.println(previous, accuracy);
EPD.setTextSize(fontSize);
EPD.setCursor(x+79 - (fontSize*6*getDeltaSize(delta)-fontSize) , 31);
//EPD.setCursor(x+79 - (fontSize*6*getDeltaSize(delta)-fontSize) , y-(8+20));
EPD.print(delta);
EPD.println("%");
if ( consumption > 0 ) {
EPD.setCursor(x+2, y+(3*8+12));
EPD.println(consumption, accuracy);
float delta = current - consumption;
EPD.setCursor(x+79 - (fontSize*6*(getSize(delta)+2*accuracy)-fontSize), y+(3*8+12));
EPD.println(delta, accuracy);
}
}
void epdGenerating(bool generating)
{
if ( generating )
{
EPD.setTextColor(EPD_BLACK);
EPD.setTextSize(1);
EPD.setCursor(95, 113);
EPD.print("GENERATING");
}
}
void epdPrintUpdateTime(String time)
{
EPD.setTextColor(EPD_BLACK);
EPD.setTextSize(1);
EPD.setCursor(218, 113);
EPD.println(time);
}
void epdPrintBatteryState(int percentage, float voltage)
{
EPD.setTextColor(EPD_BLACK);
EPD.setTextSize(1);
EPD.setCursor(1, 113);
EPD.print(percentage);
EPD.print("%, ");
EPD.print(voltage,1);
EPD.println(" V");
}
void epdSleep()
{
Serial.println("Put EPD display in sleep");
EPD.deepSleep();
}
///////////////////////////////////////////////////////
// Helpers
int getOrder(float value)
{
// returns 'size' of value, i.e. the order of magnitude
return (value < 1) ? 1 : floor(log10(value+0.5)+1);
}
int getSize(float value)
{
int sign = value < 0 ? 1 : 0;
return getOrder(abs(value)) + sign;
}
int getDeltaSize(int delta)
{
return getSize(delta) + 1;
}