antigneous/facp/src/main.cpp

1688 lines
59 KiB
C++
Raw Normal View History

2022-07-04 18:07:36 -04:00
#include <Arduino.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#include <string.h>
2022-09-27 22:31:38 -04:00
unsigned long systemClock; //-----------------SYSTEM CLOCK [VERY IMPORTANT]
unsigned long lastPulse; //-------------------LAST void loop() PULSE
2022-07-04 19:28:48 -04:00
char *firmwareRev = "1.1"; //VERSION
int EEPROMVersion = 1; //version control to rewrite eeprom after update
int EEPROMBuild = 1;
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- RUNTIME VARIABLES
2022-07-04 18:07:36 -04:00
bool fullAlarm = false; //bool to control if this is a full alarm that requres a panel reset to clear
bool silenced = false;
bool keyInserted = false; //if the control panel has a key inserted
2022-09-27 22:31:38 -04:00
bool readyLedStatus = false; //ready led status (this variable is for the trouble response code)
2022-07-04 18:07:36 -04:00
bool horn = false; //bool to control if the horns are active
bool strobe = false; //bool to control if the strobes are active
bool trouble = false; //bool to control if the panel is in trouble
bool troubleAck = false; //bool to control if the trouble is acknowledged
bool configMenu = false; //determine if the control panel is in the configuration menu
bool resetPressed = false;
bool silencePressed = false; //make sure that presses don't count more than once
bool drillPressed = false;
bool resetStillPressed = false;
bool silenceStillPressed = false; //make sure that presses don't count more than once
bool drillStillPressed = false;
bool updateScreen = false; //updating the screen in the config menu
bool possibleAlarm = false; //panel receieved 0 from pull station ciruit and is now investigating
bool walkTest = false; //is the system in walk test
bool silentWalkTest = false;
bool backlightOn = true;
2022-09-25 13:24:30 -04:00
bool keyRequiredVisual; //variable for panel security
bool debug = false;
2022-07-04 18:07:36 -04:00
int characters[] = {32,45,46,47,48,49,50,51,52,53,54,55,56,57,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}; //characters allowed on name
int panelNameList[16];
int clearTimer = 0; //timer for keeping track of button holding for clearing character in the name editor
int verification = 0; //number to keep track of ms for verification
int drill = 0; //number to keep track of ms for drill
2022-09-27 22:31:38 -04:00
int buttonCheckTimer = 0; //add a slight delay to avoid double-clicking buttons
2022-07-04 18:07:36 -04:00
int troubleTimer = 0; //ms for trouble
int codeWheelTimer = 0; //code wheel timing variable
int troubleLedTimer = 0; //number to keep track of ms for trouble light
int alarmLedTimer = 0; //alarm led timer
int troubleType = 0; //trouble type 0 - general, 1 - eol resistor
int lcdUpdateTimer = 0; //update delay
int lcdTimeoutTimer = 0; //timer to keep track of how long until lcd off
int walkTestSmokeDetectorTimer = 0;
int currentScreen = -1; //update display if previous screen is not the same
int configPage = 0; //config page for the config menu
int cursorPosition = 0; //which menu item the cursor is over
2022-09-29 17:39:07 -04:00
int zone1Count = 0; //walk test variables
int zone2Count = 0;
int zoneAlarm = 0; //which zone is in alarm 0 - none | 1 - zone 1 | 2 - zone 2 | 3 - zone 1 & 2 | 4 - drill
2022-07-04 18:07:36 -04:00
String configTop; //configuration menu strings for lcd
String configBottom;
String currentConfigTop; //configuration menu strings for current lcd display
String currentConfigBottom;
2022-09-30 19:07:30 -04:00
//---------------------------------------- CUSTOM LCD CHARACTERS
2022-09-25 23:54:40 -04:00
byte lock[] = { //lock icon
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11111,
B00000
};
2022-07-04 18:07:36 -04:00
2022-09-27 22:31:38 -04:00
byte check[] = { //check mark icon
B00000,
B00001,
B00011,
B10110,
B11100,
B01000,
B00000,
B00000
};
2022-09-30 19:07:30 -04:00
byte cross[] = { //x mark
B00000,
B11011,
B01110,
B00100,
B01110,
B11011,
B00000,
B00000
};
//---------------------------------------- CUSTOM LCD CHARACTERS
2022-09-19 20:46:43 -04:00
//Default EEPROM values in the case that the EEPROM fails to load
2022-07-04 18:07:36 -04:00
bool keyRequired = false; //determine if key switch is required to operate buttons
bool isVerification = true; //is verification turned on
bool eolResistor = true; //is the EOL resistor enabled
bool preAlarm = false; //use pre-alarm?
bool smokeDetectorPreAlarm = false; //should smoke detectors activate first stage
bool audibleSilence = true;
int smokeDetectorTimeout = 5; //how long should smoke detector pre-alarm wait before cancelling the pre-alarm
int firstStageTime = 1; //time in minutes that first stage should last
int codeWheel = 0; //which alarm pattern to use, code-3 default
2022-09-30 19:07:30 -04:00
float verificationTime = 2500;
2022-09-25 13:24:30 -04:00
//int resistorLenience = 0; DEPRECATED
2022-07-04 18:07:36 -04:00
int panelHomescreen = 0;
int lcdTimeout = 0;
String panelName = "";
LiquidCrystal_I2C lcd(0x27,16,2);
//PINS
int zone1Pin = 15;
2022-07-23 22:03:19 -04:00
int zone2Pin = 15; //TESTING is set to 15 but is normally 39.
2022-09-21 21:57:02 -04:00
int hornRelay = 13;
2022-07-04 18:07:36 -04:00
int buzzerPin = 4;
2022-09-21 21:57:02 -04:00
int strobeRelay = 18;
int smokeDetectorRelay = 14;
int readyLed = 27;
int silenceLed = 26;
int alarmLed = 25;
2022-07-04 19:28:48 -04:00
int keySwitchPin = 33;
2022-09-19 20:46:43 -04:00
int resetButtonPin = 32;
int silenceButtonPin = 35;
int drillButtonPin = 34;
2022-07-04 19:28:48 -04:00
int sclPin = 22;
int sdaPin = 21;
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- RUNTIME VARIABLES
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
2022-09-21 21:57:02 -04:00
//get resistor lenience by having zone 1, zone 2, and smoke on a output pin instead of +3.3v so you can measure the difference
2022-09-25 13:24:30 -04:00
//have it so holding down the drill button causes a visual indicator on the display along with blinking the alarm led really fast
2022-09-21 21:57:02 -04:00
2022-09-25 13:24:30 -04:00
//Add feature to calibrate activating, trouble, and normal voltages using the IO output instead of 3.3v
2022-09-21 21:57:02 -04:00
2022-09-25 13:24:30 -04:00
//maybe instead of looking for 0s for activation, simply look for a dip in voltage
2022-09-21 21:57:02 -04:00
2022-09-29 17:39:07 -04:00
//REMOVE STUPID ZERO COUNTER, ITS OBSELETE
2022-09-21 21:57:02 -04:00
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- EEPROM RESET
2022-07-04 18:07:36 -04:00
void resetEEPROM() {
for (int i=0; i<=1024; i++){ //write all 255's from 0-1024 address
EEPROM.write(i,255);
2022-09-19 20:46:43 -04:00
}
Serial.println("Erased EEPROM");
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
EEPROM.write(0,76);EEPROM.write(1,101);EEPROM.write(2,120);EEPROM.write(3,122);EEPROM.write(4,97);EEPROM.write(5,99);EEPROM.write(6,104); //write Lexzach to addresses 0-6
Serial.println("Wrote LEXZACH header");
EEPROM.write(7,0); //code-3 default
Serial.println("Configured Code-3");
EEPROM.write(8,0); //key not required by default
Serial.println("Disabled key");
EEPROM.write(9,1); //verification is turned on by default
Serial.println("Turned on verification");
EEPROM.write(10,25); //default verification time of 2.5 seconds
Serial.println("Set verification time of 2.5 seconds");
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
//system name "ANTIGNEOUS"
EEPROM.write(11,65);EEPROM.write(12,78);EEPROM.write(13,84);EEPROM.write(14,73);EEPROM.write(15,71);EEPROM.write(16,78);EEPROM.write(17,69);EEPROM.write(18,79);EEPROM.write(19,85);EEPROM.write(20,83);
Serial.println("Wrote system name 'ANTIGNEOUS'");
for (int i=21; i<=26; i++){ //write all 0's from 21-26 address
EEPROM.write(i,32);
}
Serial.println("Wrote 6 blank spaces");
2022-07-04 19:28:48 -04:00
2022-09-19 20:46:43 -04:00
EEPROM.write(50, EEPROMVersion); //write current version and build
EEPROM.write(51, EEPROMBuild);
Serial.println("Wrote EEPROM version and build");
2022-09-25 13:24:30 -04:00
//EEPROM.write(72,125); //EOL lenience 500 by default (take the value stored and multiply by 4 to get actual value)
//Serial.println("Set EOL lenience to 500");
2022-09-19 20:46:43 -04:00
EEPROM.write(73,1); //EOL resistor is enabled by default
Serial.println("Enabled EOL resistor");
EEPROM.write(74,0); //pre-alarm disabled by default
Serial.println("Disabled pre-alarm");
EEPROM.write(75,1); //pre-alarm first-stage is 1 minute by default
Serial.println("Set pre-alarm first stage to 1 minute");
EEPROM.write(76,0); //smoke detector pre-alarm is disable by default
Serial.println("Disabled smoke detector pre-alarm");
EEPROM.write(77,5); //smoke detector timeout is five minutes by default
Serial.println("Set smoke detector timeout to 5 minutes");
EEPROM.write(78,0); //homescreen is panel name by default
Serial.println("Set panel name as homescreen");
EEPROM.write(79,1); //audible silence is enabled by default
Serial.println("Enabled audible silence");
EEPROM.write(80,0); //lcd timeout is disabled by default (time in MS found by taking value and multiplying it by 15000)
Serial.println("Disabled LCD timeout");
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
EEPROM.commit();
Serial.println("Wrote changes to EEPROM");
2022-07-04 18:07:36 -04:00
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- EEPROM RESET
2022-07-04 18:07:36 -04:00
void setup() {
2022-09-19 20:46:43 -04:00
EEPROM.begin(1025); //allocate memory address 0-1024 for EEPROM
Serial.println("Configured EEPROM for addresses 0-1024");
2022-07-04 18:07:36 -04:00
Serial.begin(115200); //begin serial
Serial.println("Lexzach's Low-Cost FACP v1");
Serial.println("Booting...");
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETUP PINS
2022-09-21 21:57:02 -04:00
pinMode(hornRelay, OUTPUT); //horn
pinMode(strobeRelay, OUTPUT); //strobe
pinMode(smokeDetectorRelay, OUTPUT); //smoke relay
pinMode(readyLed, OUTPUT); //ready LED
pinMode(silenceLed, OUTPUT); //silence LED
pinMode(alarmLed, OUTPUT); //alarm LED
2022-07-04 19:28:48 -04:00
pinMode(keySwitchPin, INPUT); //key switch
2022-09-19 20:46:43 -04:00
pinMode(resetButtonPin, INPUT); //reset switch
pinMode(silenceButtonPin, INPUT); //silence switch
pinMode(drillButtonPin, INPUT); //drill switch
2022-07-04 18:07:36 -04:00
pinMode(zone1Pin, INPUT); //zone 1
pinMode(zone2Pin, INPUT); //zone 2
2022-07-04 19:28:48 -04:00
pinMode(buzzerPin, OUTPUT); //buzzer
2022-09-21 21:57:02 -04:00
digitalWrite(hornRelay, HIGH); //horn
digitalWrite(strobeRelay, HIGH); //strobe
digitalWrite(smokeDetectorRelay, HIGH); //smoke relay
2022-07-04 18:07:36 -04:00
2022-07-04 19:28:48 -04:00
pinMode(sclPin, OUTPUT); //scl
pinMode(sdaPin, OUTPUT); //sda
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETUP PINS
2022-07-04 18:07:36 -04:00
Serial.println("Initializing LCD...");
lcd.init(); //initialize LCD
2022-09-25 23:54:40 -04:00
lcd.createChar(0, lock); //create the lock character
2022-09-27 22:31:38 -04:00
lcd.createChar(1, check); //create the lock character
2022-09-30 19:07:30 -04:00
lcd.createChar(2, cross); //create the lock character
2022-09-27 22:31:38 -04:00
2022-09-30 19:07:30 -04:00
2022-07-04 18:07:36 -04:00
lcd.backlight();
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- EEPROM RESET BUTTONS
if (digitalRead(resetButtonPin)==HIGH and digitalRead(silenceButtonPin)==HIGH and digitalRead(drillButtonPin)==HIGH){ //reset EEPROM if all buttons are pressed
for(int i=5; i!=0; i--){
lcd.clear();
lcd.setCursor(0,0);
2022-09-19 21:52:52 -04:00
lcd.print("TO FACTORY RESET");
2022-09-19 20:46:43 -04:00
lcd.setCursor(0,1);
lcd.print((String)"HOLD BUTTONS - "+i);
delay(1000);
}
if (digitalRead(resetButtonPin)==HIGH and digitalRead(silenceButtonPin)==HIGH and digitalRead(drillButtonPin)==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("RESETTING TO");
lcd.setCursor(0,1);
lcd.print("FACTORY SETTINGS");
resetEEPROM();
delay(4000);
ESP.restart();
} else {
lcd.clear();
lcd.setCursor(0,0);
2022-09-19 21:52:52 -04:00
lcd.print("FACTORY RESET");
2022-09-19 20:46:43 -04:00
lcd.setCursor(0,1);
lcd.print("CANCELLED");
delay(3000);
}
}
//----------------------------------------------------------------------------- EEPROM RESET BUTTONS
2022-09-25 13:24:30 -04:00
if (digitalRead(silenceButtonPin)==HIGH){
debug = true;
}
2022-07-04 18:07:36 -04:00
lcd.clear();
lcd.setCursor(4,0);
2022-09-19 21:52:52 -04:00
lcd.print("BOOTING...");
lcd.setCursor(0,1);
lcd.print("I/O");
delay(100);
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
Serial.println("Configured all pins");
2022-07-04 18:07:36 -04:00
2022-09-19 20:46:43 -04:00
//EEPROM.write(0,255); //-------------------------------------------------------UNCOMMENT TO INVALIDATE EEPROM AND REFLASH IT AFTER EVERY RESTART
//EEPROM.commit();
2022-07-04 18:07:36 -04:00
Serial.println("Verifying EEPROM configuration integrity...");
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- EEPROM INTEGRETY
if (EEPROM.read(0) != 76 or EEPROM.read(6) != 104 or EEPROM.read(7) > 5 or EEPROM.read(8) > 1 or EEPROM.read(50) != EEPROMVersion or EEPROM.read(51) != EEPROMBuild){
Serial.println("EEPROM verification failed.");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ERROR 1");
lcd.setCursor(0,1);
lcd.print("check manual");
while(digitalRead(resetButtonPin) == LOW and digitalRead(drillButtonPin) == LOW){ //wait until button is pressed
delay(1);
}
if(digitalRead(resetButtonPin) == HIGH){
Serial.println("Resetting...");
ESP.restart();
} else if (digitalRead(drillButtonPin) == HIGH){
resetEEPROM();
}
2022-07-04 18:07:36 -04:00
} else {
2022-09-19 21:52:52 -04:00
Serial.println("EEPROM integrity verified");
2022-07-04 18:07:36 -04:00
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- EEPROM INTEGRETY
2022-09-19 21:52:52 -04:00
lcd.clear();
lcd.setCursor(4,0);
lcd.print("BOOTING...");
lcd.setCursor(0,1);
lcd.print("I/O-SLFTST");
delay(100);
2022-09-19 20:46:43 -04:00
Serial.println("Current EEPROM dump:"); //dump EEPROM into serial monitor
2022-07-04 18:07:36 -04:00
for (int i=0; i<=1024; i++){
Serial.print(EEPROM.read(i));
Serial.print(" ");
}
Serial.println();
//CONFIG LOADING ROUTINE
Serial.println("Loading config from EEPROM...");
codeWheel = EEPROM.read(7); //codeWheel setting address
if (EEPROM.read(8) == 1){
keyRequired = true;
} else {
keyRequired = false;
}
2022-09-25 13:24:30 -04:00
//----------------------------- Panel security variable
if (keyRequired){
keyRequiredVisual = true;
} else {
keyRequiredVisual = false;
}
//----------------------------- Panel security variable
2022-07-04 18:07:36 -04:00
if (EEPROM.read(9) == 1){
isVerification = true;
} else {
isVerification = false;
}
if (EEPROM.read(73) == 1){
eolResistor = true;
} else {
eolResistor = false;
}
if (EEPROM.read(74) == 1){
preAlarm = true;
} else {
preAlarm = false;
}
if (EEPROM.read(76) == 1){
smokeDetectorPreAlarm = true;
} else {
smokeDetectorPreAlarm = false;
}
if (EEPROM.read(79) == 1){
audibleSilence = true;
} else {
audibleSilence = false;
}
smokeDetectorTimeout = EEPROM.read(77)*60000;
firstStageTime = EEPROM.read(75)*60000;
2022-09-27 22:31:38 -04:00
verificationTime = EEPROM.read(10)*100;
2022-09-25 13:24:30 -04:00
//resistorLenience = EEPROM.read(72)*4; DEPRECATED
2022-07-04 18:07:36 -04:00
panelHomescreen = EEPROM.read(78);
2022-09-27 22:31:38 -04:00
lcdTimeout = EEPROM.read(80)*15000;
2022-07-04 18:07:36 -04:00
int x=0;
2022-09-19 20:46:43 -04:00
for (int i=11; i<=26; i++){ //read panel name
2022-07-04 18:07:36 -04:00
if (EEPROM.read(i) != 0){
panelName = panelName + (char)EEPROM.read(i);
panelNameList[x] = EEPROM.read(i);
x++;
}
}
2022-09-19 21:52:52 -04:00
lcd.clear();
lcd.setCursor(4,0);
lcd.print("BOOTING...");
lcd.setCursor(0,1);
lcd.print("I/O-SLFTST-CONFIG");
delay(100);
2022-07-04 18:07:36 -04:00
Serial.println("Config loaded");
2022-09-21 21:57:02 -04:00
digitalWrite(readyLed, HIGH); //power on ready LED on startup
2022-09-27 22:31:38 -04:00
readyLedStatus = true;
2022-09-21 21:57:02 -04:00
digitalWrite(silenceLed, LOW);
digitalWrite(alarmLed, LOW);
digitalWrite(smokeDetectorRelay, LOW); //turn on smoke relay
2022-09-27 22:31:38 -04:00
lastPulse = millis(); //start last pulse
2022-09-19 21:52:52 -04:00
Serial.println("-=- STARTUP COMPLETE -=-");
2022-07-04 18:07:36 -04:00
}
2022-09-29 17:39:07 -04:00
//---------------------------------------------------------------------------------------- functions for turning certain things on and off
2022-07-04 18:07:36 -04:00
void tone() {
ledcSetup(0, 5000, 8); // setup beeper
ledcAttachPin(buzzerPin, 0); // attach beeper
ledcWriteTone(0, 1500); // play tone
}
void noTone() {
ledcSetup(0, 5000, 8); // setup beeper
ledcAttachPin(buzzerPin, 0); // attach beeper
ledcWriteTone(0, 0); // stop tone
}
2022-09-29 17:39:07 -04:00
void hornOn(bool on){
if (on == true){
digitalWrite(hornRelay, LOW); //turn on horn relay
} else {
digitalWrite(hornRelay, HIGH); //turn off horn relay
}
}
void strobeOn(bool on){
if (on == true){
digitalWrite(strobeRelay, LOW); //turn on strobe relay
} else {
digitalWrite(strobeRelay, HIGH); //turn off strobe relay
}
}
void smokeDetectorOn(bool on){
if (on == true){
digitalWrite(smokeDetectorRelay, LOW); //turn on smoke relay
} else {
digitalWrite(smokeDetectorRelay, HIGH); //turn off smoke relay
}
}
//---------------------------------------------------------------------------------------- functions for turning certain things on and off
2022-07-04 18:07:36 -04:00
void activateNAC(){
horn = true;
strobe = true;
fullAlarm = true;
silenced = false;
configMenu = false;
tone();
2022-09-21 21:57:02 -04:00
digitalWrite(alarmLed, HIGH);
digitalWrite(silenceLed, LOW);
2022-07-04 18:07:36 -04:00
}
void checkKey(){
2022-07-04 19:28:48 -04:00
if (digitalRead(keySwitchPin) == HIGH){
2022-09-25 23:54:40 -04:00
if (keyInserted == false and keyRequired == true){
currentScreen=-1;
2022-09-27 22:31:38 -04:00
keyInserted = true;
2022-09-25 23:54:40 -04:00
}
2022-07-04 18:07:36 -04:00
} else {
2022-09-25 23:54:40 -04:00
if (keyInserted == true and keyRequired == true){
currentScreen=-1;
keyInserted = false;
drillPressed=false;
silencePressed=false; //make sure all buttons are registered as depressed after key is removed
resetPressed=false;
drillStillPressed=false;
resetStillPressed=false;
silenceStillPressed=false;
drill = 0;
}
2022-07-04 18:07:36 -04:00
}
}
2022-09-30 19:07:30 -04:00
//----------------------------------------------------------------------------- CHECK ACTIVATION DEVICES [!THIS CODE MUST WORK!]
2022-07-04 18:07:36 -04:00
void checkDevices(){
2022-09-25 13:24:30 -04:00
if (debug == true){
Serial.println(analogRead(zone1Pin));
}
2022-09-29 17:39:07 -04:00
if (walkTest == false){
2022-09-25 13:24:30 -04:00
if ((analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0) and horn != true and silenced==false){
2022-07-04 18:07:36 -04:00
possibleAlarm = true;
}
2022-09-30 19:07:30 -04:00
if (possibleAlarm == true and horn != true and strobe != true and silenced==false){
if (verification >= verificationTime or isVerification == false){
2022-09-29 17:39:07 -04:00
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){
if (analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){
zoneAlarm = 3; //both
} else if (analogRead(zone2Pin) == 0){
zoneAlarm = 2; //z2
} else {
zoneAlarm = 1; //z1
}
2022-09-30 19:07:30 -04:00
activateNAC();
2022-07-04 18:07:36 -04:00
possibleAlarm = false;
verification = 0;
} else {
possibleAlarm = false;
verification = 0;
}
} else {
verification++;
}
}
} else if (walkTest == true){
2022-09-29 17:39:07 -04:00
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){// or analogRead(zone2Pin) == 0){
if (analogRead(zone1Pin) == 0){
zone1Count++;
smokeDetectorOn(false);
strobeOn(true);
delay(500);
2022-09-30 19:07:30 -04:00
digitalWrite(alarmLed, HIGH);
if (silentWalkTest == false){
hornOn(true);
}
2022-09-29 17:39:07 -04:00
delay(500);
2022-09-30 19:07:30 -04:00
if (silentWalkTest == false){
hornOn(false);
}
2022-09-29 17:39:07 -04:00
delay(3000);
2022-09-30 19:07:30 -04:00
digitalWrite(alarmLed, LOW);
2022-09-29 17:39:07 -04:00
strobeOn(false);
smokeDetectorOn(true);
} else if (analogRead(zone2Pin) == 0){
zone2Count++;
smokeDetectorOn(false);
strobeOn(true);
delay(500);
2022-09-30 19:07:30 -04:00
digitalWrite(alarmLed, HIGH);
if (silentWalkTest == false){
hornOn(true);
}
2022-09-29 17:39:07 -04:00
delay(500);
2022-09-30 19:07:30 -04:00
if (silentWalkTest == false){
hornOn(false);
}
2022-09-29 17:39:07 -04:00
delay(500);
2022-09-30 19:07:30 -04:00
if (silentWalkTest == false){
hornOn(true);
}
2022-09-29 17:39:07 -04:00
delay(500);
2022-09-30 19:07:30 -04:00
if (silentWalkTest == false){
hornOn(false);
}
digitalWrite(alarmLed, LOW);
2022-09-29 17:39:07 -04:00
delay(3000);
strobeOn(false);
smokeDetectorOn(true);
2022-07-04 18:07:36 -04:00
}
currentScreen = -1;
}
}
2022-09-30 19:07:30 -04:00
if ((analogRead(zone1Pin) == 4095 or analogRead(zone2Pin) == 4095) and eolResistor == true) {
if (troubleTimer >= 10){
trouble = true;
troubleType=1;
} else {
troubleTimer++;
}
2022-07-04 18:07:36 -04:00
} else {
troubleTimer = 0;
}
}
2022-09-30 19:07:30 -04:00
//----------------------------------------------------------------------------- CHECK ACTIVATION DEVICES [!THIS CODE MUST WORK!]
2022-09-19 20:46:43 -04:00
2022-07-04 18:07:36 -04:00
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- TROUBLE RESPONSE
2022-07-04 18:07:36 -04:00
void troubleCheck(){
if (trouble == true){
2022-09-27 22:31:38 -04:00
if (troubleLedTimer >= 200){
if (readyLedStatus == true){
digitalWrite(readyLed, LOW);
readyLedStatus = false;
if (troubleAck==false){
noTone();
}
} else {
digitalWrite(readyLed, HIGH);
readyLedStatus = true;
if (troubleAck==false){
tone();
}
2022-07-04 18:07:36 -04:00
}
2022-09-27 22:31:38 -04:00
troubleLedTimer = 0;
} else {
troubleLedTimer++;
2022-07-04 18:07:36 -04:00
}
} else {
troubleLedTimer=0;
}
}
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- TROUBLE RESPONSE
2022-07-04 18:07:36 -04:00
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- RESET CODE
2022-09-19 20:46:43 -04:00
void reboot(){
lcd.clear();
2022-07-04 18:07:36 -04:00
lcd.setCursor(2,0);
lcd.print("Resetting...");
tone();
2022-09-21 21:57:02 -04:00
digitalWrite(readyLed, HIGH); //ready LED
digitalWrite(silenceLed, HIGH); //silence LED
digitalWrite(alarmLed, HIGH); //alarm LED
2022-09-29 17:39:07 -04:00
hornOn(false); //horn
strobeOn(false); //strobe
smokeDetectorOn(false); //smoke relay
2022-09-19 21:52:52 -04:00
lcd.backlight();
2022-07-04 18:07:36 -04:00
delay(2500);
noTone();
2022-09-21 21:57:02 -04:00
digitalWrite(readyLed, LOW); //ready LED
digitalWrite(silenceLed, LOW); //silence LED
digitalWrite(alarmLed, LOW); //alarm LED
2022-07-04 18:07:36 -04:00
ESP.restart();
2022-09-19 20:46:43 -04:00
}
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- RESET CODE
2022-09-19 20:46:43 -04:00
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- BUTTON CHECK
2022-09-19 20:46:43 -04:00
void checkButtons(){
2022-09-29 17:39:07 -04:00
if (digitalRead(resetButtonPin) == HIGH){ //-----------------------------------------------------------RESET BUTTON
2022-09-19 20:46:43 -04:00
reboot();
2022-07-04 18:07:36 -04:00
}
2022-09-29 17:39:07 -04:00
if (digitalRead(silenceButtonPin) == HIGH){ //---------------------------------------------------------SILENCE BUTTON
2022-07-04 18:07:36 -04:00
if (horn == true){ //if horns are not silenced, silence the horns
2022-09-21 21:57:02 -04:00
digitalWrite(silenceLed, HIGH);
digitalWrite(alarmLed, LOW);
2022-09-29 17:39:07 -04:00
digitalWrite(readyLed, LOW);
readyLedStatus = false;
2022-07-04 18:07:36 -04:00
horn = false;
if (audibleSilence == false){
strobe = false;
}
silenced=true;
noTone();
} else if (horn == false and strobe == false and trouble == true and silencePressed == false and troubleAck==false){
troubleAck = true;
noTone();
} else if (horn == false and strobe == false and fullAlarm == false and silencePressed == false and configMenu == false){
configMenu = true;
resetStillPressed = true; //make sure the menu doesn't close out as soon as someone opens it
silenceStillPressed = true;
drillStillPressed = true;
char *main[] = {"Testing","Settings"}; //menu 0
configTop = (String)main[0];
configBottom = (String)main[1];
configPage = 0;
cursorPosition = 0;
currentConfigBottom = "";
currentConfigTop = "";
}
silencePressed = true;
} else {
silencePressed = false;
}
2022-09-29 17:39:07 -04:00
if (digitalRead(drillButtonPin) == HIGH and horn != true and silenced != true){ //------------------------------------------DRILL BUTTON
2022-09-25 13:24:30 -04:00
if (drill >= 5000){
2022-09-29 17:39:07 -04:00
zoneAlarm = 4;
2022-07-04 18:07:36 -04:00
activateNAC();
} else {
drill++;
}
drillPressed = true;
} else {
drill = 0;
drillPressed = false;
}
}
2022-09-27 22:31:38 -04:00
//----------------------------------------------------------------------------- BUTTON CHECK
2022-07-04 18:07:36 -04:00
2022-09-19 21:52:52 -04:00
//----------------------------------------------------------------------------- NAC ACTIVATION
2022-07-04 18:07:36 -04:00
void alarm(){
if (strobe == true){
2022-09-29 17:39:07 -04:00
strobeOn(true);
2022-07-04 18:07:36 -04:00
}else{
2022-09-29 17:39:07 -04:00
strobeOn(false);
2022-07-04 18:07:36 -04:00
}
if (horn == true){
if (codeWheel == 0){
if (codeWheelTimer == 0){ //temporal code 3
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 500) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1000) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1500) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 2000) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 2500) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 4000) {
codeWheelTimer = -1;
}
} else if (codeWheel == 1) {
if (codeWheelTimer == 0){ //marchtime
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 250){
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 500){
codeWheelTimer = -1;
}
} else if (codeWheel == 2) { //4-4
if (codeWheelTimer == 0) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 300) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 600) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 900) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1200) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1500) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1800) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 2100) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 2850) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 3150) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 3450) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 3750) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 4050) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 4350) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 4650) {
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 4950) {
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 14950) {
codeWheelTimer = -1;
}
} else if (codeWheel == 3) { //continuous
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheel == 5) {
if (codeWheelTimer == 0){ //marchtime slower
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 500){
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 1000){
codeWheelTimer = -1;
}
} else if (codeWheel == 4) {
if (codeWheelTimer == 0){ //california code
2022-09-29 17:39:07 -04:00
hornOn(true);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 10000){
2022-09-29 17:39:07 -04:00
hornOn(false);
2022-07-04 18:07:36 -04:00
} else if (codeWheelTimer == 15000){
codeWheelTimer = -1;
}
}
codeWheelTimer++;
2022-09-29 17:39:07 -04:00
} else {
hornOn(false);
codeWheelTimer = 0;
}
if (fullAlarm == true){
2022-07-04 18:07:36 -04:00
alarmLedTimer++;
if (alarmLedTimer >= 750){
2022-09-29 17:39:07 -04:00
if (digitalRead(alarmLed) == false){
if (silenced == true){
tone();
}
2022-09-21 21:57:02 -04:00
digitalWrite(alarmLed, HIGH);
2022-07-04 18:07:36 -04:00
} else {
2022-09-29 17:39:07 -04:00
if (silenced == true){
noTone();
}
2022-09-21 21:57:02 -04:00
digitalWrite(alarmLed, LOW);
2022-07-04 18:07:36 -04:00
}
2022-09-29 17:39:07 -04:00
alarmLedTimer = 0;
2022-07-04 18:07:36 -04:00
}
}
}
2022-09-19 21:52:52 -04:00
//----------------------------------------------------------------------------- NAC ACTIVATION
2022-07-04 18:07:36 -04:00
void lcdUpdate(){
2022-09-25 13:24:30 -04:00
if (trouble==false and fullAlarm==false and horn==false and strobe==false and walkTest == false and currentScreen != 0 and drill == 0){
2022-07-04 18:07:36 -04:00
lcd.noAutoscroll();
lcd.clear();
2022-09-25 23:54:40 -04:00
if (keyRequired == true and keyInserted == false){
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.print(" System Normal");
} else {
lcd.setCursor(2,0);
lcd.print("System Normal");
}
2022-07-04 18:07:36 -04:00
lcd.setCursor(0,1);
if (panelHomescreen == 0){
lcd.print(panelName);
} else if (panelHomescreen == 1){
lcd.print(analogRead(zone1Pin));
}
currentScreen = 0;
} else if (trouble==true){
if (troubleType == 0 and currentScreen != 1){
lcd.clear();
lcd.setCursor(1,0);
lcd.print("* Trouble *");
2022-09-25 13:24:30 -04:00
lcd.setCursor(0,1);
2022-07-04 18:07:36 -04:00
lcd.print("Unknown");
currentScreen = 1;
} else if (troubleType == 1 and currentScreen != 2){
lcd.clear();
2022-09-25 13:24:30 -04:00
lcd.setCursor(1,0);
2022-07-04 18:07:36 -04:00
lcd.print("* Trouble *");
2022-09-25 13:24:30 -04:00
lcd.setCursor(0,1);
2022-07-04 18:07:36 -04:00
lcd.print("Ground Fault");
currentScreen = 2;
}
} else if (fullAlarm == true and silenced == false and currentScreen != 3){
lcd.clear();
lcd.setCursor(1,0);
2022-09-29 17:39:07 -04:00
if (keyRequired == true and keyInserted == false){
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.print("* FIRE ALARM *");
} else {
lcd.setCursor(1,0);
lcd.print("* FIRE ALARM *");
}
lcd.setCursor(0,1);
if (zoneAlarm == 1){
lcd.print("Zone 1");
} else if (zoneAlarm == 2){
lcd.print("Zone 2");
} else if (zoneAlarm == 3){
lcd.print("Zone 1 & Zone 2");
} else if (zoneAlarm == 4){
lcd.print("Fire Drill");
}
2022-07-04 18:07:36 -04:00
currentScreen = 3;
} else if (silenced == true and currentScreen != 4){
lcd.clear();
2022-09-29 17:39:07 -04:00
if (keyRequired == true and keyInserted == false){
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.print("-- SILENCED --");
} else {
lcd.setCursor(1,0);
lcd.print("-- SILENCED --");
}
lcd.setCursor(0,1);
if (zoneAlarm == 1){
lcd.print("Zone 1");
} else if (zoneAlarm == 2){
lcd.print("Zone 2");
} else if (zoneAlarm == 3){
lcd.print("Zone 1 & Zone 2");
} else if (zoneAlarm == 4){
lcd.print("Fire Drill");
}
2022-07-04 18:07:36 -04:00
// lcd.setCursor(2,1);
// lcd.print("Zone 1");
currentScreen = 4;
} else if (walkTest == true and currentScreen != 5) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("* Supervisory *");
lcd.setCursor(0,1);
2022-09-29 17:39:07 -04:00
lcd.print("Z1:"+(String)zone1Count+" Z2:"+(String)zone2Count);
2022-07-04 18:07:36 -04:00
currentScreen = 5;
2022-09-21 21:57:02 -04:00
digitalWrite(readyLed, LOW); //ready led off for walk test
2022-09-29 17:39:07 -04:00
readyLedStatus = false;
2022-09-25 13:24:30 -04:00
} else if (drillPressed == true and fullAlarm == false and horn == false and strobe == false and walkTest == false and currentScreen != 6) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CONTINUE HOLDING");
lcd.setCursor(1,1);
lcd.print("TO START DRILL");
currentScreen = 6;
2022-07-04 18:07:36 -04:00
}
}
void config(){
char *main[] = {"Testing","Settings"}; //menu 0
char *mainTesting[] = {"Walk Test","Silent Wlk Test","Strobe Test"}; //menu 1
char *mainSettings[] = {"Fire Alarm","Panel"}; //menu 2
2022-09-30 19:07:30 -04:00
char *mainSettingsFireAlarmSettings[] = {"Coding","Verification","Pre-Alarm","Audible Sil.:","Keyless Sil."}; //menu 3
char *mainSettingsVerificationSettings[] = {"Verification:","V.Time:"}; //menu 4
2022-07-04 18:07:36 -04:00
char *mainSettingsFireAlarmSettingsCoding[] = {"Temporal Three","Marchtime","4-4","Continuous","California","Slow Marchtime"}; //menu 5
char *mainSettingsFireAlarmSettingsPreAlarmSettings[] = {"Pre-Alarm: ","stage 1: ","Detector PreAlrm"}; //menu 6
char *mainSettingsFireAlarmSettingsPreAlarmSettingsSmokeDetectorPreAlarmSettings[] = {"Det. PreAlrm: ","Det. 1st stge: ","Det. Tmeout: "}; //menu 7
2022-09-25 13:24:30 -04:00
char *mainPanelSettings[] = {"Panel Name","Panel Security","LCD Dim:","Factory Reset","About","Calibration"}; //menu 8
2022-07-04 18:07:36 -04:00
char *mainPanelSettingsPanelSecurity[] = {"None","Keyswitch","Passcode"}; //menu 9
char *mainPanelSettingsPanelName[] = {"Enter Name:"}; //menu 10
2022-09-27 22:31:38 -04:00
char *mainPanelSettingsAbout[] = {"Antigneous FACP","Firmware: ","by Lexzach"}; //menu 12
2022-09-25 13:24:30 -04:00
char *mainPanelSettingsCalibrate[] = {"Activated Zone 1", "Normal Zone 1", "Trouble Zone 1", "Activated Zone 2", "Normal Zone 2", "Trouble Zone 2"}; //menu 13
2022-07-04 18:07:36 -04:00
// char *mainPanelSettingsHomescreen[] = {"Panel Name", "Stats for Nerds"}; //menu 10
// char *mainPanelSettingsHomescreenStatsForNerds[] = {"Zone Input Voltages"}; //menu 11
2022-09-19 20:46:43 -04:00
if (digitalRead(resetButtonPin) == HIGH){ //RESET BUTTON
2022-07-04 18:07:36 -04:00
resetPressed = true;
} else {
resetPressed = false;
resetStillPressed = false;
}
2022-09-19 20:46:43 -04:00
if (digitalRead(silenceButtonPin) == HIGH){ //SILENCE BUTTON
2022-07-04 18:07:36 -04:00
silencePressed = true;
} else {
silencePressed = false;
silenceStillPressed = false;
}
2022-09-19 20:46:43 -04:00
if (digitalRead(drillButtonPin) == HIGH){ //DRILL BUTTON
2022-07-04 18:07:36 -04:00
drillPressed = true;
} else {
drillPressed = false;
drillStillPressed = false;
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- MAIN MENU
2022-07-04 18:07:36 -04:00
if (configPage == 0){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){ //main screen
cursorPosition = 1;
configTop = (String)main[1];
configBottom = (String)main[0];
} else if (cursorPosition == 1){
cursorPosition = 0;
configTop = (String)main[0];
configBottom = (String)main[1];
}
} else if (silencePressed == true and silenceStillPressed == false){
silencePressed = true;
configMenu = false;
currentScreen=-1;
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){ //cursor over testing
configPage = 1; //change screen to testing
cursorPosition = 0;
configTop = (String)mainTesting[0];
configBottom = (String)mainTesting[1];
} else if (cursorPosition == 1){ //cursor over settings
configPage = 2; //change screen to settings
cursorPosition = 0;
configTop = (String)mainSettings[0];
configBottom = (String)mainSettings[1];
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- MAIN MENU
//----------------------------------------------------------------------------- TESTING
2022-07-04 18:07:36 -04:00
} else if (configPage == 1){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
configTop = (String)mainTesting[1];
configBottom = (String)mainTesting[2];
} else if (cursorPosition == 1) {
cursorPosition = 2;
configTop = (String)mainTesting[2];
configBottom = (String)mainTesting[0];
} else if (cursorPosition == 2) {
cursorPosition = 0;
configTop = (String)mainTesting[0];
configBottom = (String)mainTesting[1];
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 0;
cursorPosition = 0;
configTop = (String)main[0];
configBottom = (String)main[1];
strobe = false;
2022-09-30 19:07:30 -04:00
smokeDetectorOn(true);
digitalWrite(readyLed,HIGH);
readyLedStatus = true;
2022-07-04 18:07:36 -04:00
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
walkTest = true;
silentWalkTest = false;
silencePressed = true;
configMenu = false;
currentScreen=-1;
2022-09-29 17:39:07 -04:00
zone1Count = 0;
zone2Count = 0;
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 1) {
walkTest = true;
silentWalkTest = true;
silencePressed = true;
configMenu = false;
currentScreen=-1;
2022-09-29 17:39:07 -04:00
zone1Count = 0;
zone2Count = 0;
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 2) {
if (strobe == false){
strobe = true;
2022-09-30 19:07:30 -04:00
smokeDetectorOn(false); //prevent (specifically cheap IR) smoke detectors from tripping from the strobe
digitalWrite(readyLed,LOW);
readyLedStatus = false;
2022-07-04 18:07:36 -04:00
configTop = (String)mainTesting[2]+" *";
} else {
strobe = false;
2022-09-30 19:07:30 -04:00
smokeDetectorOn(true);
digitalWrite(readyLed,HIGH);
readyLedStatus = true;
2022-07-04 18:07:36 -04:00
configTop = (String)mainTesting[2];
}
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- TESTING
//----------------------------------------------------------------------------- SETTINGS
2022-07-04 18:07:36 -04:00
} else if (configPage == 2){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){ //main screen
cursorPosition = 1;
configTop = (String)mainSettings[1];
configBottom = (String)mainSettings[0];
} else if (cursorPosition == 1){
cursorPosition = 0;
configTop = (String)mainSettings[0];
configBottom = (String)mainSettings[1];
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 0;
cursorPosition = 0;
configTop = (String)main[0];
configBottom = (String)main[1];
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
configPage = 3; //change screen to facp settings
cursorPosition = 0;
configTop = (String)mainSettingsFireAlarmSettings[0];
configBottom = (String)mainSettingsFireAlarmSettings[1];
} else if (cursorPosition == 1){
configPage = 8; //change screen to facp settings
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETTINGS
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM
2022-07-04 18:07:36 -04:00
} else if (configPage == 3){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
configTop = (String)mainSettingsFireAlarmSettings[1];
configBottom = (String)mainSettingsFireAlarmSettings[2];
} else if (cursorPosition == 1) {
cursorPosition = 2;
configTop = (String)mainSettingsFireAlarmSettings[2];
configBottom = (String)mainSettingsFireAlarmSettings[3]+audibleSilence;
2022-09-30 19:07:30 -04:00
configBottom.replace("1","*");
configBottom.replace("0","$");
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 2) {
cursorPosition = 3;
configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence;
configBottom = (String)mainSettingsFireAlarmSettings[0];
2022-09-30 19:07:30 -04:00
configTop.replace("1","*");
configTop.replace("0","$");
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 3) {
cursorPosition = 0;
configTop = (String)mainSettingsFireAlarmSettings[0];
configBottom = (String)mainSettingsFireAlarmSettings[1];
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 2;
cursorPosition = 0;
configTop = (String)mainSettings[0];
configBottom = (String)mainSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
configPage = 5;
cursorPosition = 0;
if (codeWheel == 0){
configTop = (String)mainSettingsFireAlarmSettingsCoding[0] + "*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[0];
}
if (codeWheel == 1){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[1] + "*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[1];
}
} else if (cursorPosition == 1) {
configPage = 4;
cursorPosition = 0;
2022-09-30 19:07:30 -04:00
configTop = (String)mainSettingsVerificationSettings[0] + isVerification;
if (isVerification == false){
configBottom = (String)mainSettingsVerificationSettings[1] + "off";
} else {
configBottom = (String)mainSettingsVerificationSettings[1] + (verificationTime/1000)+"s";
}
configTop.replace("1","*");
configTop.replace("0","$");
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 2) {
configPage = 6;
cursorPosition = 0;
configTop = (String)mainSettingsFireAlarmSettingsPreAlarmSettings[0];
configBottom = (String)mainSettingsFireAlarmSettingsPreAlarmSettings[1];
} else if (cursorPosition == 3) {
if (audibleSilence == true){
audibleSilence = false;
EEPROM.write(79,0);
} else {
audibleSilence = true;
EEPROM.write(79,1);
}
EEPROM.commit();
configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence;
configBottom = (String)mainSettingsFireAlarmSettings[0];
2022-09-30 19:07:30 -04:00
configTop.replace("1","*");
configTop.replace("0","$");
2022-07-04 18:07:36 -04:00
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM
//----------------------------------------------------------------------------- SETTINGS > PANEL
2022-07-04 18:07:36 -04:00
} else if (configPage == 8){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
configTop = (String)mainPanelSettings[1];
if (lcdTimeout == 0){
configBottom = (String)mainPanelSettings[2] + "off";
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout<=30000) {
configBottom = (String)mainPanelSettings[2] + lcdTimeout/1000+"s";
2022-07-04 18:07:36 -04:00
} else {
2022-09-27 22:31:38 -04:00
configBottom = (String)mainPanelSettings[2] + lcdTimeout/60000+"m";
2022-07-04 18:07:36 -04:00
}
} else if (cursorPosition == 1) {
cursorPosition = 2;
if (lcdTimeout == 0){
configTop = (String)mainPanelSettings[2] + "off";
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout<=30000) {
configTop = (String)mainPanelSettings[2] + lcdTimeout/1000+"s";
2022-07-04 18:07:36 -04:00
} else {
2022-09-27 22:31:38 -04:00
configTop = (String)mainPanelSettings[2] + lcdTimeout/60000+"m";
2022-07-04 18:07:36 -04:00
}
configBottom = (String)mainPanelSettings[3];
} else if (cursorPosition == 2) {
cursorPosition = 3;
configTop = (String)mainPanelSettings[3];
configBottom = (String)mainPanelSettings[4];
} else if (cursorPosition == 3) {
cursorPosition = 4;
configTop = (String)mainPanelSettings[4];
2022-09-25 13:24:30 -04:00
configBottom = (String)mainPanelSettings[5];
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 4) {
2022-09-25 13:24:30 -04:00
cursorPosition = 5;
configTop = (String)mainPanelSettings[5];
configBottom = (String)mainPanelSettings[0];
} else if (cursorPosition == 5) {
2022-07-04 18:07:36 -04:00
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 2;
cursorPosition = 0;
configTop = (String)mainSettings[0];
configBottom = (String)mainSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
configPage = 10;
cursorPosition = 0;
configTop = "Enter Name:";
configBottom = (String)panelName;
lcd.blink_on();
} else if (cursorPosition == 1) {
2022-09-25 13:24:30 -04:00
configPage = 9;
cursorPosition = 0;
2022-09-25 23:54:40 -04:00
if (keyRequiredVisual == true){
2022-09-25 13:24:30 -04:00
configTop = (String)mainPanelSettingsPanelSecurity[0];
configBottom = (String)mainPanelSettingsPanelSecurity[1]+"*";
} else {
configTop = (String)mainPanelSettingsPanelSecurity[0]+"*";
configBottom = (String)mainPanelSettingsPanelSecurity[1];
}
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 2) {
if (lcdTimeout == 0){
2022-09-27 22:31:38 -04:00
lcdTimeout = 15000;
2022-07-04 18:07:36 -04:00
EEPROM.write(80,1);
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout == 15000){
lcdTimeout = 30000;
2022-07-04 18:07:36 -04:00
EEPROM.write(80,2);
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout == 30000){
lcdTimeout = 60000;
2022-07-04 18:07:36 -04:00
EEPROM.write(80,4);
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout == 60000){
lcdTimeout = 300000;
2022-07-04 18:07:36 -04:00
EEPROM.write(80,20);
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout == 300000){
lcdTimeout = 600000;
2022-07-04 18:07:36 -04:00
EEPROM.write(80,40);
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout >= 600000){
2022-07-04 18:07:36 -04:00
lcdTimeout = 0;
EEPROM.write(80,0);
}
EEPROM.commit();
if (lcdTimeout == 0){
configTop = (String)mainPanelSettings[2] + "off";
2022-09-27 22:31:38 -04:00
} else if (lcdTimeout<=30000) {
configTop = (String)mainPanelSettings[2] + lcdTimeout/1000+"s";
2022-07-04 18:07:36 -04:00
} else {
2022-09-27 22:31:38 -04:00
configTop = (String)mainPanelSettings[2] + lcdTimeout/60000+"m";
2022-07-04 18:07:36 -04:00
}
} else if (cursorPosition == 3){
2022-09-19 20:46:43 -04:00
configBottom = "drill = yes";
configTop = "silence = no";
2022-09-19 21:52:52 -04:00
configPage = -1;
2022-07-04 18:07:36 -04:00
} else if (cursorPosition == 4){
2022-09-27 22:31:38 -04:00
configPage = 12;
cursorPosition = 0;
configTop = (String)mainPanelSettingsAbout[0];
2022-09-30 19:07:30 -04:00
configBottom = (String)mainPanelSettingsAbout[1] + firmwareRev;
2022-07-04 18:07:36 -04:00
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETTINGS > PANEL
//----------------------------------------------------------------------------- SETTINGS > PANEL > PANEL NAME
2022-07-04 18:07:36 -04:00
} else if (configPage == 10){ //panel rename routine
if (resetPressed == true and resetStillPressed == false){
clearTimer = 0;
if (panelNameList[cursorPosition] == 90){
panelNameList[cursorPosition] = 32;
} else if (panelNameList[cursorPosition] == 32){
panelNameList[cursorPosition] = 39;
} else if (panelNameList[cursorPosition] == 39){
panelNameList[cursorPosition] = 45;
} else if (panelNameList[cursorPosition] == 57){
panelNameList[cursorPosition] = 65;
} else {
panelNameList[cursorPosition] = panelNameList[cursorPosition] + 1;
}
} else if (resetPressed==true and resetStillPressed==true) {
clearTimer++;
2022-09-27 22:31:38 -04:00
if (clearTimer >= 35) { //clear character if held down
2022-07-04 18:07:36 -04:00
panelNameList[cursorPosition] = 32;
}
} else if (silencePressed == true and silenceStillPressed == false){
int x=0;
for (int i=11; i<=26; i++){ //write new panel name
EEPROM.write(i,panelNameList[x]);
x++;
}
lcd.blink_off();
EEPROM.commit();
configPage = 8;
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
x=0;
panelName = "";
2022-09-19 20:46:43 -04:00
for (int i=11; i<=26; i++){ //read panel name
2022-07-04 18:07:36 -04:00
if (EEPROM.read(i) != 0){
panelName = panelName + (char)EEPROM.read(i);
panelNameList[x] = EEPROM.read(i);
x++;
}
}
} else if (drillPressed == true and drillStillPressed == false){
2022-07-04 19:28:48 -04:00
currentConfigTop = "e"; //make sure the screen re-renders
2022-07-04 18:07:36 -04:00
if (cursorPosition != 15){
cursorPosition++;
} else {
cursorPosition = 0;
}
}
if (configPage == 10){ //make sure the panel doesn't re-render the text on the previous page when exiting
configBottom = "";
for (int i=0; i<=15; i++){ //generate name to print on lcd
configBottom = configBottom + (char)panelNameList[i];
}
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETTINGS > PANEL > PANEL NAME
//----------------------------------------------------------------------------- SETTINGS > PANEL > FACTORY RESET
2022-09-19 21:52:52 -04:00
} else if (configPage == -1){
2022-09-19 20:46:43 -04:00
configBottom = "drill = yes";
configTop = "silence = no";
if (silencePressed == true and silenceStillPressed == false){
configPage = 8;
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
2022-09-21 21:57:02 -04:00
digitalWrite(readyLed, LOW); //ready LED
2022-09-19 20:46:43 -04:00
lcd.clear();
lcd.setCursor(0,0);
lcd.print("RESETTING TO");
lcd.setCursor(0,1);
lcd.print("FACTORY SETTINGS");
resetEEPROM();
delay(4000);
ESP.restart();
}
//----------------------------------------------------------------------------- SETTINGS > PANEL > FACTORY RESET
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM > CODING
2022-07-04 18:07:36 -04:00
} else if (configPage == 5){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
if (codeWheel == 1){
configTop = (String)mainSettingsFireAlarmSettingsCoding[1]+"*";
} else{
configTop = (String)mainSettingsFireAlarmSettingsCoding[1];
}
if (codeWheel == 2){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[2]+"*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[2];
}
} else if (cursorPosition == 1) {
cursorPosition = 2;
if (codeWheel == 2){
configTop = (String)mainSettingsFireAlarmSettingsCoding[2]+"*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[2];
}
if (codeWheel == 3){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[3]+"*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[3];
}
} else if (cursorPosition == 2) {
cursorPosition = 3;
if (codeWheel == 3){
configTop = (String)mainSettingsFireAlarmSettingsCoding[3]+"*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[3];
}
if (codeWheel == 4){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[4]+"*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[4];
}
} else if (cursorPosition == 3) {
cursorPosition = 4;
if (codeWheel == 4){
configTop = (String)mainSettingsFireAlarmSettingsCoding[4]+"*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[4];
}
if (codeWheel == 5){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[5]+"*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[5];
}
} else if (cursorPosition == 4) {
cursorPosition = 5;
if (codeWheel == 5){
configTop = (String)mainSettingsFireAlarmSettingsCoding[5]+"*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[5];
}
if (codeWheel == 0){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[0]+"*";
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[0];
}
} else if (cursorPosition == 5) {
cursorPosition = 0;
if (codeWheel == 0){
configTop = (String)mainSettingsFireAlarmSettingsCoding[0]+"*";
} else {
configTop = (String)mainSettingsFireAlarmSettingsCoding[0];
}
if (codeWheel == 1){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[1]+"*";
} else{
configBottom = (String)mainSettingsFireAlarmSettingsCoding[1];
}
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 3; //change screen to facp settings
cursorPosition = 0;
configTop = (String)mainSettingsFireAlarmSettings[0];
configBottom = (String)mainSettingsFireAlarmSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
2022-09-25 13:24:30 -04:00
EEPROM.write(7,cursorPosition); //write the new codewheel settings to eeprom
2022-07-04 18:07:36 -04:00
EEPROM.commit();
configTop = (String)mainSettingsFireAlarmSettingsCoding[cursorPosition]+"*";
if (cursorPosition == 5){
configBottom = (String)mainSettingsFireAlarmSettingsCoding[0];
} else {
configBottom = (String)mainSettingsFireAlarmSettingsCoding[cursorPosition+1];
}
codeWheel = EEPROM.read(7); //codeWheel setting address
}
2022-09-19 20:46:43 -04:00
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM > CODING
2022-09-19 21:52:52 -04:00
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM > VERIFICATION
} else if (configPage == 4){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
2022-09-30 19:07:30 -04:00
if (isVerification == false){
configTop = (String)mainSettingsVerificationSettings[1] + "off";
} else {
configTop = (String)mainSettingsVerificationSettings[1] + (verificationTime/1000)+"s";
}
2022-09-19 21:52:52 -04:00
configBottom = (String)mainSettingsVerificationSettings[0]+isVerification;
2022-09-30 19:07:30 -04:00
configBottom.replace("1","*");
configBottom.replace("0","$");
2022-09-19 21:52:52 -04:00
} else if (cursorPosition == 1) {
cursorPosition = 0;
configTop = (String)mainSettingsVerificationSettings[0]+isVerification;
2022-09-30 19:07:30 -04:00
if (isVerification == false){
configBottom = (String)mainSettingsVerificationSettings[1] + "off";
} else {
configBottom = (String)mainSettingsVerificationSettings[1] + (verificationTime/1000)+"s";
}
configTop.replace("1","*");
configTop.replace("0","$");
2022-09-19 21:52:52 -04:00
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 3;
cursorPosition = 0;
configTop = (String)mainSettingsFireAlarmSettings[0];
configBottom = (String)mainSettingsFireAlarmSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
if (isVerification == true){
isVerification = false;
EEPROM.write(9,0);
} else {
isVerification = true;
EEPROM.write(9,1);
}
EEPROM.commit();
configTop = (String)mainSettingsVerificationSettings[0]+isVerification;
2022-09-30 19:07:30 -04:00
if (isVerification == false){
configBottom = (String)mainSettingsVerificationSettings[1] + "off";
} else {
configBottom = (String)mainSettingsVerificationSettings[1] + (verificationTime/1000)+"s";
}
configTop.replace("1","*");
configTop.replace("0","$");
} else if (cursorPosition == 1 and isVerification == true) {
if (verificationTime == 500){
verificationTime = 1000;
EEPROM.write(10,10);
} else if (verificationTime == 1000){
verificationTime = 1500;
EEPROM.write(10,15);
} else if (verificationTime == 1500){
verificationTime = 2500;
EEPROM.write(10,25);
} else if (verificationTime == 2500){
verificationTime = 4500;
EEPROM.write(10,45);
} else if (verificationTime == 4500){
verificationTime = 7500;
EEPROM.write(10,75);
} else if (verificationTime >= 7500){
verificationTime = 500;
EEPROM.write(10,5);
}
EEPROM.commit();
if (isVerification == false){
configTop = (String)mainSettingsVerificationSettings[1] + "off";
} else {
configTop = (String)mainSettingsVerificationSettings[1] + (verificationTime/1000)+"s";
}
configBottom = (String)mainSettingsVerificationSettings[0]+isVerification;
configBottom.replace("1","*");
configBottom.replace("0","$");
2022-09-19 21:52:52 -04:00
}
2022-07-04 18:07:36 -04:00
}
2022-09-25 13:24:30 -04:00
//----------------------------------------------------------------------------- SETTINGS > FIRE ALARM > VERIFICATION
//----------------------------------------------------------------------------- SETTINGS > PANEL > PANEL SECURITY
2022-09-27 22:31:38 -04:00
} else if (configPage == 9){
2022-09-25 13:24:30 -04:00
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
if (keyRequiredVisual == true){
configTop = (String)mainPanelSettingsPanelSecurity[1]+"*";
configBottom = (String)mainPanelSettingsPanelSecurity[0];
} else {
configTop = (String)mainPanelSettingsPanelSecurity[1];
configBottom = (String)mainPanelSettingsPanelSecurity[0]+"*";
}
} else if (cursorPosition == 1) {
cursorPosition = 0;
if (keyRequiredVisual == true){
configTop = (String)mainPanelSettingsPanelSecurity[0];
configBottom = (String)mainPanelSettingsPanelSecurity[1]+"*";
} else {
configTop = (String)mainPanelSettingsPanelSecurity[0]+"*";
configBottom = (String)mainPanelSettingsPanelSecurity[1];
}
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 8;
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
} else if (drillPressed == true and drillStillPressed == false){
if (cursorPosition == 0){
EEPROM.write(8,0); //write the new keyswitch settings to eeprom
EEPROM.commit();
keyRequiredVisual = false;
configTop = (String)mainPanelSettingsPanelSecurity[0]+"*";
configBottom = (String)mainPanelSettingsPanelSecurity[1];
} else if (cursorPosition == 1) {
EEPROM.write(8,1); //write the new keyswitch settings to eeprom
EEPROM.commit();
keyRequiredVisual = true;
configTop = (String)mainPanelSettingsPanelSecurity[1]+"*";
configBottom = (String)mainPanelSettingsPanelSecurity[0];
}
2022-09-27 22:31:38 -04:00
}
//----------------------------------------------------------------------------- SETTINGS > PANEL > PANEL SECURITY
} else if (configPage == 12){
if (resetPressed == true and resetStillPressed == false){
if (cursorPosition == 0){
cursorPosition = 1;
configTop = (String)mainPanelSettingsAbout[1]+firmwareRev;
configBottom = (String)mainPanelSettingsAbout[2];
} else if (cursorPosition == 1) {
cursorPosition = 2;
configTop = (String)mainPanelSettingsAbout[2];
configBottom = (String)mainPanelSettingsAbout[0];
} else if (cursorPosition == 2) {
cursorPosition = 0;
configTop = (String)mainPanelSettingsAbout[0];
configBottom = (String)mainPanelSettingsAbout[1]+firmwareRev;
}
} else if (silencePressed == true and silenceStillPressed == false){
configPage = 8;
cursorPosition = 0;
configTop = (String)mainPanelSettings[0];
configBottom = (String)mainPanelSettings[1];
}
//----------------------------------------------------------------------------- SETTINGS > PANEL > ABOUT
2022-09-25 13:24:30 -04:00
}
2022-09-27 22:31:38 -04:00
2022-09-19 20:46:43 -04:00
2022-07-04 18:07:36 -04:00
// if (resetPressed == true and resetStillPressed == false){
// } else if (silencePressed == true and silenceStillPressed == false){
// } else if (drillPressed == true and drillStillPressed == false){
// }
if (configTop != currentConfigTop or configBottom != currentConfigBottom){
lcd.clear();
lcd.setCursor(0,0);
2022-09-25 13:24:30 -04:00
if (configPage != -1){
2022-09-30 19:07:30 -04:00
if (configTop.indexOf("*")>0){ //RENDER TOP OF CONFIG WINDOW
configTop.replace("*","");
lcd.print("]" + configTop);
lcd.write(byte(1));
2022-09-27 22:31:38 -04:00
2022-09-30 19:07:30 -04:00
} else if (configTop.indexOf("$")>0) {
configTop.replace("$","");
2022-09-27 22:31:38 -04:00
lcd.print("]" + configTop);
2022-09-30 19:07:30 -04:00
lcd.write(byte(2));
} else {
lcd.print("]" + configTop);
}
2022-09-25 13:24:30 -04:00
} else {
lcd.print(configTop);
}
2022-07-04 18:07:36 -04:00
lcd.setCursor(0,1);
2022-09-30 19:07:30 -04:00
if (configBottom.indexOf("*")>0){ //RENDER BOTTOM OF CONFIG WINDOW
configBottom.replace("*","");
lcd.print(configBottom);
lcd.write(byte(1));
} else if (configBottom.indexOf("$")>0) {
configBottom.replace("$","");
lcd.print(configBottom);
lcd.write(byte(2));
} else {
lcd.print(configBottom);
}
2022-07-04 18:07:36 -04:00
currentConfigTop = configTop;
currentConfigBottom = configBottom;
if (configPage == 10){
lcd.setCursor(cursorPosition,1);
}
}
2022-09-19 20:46:43 -04:00
if (digitalRead(resetButtonPin) == HIGH){ //RESET BUTTON
2022-07-04 18:07:36 -04:00
resetStillPressed = true;
}
2022-09-19 20:46:43 -04:00
if (digitalRead(silenceButtonPin) == HIGH){ //SILENCE BUTTON
2022-07-04 18:07:36 -04:00
silenceStillPressed = true;
}
2022-09-19 20:46:43 -04:00
if (digitalRead(drillButtonPin) == HIGH){ //DRILL BUTTON
2022-07-04 18:07:36 -04:00
drillStillPressed = true;
}
}
2022-09-25 23:54:40 -04:00
void lcdBacklight(){
2022-07-04 18:07:36 -04:00
if (lcdTimeout!=0){
if (lcdTimeout <= lcdTimeoutTimer and backlightOn == true){
lcd.noBacklight();
backlightOn = false;
} else if (backlightOn == true) {
lcdTimeoutTimer++;
}
2022-09-25 13:24:30 -04:00
if (drillPressed == true or silencePressed == true or resetPressed == true or fullAlarm == true or trouble == true or (keyInserted == true and keyRequired == true)){
2022-07-04 18:07:36 -04:00
lcdTimeoutTimer = 0;
2022-09-19 20:46:43 -04:00
if (backlightOn == false){
lcd.backlight();
}
2022-07-04 18:07:36 -04:00
backlightOn = true;
}
}
2022-09-25 23:54:40 -04:00
}
void loop() {
2022-09-27 22:31:38 -04:00
systemClock = millis(); //-------------------- SYSTEM CLOCK
if (systemClock-lastPulse >= 1){
//------------------------------------------------------ CHECK LCD BACKLIGHT
2022-09-25 23:54:40 -04:00
lcdBacklight();
2022-09-25 13:24:30 -04:00
2022-09-27 22:31:38 -04:00
//------------------------------------------------------ CHECK LCD BACKLIGHT
//------------------------------------------------------ CHECK KEY
2022-09-25 13:24:30 -04:00
checkKey();
2022-09-27 22:31:38 -04:00
//------------------------------------------------------ CHECK KEY
2022-09-25 13:24:30 -04:00
2022-09-27 22:31:38 -04:00
//------------------------------------------------------ CHECK ACTIVATING DEVICES
2022-09-25 23:54:40 -04:00
2022-09-27 22:31:38 -04:00
checkDevices();
2022-09-25 13:24:30 -04:00
2022-09-27 22:31:38 -04:00
//------------------------------------------------------ CHECK ACTIVATING DEVICES
troubleCheck(); //trouble check
alarm(); //alarm codewheel
//------------------------------------------------------ CHECK BUTTONS
if (((keyInserted == true and keyRequired == true) or (keyInserted==false and keyRequired==false)) and configMenu == false){
checkButtons(); //check if certain buttons are pressed
2022-07-04 18:07:36 -04:00
}
2022-09-27 22:31:38 -04:00
//------------------------------------------------------ CHECK BUTTONS
//------------------------------------------------------ UPDATE LCD DISPLAY
if (buttonCheckTimer >= 20){
if (configMenu==false){
lcdUpdate();
} else if (configMenu==true) {
if ((keyInserted == true and keyRequired == true) or (keyInserted==false and keyRequired==false)){
config();
}
}
buttonCheckTimer = 0;
} else {
buttonCheckTimer++;
}
//------------------------------------------------------ UPDATE LCD DISPLAY
lastPulse = millis(); //update last pulse
2022-07-04 18:07:36 -04:00
}
}