This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOledScreen.cpp
116 lines (103 loc) · 2.73 KB
/
OledScreen.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
#include "OledScreen.h"
#include "Settings.h"
#include <Wire.h>
#include <LOLIN_I2C_BUTTON.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <WiFiUdp.h>
#include "ESP8266mDNS.h"
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
I2C_BUTTON button(DEFAULT_I2C_BUTTON_ADDRESS); //I2C Address 0x31
String keyString[] = {"None", "Press", "Long", "Double", "Hold"};
OledScreen::OledScreen(bool inDebugMode)
{
debugMode = inDebugMode;
}
// start screen en display text
void OledScreen::start()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0); // col, row
display.println("Booting..");
display.display();
// sleep
delay(500);
handle();
}
void OledScreen::handle()
{
if (button.get() == 0) // Button press
{
// Display IP
if (button.BUTTON_A)
{
if (debugMode)
{
Serial.println("Button A pressed");
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("IP: ");
display.setCursor(0, 10);
display.println(WiFi.localIP());
display.display();
delay(2000);
}
display.clearDisplay();
// if set, WIFI and MQTT status is shows
if (SHOW_CONNECTION_STATUS)
{
if (hasWIFI)
{
display.setCursor(0, 0);
display.println("WIFI: Y");
}
else
{
display.setCursor(0, 0);
display.println("WIFI: N");
}
if (hasMQTT)
{
display.setCursor(0, 10);
display.println("MQTT: Y");
}
else
{
display.setCursor(0, 10);
display.println("MQTT: N");
}
if (lastEco2 != 0)
{
display.setCursor(0, 30);
display.println("eCO2: " + String(lastEco2));
}
if (lastTVoc != 0)
{
display.setCursor(0, 40);
display.println("TVOC: " + String(lastTVoc));
}
}
else
{
if (lastEco2 != 0)
{
display.setCursor(0, 15);
display.println("ECO2: " + String(lastEco2));
}
if (lastTVoc != 0)
{
display.setCursor(0, 25);
display.println("TVOC: " + String(lastTVoc));
}
}
display.display();
}
}