-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayingData.ino
255 lines (199 loc) · 7.45 KB
/
DisplayingData.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//OLED_Display
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <SPI.h> //just for compilation - to not show errors
#include <Wire.h> //I2C communication
#include <Adafruit_GFX.h> //Base graphic library
#include <ESP_SSD1306.h> //OLED display controling library
//16x2 display Version
#include <LiquidCrystal_I2C.h>
#include "symbolsDefine.h"
#define OLED_DISPLAY_ADDRESS 0x3c
#define LCD_DISPLAY_ADDRESS 0X27
LiquidCrystal_I2C lcd(LCD_DISPLAY_ADDRESS, 16, 2); // set the lcd address to 0x27 for a 16 chars and 2 line display
ESP_SSD1306 oledDisplay(-1);// -1 means no reset pin, library edited
#define serviceAreaDisplayStartCol 0
#define serviceAreaDisplayStartRow 1
#define serviceAreaDisplayLength 8
bool lcdDisplayConnected_global = false;
bool oledDisplayConnected_global = false;
void i2cBus_setup()
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(" F:i2cBus_setup()");
Wire.begin(4, 5); //Wire.begin(int sda, int scl) !!! labels GPIO4 and GPIO5 on EPS8266 are swaped at old esps!!!!
Wire.beginTransmission(LCD_DISPLAY_ADDRESS);
if (Wire.endTransmission() == 0)
lcd_setup();
Wire.beginTransmission(OLED_DISPLAY_ADDRESS);
if (Wire.endTransmission() == 0)
oledDisplay_setup();
}
void lcd_setup()
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(" F:lcd_setup()");
lcdDisplayConnected_global = true;
// initialize the lcd
lcd.begin();
lcd.createChar(6, newCharDrop);
lcd.createChar(7, newCharTemp);
// Turn on the blacklight and print a message.
lcd.backlight();
showServiceMessage("Loading...");
lcd.setCursor(9, 0);
lcd.write(6);//drop symbol
displayPrintAt("0.0L " , 10, 0);
lcd.setCursor(0, 0);
lcd.write(7);//temp symbol
}
void oledDisplay_setup()
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(" F:oledDisplay_setup()");
oledDisplayConnected_global = true;
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
oledDisplay.begin(SSD1306_SWITCHCAPVCC, OLED_DISPLAY_ADDRESS); // initialize with the I2C addr 0x3c (for the 128x64)
oledDisplay.clearDisplay();
oledDisplay.display();
//if(!DEBUG_REMOTE_CONSOLE) remoteConsole.assignDisplayOutput(&oledDisplay, 0,2,150);
oledDisplay.setTextSize(1);
oledDisplay.setTextColor(WHITE, BLACK);
}
void displayData_loop(int)
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(" F:displayData_loop()");
if(waterFlowSensorCount_ISR_global > 1)
showServiceMessage(getWaterFlowLitresInMinutes() + "");
else
showServiceMessage(getStringUpTime() + " ");
char bufferCharConversion[10]; //temporarily holds data from vals
int row = 0;
//Temperature
// lcd.write(7);//temp symbol
if(lcdDisplayConnected_global)
{
if(lastTemp_global == ERROR_TEMP_VALUE_MINUS_127)
displayPrintAt(" -- ", 1, 0); // prints
else
{
dtostrf(lastTemp_global, 2, 2, bufferCharConversion); //float value lastTemp_global is copied onto buff bufferCharConversion
displayPrintAt(bufferCharConversion, 1, 0); // prints temp on OLED
lcd.print((char)223);//Degree Symbol°
// oledDisplay.write(759);//° symbol
displayPrint("C");
dtostrf(pipeTemp_global, 2, 2, bufferCharConversion); //float value lastTemp_global is copied onto buff bufferCharConversion
displayPrintAt(bufferCharConversion, 10, 1); // prints temp on OLED
lcd.print((char)223);//Degree Symbol°
//oledDisplay.write(759);//° symbol
displayPrint("C");
}
}
if(oledDisplayConnected_global)
{
//float namerenaTeplotaVBojleru = readTemperature();
if(lastTemp_global != ERROR_TEMP_VALUE_MINUS_127)
if(lastTemp_global)
{
//lcd.write('^');
oledDisplay.write(24);//up arrow symbol
}
else
{
//lcd.write('_');
oledDisplay.write(25);//down arrow symbol
}
}
//If changed Water Flow state
if(waterFlowSensorCount_ISR_global > lastWaterFlowSensorCount_global || waterFlowDisplay_global == 0)
{
dtostrf(convertWaterFlowSensorImpulsesToLitres(waterFlowDisplay_global + lastWaterFlowSensorCount_global), 4, 1, bufferCharConversion); //4 is mininum width, 4 is precision; float value is copied onto buff
displayPrintAt(bufferCharConversion, 10, row); // prints flow on OLED
displayPrint("L ");
}
if(oledDisplayConnected_global)
{
oledDisplay.setCursor(0, 4 * 8);//4*8 4.řádek * 8bodů font
oledDisplay.print("MainTemp: ");
oledDisplay.print(lastTemp_global);
oledDisplay.println(" ");
oledDisplay.print("FlowTemp: ");
oledDisplay.print(flowTemp_global);
oledDisplay.println(" ");
oledDisplay.print("PipeTemp: ");
oledDisplay.print(pipeTemp_global);
oledDisplay.println(" ");
oledDisplay.display();
}
}
void showServiceMessage(String message) {showServiceMessage(message.c_str());}
void showServiceMessage(char const* message)
{
if(DISPLAY_DEBUG) DEBUG_OUTPUT.print("DsiplayServiceMessage: ");
if(DISPLAY_DEBUG) DEBUG_OUTPUT.println(message);
eraseServiceDisplayArea();
displayPrintAt(message, 0, 1);
}
void eraseServiceDisplayArea()
{
const char* message = " ";
if(lcdDisplayConnected_global)
{
lcd.setCursor(serviceAreaDisplayStartCol, serviceAreaDisplayStartRow);
lcd.print(message);
}
if(oledDisplayConnected_global)
{
oledDisplay.setCursor(serviceAreaDisplayStartCol * 6, serviceAreaDisplayStartRow * 8);
oledDisplay.print(message);
oledDisplay.display();
}
}
/////////////////////////////////////////////////////
//////////////Internal functions/////////////////////
/////////////////////////////////////////////////////
void displayPrintAt(char const* message, int col, int row)
{
if(lcdDisplayConnected_global)
{
lcd.setCursor(col, row);
lcd.print(message);
}
yield();
if(oledDisplayConnected_global)
{
oledDisplay.setCursor(col * 6, row * 8);
oledDisplay.print(message);
oledDisplay.display();
}
}
void displayPrint(char const* message)
{
if(lcdDisplayConnected_global)
lcd.print(message);
if(oledDisplayConnected_global)
oledDisplay.print(message);
}
String getTimeFromLastUpdate()
{
return formatTimeToString(millis() - lastUpdateTime_global);
}
String getStringUpTime()
{
return formatTimeToString(millis());
}
String formatTimeToString(long timeInMilliseconds)
{
byte hoursFromLastSend = timeInMilliseconds / 1000 / 60 / 60;
byte minutesFromLastSend = timeInMilliseconds / 1000 / 60 - hoursFromLastSend * 60;
byte secondsFromLastSend = timeInMilliseconds / 1000 - minutesFromLastSend * 60 - hoursFromLastSend * 60 * 60;
return ((hoursFromLastSend <10 ) ? "0" : "") + (String)hoursFromLastSend + ":" + ((minutesFromLastSend <10 ) ? "0" : "") + (String)minutesFromLastSend + ":" + ((secondsFromLastSend <10 ) ? "0" : "") + (String)secondsFromLastSend;
}