-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplaymanager.cpp
More file actions
185 lines (149 loc) · 4.61 KB
/
Copy pathdisplaymanager.cpp
File metadata and controls
185 lines (149 loc) · 4.61 KB
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
#include "displaymanager.h"
#include "tempprobemanager.h"
#include "pidmanager.h"
#include "WIFIManagerImpl.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define DISPLAY_SCK 23
#define DISPLAY_SDA 22
#define DISPLAY_RESET 25
#define DISPLAY_I2C_FREQ 800000
#define DISPLAY_I2C_ADDR 0x3C
#define DISPLAY_CARD_COUNT 7
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, DISPLAY_RESET,DISPLAY_I2C_FREQ, DISPLAY_I2C_FREQ);
DisplayManager::DisplayManager(TempProbeManager& _probeMgr, PIDManager& __pidMgr, WifiManagerImpl& __wifiMgr):
probeMgr(_probeMgr), pidMgr(__pidMgr), wifiMgr(__wifiMgr)
{
pinMode(DISPLAY_RESET, OUTPUT);
digitalWrite(DISPLAY_RESET, HIGH);
}
void DisplayManager::begin()
{
if (!Wire.begin(DISPLAY_SDA, DISPLAY_SCK))
{
//DEBUG_PRINTLN("I2C failed");
for (;;);
}
Wire.setClock(DISPLAY_I2C_FREQ);
display.setRotation(2);
if (!display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDR, true, false))
{
//DEBUG_PRINTLN("SSD1306 allocation failed");
for (;;);
}
display.clearDisplay();
// testdrawline();
display.display();
}
void DisplayManager::testdrawline() {
int16_t i;
display.clearDisplay(); // Clear display buffer
for(i=0; i<display.width(); i+=4) {
display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE);
display.display(); // Update screen with each newly-drawn line
delay(1);
}
for(i=0; i<display.height(); i+=4) {
display.drawLine(0, 0, display.width()-1, i, SSD1306_WHITE);
display.display();
delay(1);
}
delay(250);
display.clearDisplay();
for(i=0; i<display.width(); i+=4) {
display.drawLine(0, display.height()-1, i, 0, SSD1306_WHITE);
display.display();
delay(1);
}
for(i=display.height()-1; i>=0; i-=4) {
display.drawLine(0, display.height()-1, display.width()-1, i, SSD1306_WHITE);
display.display();
delay(1);
}
delay(250);
display.clearDisplay();
for(i=display.width()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE);
display.display();
delay(1);
}
for(i=display.height()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, 0, i, SSD1306_WHITE);
display.display();
delay(1);
}
delay(250);
display.clearDisplay();
for(i=0; i<display.height(); i+=4) {
display.drawLine(display.width()-1, 0, 0, i, SSD1306_WHITE);
display.display();
delay(1);
}
for(i=0; i<display.width(); i+=4) {
display.drawLine(display.width()-1, 0, i, display.height()-1, SSD1306_WHITE);
display.display();
delay(1);
}
delay(2000); // Pause for 2 seconds
}
typedef void (*drawLine)();
void DisplayManager::printTemp()
{
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.printf("Temp:%.1f", probeMgr.getTemp1());
}
void DisplayManager::printTargetTemp()
{
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 17);
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.printf("Targt:%.1f", pidMgr.getSetpoint());
}
void DisplayManager::printState()
{
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 34);
display.cp437(true); // Use full 256 char 'Code Page 437' font
const char* strState = "Idle";
state = pidMgr.getState();
if(state == PIDManager::Tuning)
{
strState = "Tuning";
}
else if(state == PIDManager::PidEnabled)
{
strState = "PID Running";
}
display.printf("State:\n%s", strState);
}
void DisplayManager::printIP()
{
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0);
display.cp437(true); // Use full 256 char 'Code Page 437' font
String ip = wifiMgr.GetIp().toString();
display.printf("IP:%s", ip);
}
void DisplayManager::loop()
{
uint32_t now = millis();
if(now - last_read < SAMPLE_INTERVAL)
{
return;
}
last_read = now;
display.clearDisplay();
printTemp();
printTargetTemp();
printState();
display.display();
}