-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
96 lines (83 loc) · 1.98 KB
/
display.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
#include "display.h"
#include <Arduino.h>
#include <WiFi.h>
#include <splash.h>
#include "beep.h"
Adafruit_SSD1305 *_display;
bool *_armed;
int announce = -1;
unsigned long lastarmed = millis();
bool showarmed = false;
unsigned long displayOn;
void animArmed(){
if(millis() - lastarmed > 250){
showarmed = !showarmed;
lastarmed = millis();
}
if(showarmed){
_display->println(" --- ARMED ---");
// Circles in the top corners for attention
_display->fillCircle(5,5,5,WHITE);
_display->fillCircle(122,5,5,WHITE);
}
else
_display->println("");
}
void resetDisplayTimeout(){
displayOn = millis();
}
void announceArming(){
displayOn = millis();
announce = 5;
do{
beep(50, 1);
updateDisplay();
delay(1000);
announce--;
}
while(announce > -1);
}
void updateDisplay(){
//Turn off after 60 secs, if not armed
if(millis() - displayOn > 60000 && !*_armed){
_display->clearDisplay();
_display->display();
return;
}
_display->clearDisplay();
_display->setTextSize(1);
_display->setCursor(32,0);
_display->println("FIRE SYSTEM");
_display->setTextSize(1);
if(!*_armed && announce == -1)
_display->println(" TEST MODE");
else if(*_armed)
animArmed();
else{
_display->printf(" ARMING IN %us\n", announce);
// Circles in the top corners for attention
_display->fillCircle(5,5,5,WHITE);
_display->fillCircle(122,5,5,WHITE);
}
_display->print("IP: ");
_display->println(WiFi.softAPIP());
_display->display();
}
void setupGraphics(bool *armed, Adafruit_SSD1305 *display){
if ( ! display->begin(0x3C) ) {
Serial.println("Unable to initialize OLED");
while (1) yield();
}
// Set as globals
_armed = armed;
_display = display;
// Clear display contents
_display->clearDisplay();
_display->display();
_display->setTextSize(1);
_display->setTextColor(WHITE);
_display->setCursor(0,0);
_display->println("Init...");
_display->display();
displayOn = millis();
}