failsafe mode, user defined smoke detector verification

This commit is contained in:
Lexzach 2022-10-03 23:05:16 -04:00
parent 7253fba57c
commit 01edd575d8
Signed by: Lexzach
GPG Key ID: B574880929E6F1F0
2 changed files with 340 additions and 214 deletions

View File

@ -5,10 +5,11 @@
unsigned long systemClock; //-----------------SYSTEM CLOCK [VERY IMPORTANT] unsigned long systemClock; //-----------------SYSTEM CLOCK [VERY IMPORTANT]
unsigned long lastPulse; //-------------------LAST void loop() PULSE unsigned long lastPulse; //-------------------LAST void loop() PULSE
bool failsafeMode = false; // If panel fails to boot, you can enter a reduced-feature down panel that is guaranteed to work
char *firmwareRev = "1.2"; //VERSION char *firmwareRev = "v1.3"; //VERSION
int EEPROMVersion = 1; //version control to rewrite eeprom after update int EEPROMVersion = 1; //version control to rewrite eeprom after update
int EEPROMBuild = 2; int EEPROMBuild = 3;
//----------------------------------------------------------------------------- RUNTIME VARIABLES //----------------------------------------------------------------------------- RUNTIME VARIABLES
@ -77,8 +78,9 @@ bool preAlarm = false; //use pre-alarm?
bool smokeDetectorVerification = false; //should smoke detectors activate first stage bool smokeDetectorVerification = false; //should smoke detectors activate first stage
bool smokeDetectorCurrentlyInVerification = false; //Is a smoke detector currently in verification? bool smokeDetectorCurrentlyInVerification = false; //Is a smoke detector currently in verification?
bool audibleSilence = true; bool audibleSilence = true;
int smokeDetectorVerificationTime = 60000; //how long to wait before toggling smoke detectors back on int smokeDetectorTimeout = 60000; //how long to wait before toggling smoke detectors back on
int smokeDetectorPostRestartTimer = 0; //variable to keep track of the 60 seconds post-power up that the panel watches the smoke detector int smokeDetectorPostRestartTimer = 0; //variable to keep track of the 60 seconds post-power up that the panel watches the smoke detector
int smokeDetectorPostRestartVerificationTime = 120000; //time in ms that the smoke detector should be monitored
int smokeDetectorTimer = 0; //timer to keep track of the current smoke detector timeout progress int smokeDetectorTimer = 0; //timer to keep track of the current smoke detector timeout progress
int firstStageTime = 300000; //time in minutes that first stage should last int firstStageTime = 300000; //time in minutes that first stage should last
int firstStageTimer = 0; //timer to keep track of current first stage int firstStageTimer = 0; //timer to keep track of current first stage
@ -172,6 +174,8 @@ void resetEEPROM() {
EEPROM.write(27,0); //write current version and build EEPROM.write(27,0); //write current version and build
Serial.println("Disabled keyless silence"); Serial.println("Disabled keyless silence");
EEPROM.write(28,24); //write current version and build
Serial.println("Set smoke detector verification to 120 seconds");
EEPROM.write(50, EEPROMVersion); //write current version and build EEPROM.write(50, EEPROMVersion); //write current version and build
EEPROM.write(51, EEPROMBuild); EEPROM.write(51, EEPROMBuild);
Serial.println("Wrote EEPROM version and build"); Serial.println("Wrote EEPROM version and build");
@ -208,6 +212,10 @@ void setup() {
Serial.println("Booting..."); Serial.println("Booting...");
//----------------------------------------------------------------------------- SETUP PINS //----------------------------------------------------------------------------- SETUP PINS
pinMode(resetButtonPin, INPUT); //reset switch
if (digitalRead(resetButtonPin) == HIGH){
failsafeMode = true;
}
pinMode(hornRelay, OUTPUT); //horn pinMode(hornRelay, OUTPUT); //horn
pinMode(strobeRelay, OUTPUT); //strobe pinMode(strobeRelay, OUTPUT); //strobe
pinMode(smokeDetectorRelay, OUTPUT); //smoke relay pinMode(smokeDetectorRelay, OUTPUT); //smoke relay
@ -215,7 +223,6 @@ void setup() {
pinMode(silenceLed, OUTPUT); //silence LED pinMode(silenceLed, OUTPUT); //silence LED
pinMode(alarmLed, OUTPUT); //alarm LED pinMode(alarmLed, OUTPUT); //alarm LED
pinMode(keySwitchPin, INPUT); //key switch pinMode(keySwitchPin, INPUT); //key switch
pinMode(resetButtonPin, INPUT); //reset switch
pinMode(silenceButtonPin, INPUT); //silence switch pinMode(silenceButtonPin, INPUT); //silence switch
pinMode(drillButtonPin, INPUT); //drill switch pinMode(drillButtonPin, INPUT); //drill switch
@ -241,7 +248,7 @@ void setup() {
lcd.backlight(); lcd.backlight();
//----------------------------------------------------------------------------- EEPROM RESET BUTTONS //----------------------------------------------------------------------------- EEPROM RESET BUTTONS
if (digitalRead(resetButtonPin)==HIGH and digitalRead(silenceButtonPin)==HIGH and digitalRead(drillButtonPin)==HIGH){ //reset EEPROM if all buttons are pressed if (digitalRead(resetButtonPin)==HIGH and digitalRead(silenceButtonPin)==HIGH and digitalRead(drillButtonPin)==HIGH and failsafeMode == false){ //reset EEPROM if all buttons are pressed
for(int i=5; i!=0; i--){ for(int i=5; i!=0; i--){
lcd.clear(); lcd.clear();
lcd.setCursor(0,0); lcd.setCursor(0,0);
@ -270,16 +277,15 @@ void setup() {
} }
//----------------------------------------------------------------------------- EEPROM RESET BUTTONS //----------------------------------------------------------------------------- EEPROM RESET BUTTONS
if (digitalRead(silenceButtonPin)==HIGH){ // if (digitalRead(silenceButtonPin)==HIGH){ //debug code
debug = true; // debug = true;
} // }
lcd.clear(); lcd.clear();
lcd.setCursor(4,0); lcd.setCursor(4,0);
lcd.print("BOOTING..."); lcd.print("BOOTING...");
lcd.setCursor(0,1); lcd.setCursor(0,1);
lcd.print("IO"); lcd.print("IO");
delay(100);
Serial.println("Configured all pins"); Serial.println("Configured all pins");
@ -287,13 +293,12 @@ void setup() {
//EEPROM.commit(); //EEPROM.commit();
Serial.println("Verifying EEPROM configuration integrity..."); Serial.println("Verifying EEPROM configuration integrity...");
//----------------------------------------------------------------------------- EEPROM INTEGRETY //----------------------------------------------------------------------------- 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){ 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) and failsafeMode == false){ //completely skip eeprom verification if booting into failsafe
Serial.println("EEPROM verification failed."); Serial.println("EEPROM verification failed.");
lcd.clear(); lcd.clear();
lcd.setCursor(0,0); lcd.setCursor(0,0);
if (EEPROM.read(50) != EEPROMVersion or EEPROM.read(51) != EEPROMBuild){ if (EEPROM.read(50) != EEPROMVersion or EEPROM.read(51) != EEPROMBuild){ //display error 2 if the firmware is different
lcd.print("ERROR 2"); lcd.print("ERROR 2");
} else { } else {
lcd.print("ERROR 1"); lcd.print("ERROR 1");
@ -304,8 +309,7 @@ void setup() {
delay(1); delay(1);
} }
if(digitalRead(resetButtonPin) == HIGH){ if(digitalRead(resetButtonPin) == HIGH){
Serial.println("Resetting..."); failsafeMode = true; // ----- ENTER FAILSAFE MODE
ESP.restart();
} else if (digitalRead(drillButtonPin) == HIGH){ } else if (digitalRead(drillButtonPin) == HIGH){
resetEEPROM(); resetEEPROM();
} }
@ -313,12 +317,12 @@ void setup() {
Serial.println("EEPROM integrity verified"); Serial.println("EEPROM integrity verified");
} }
//----------------------------------------------------------------------------- EEPROM INTEGRETY //----------------------------------------------------------------------------- EEPROM INTEGRETY
if (failsafeMode == false){ //continue loading if failsafe mode is not enabled
lcd.clear(); lcd.clear();
lcd.setCursor(4,0); lcd.setCursor(4,0);
lcd.print("BOOTING..."); lcd.print("BOOTING...");
lcd.setCursor(0,1); lcd.setCursor(0,1);
lcd.print("IO-SLFTST"); lcd.print("IO-SLFTST");
delay(100);
Serial.println("Current EEPROM dump:"); //dump EEPROM into serial monitor Serial.println("Current EEPROM dump:"); //dump EEPROM into serial monitor
for (int i=0; i<=1024; i++){ for (int i=0; i<=1024; i++){
@ -337,14 +341,14 @@ void setup() {
} else { } else {
keyRequired = false; keyRequired = false;
} }
//----------------------------- Panel security variable //----------------------------- Panel security variable
if (keyRequired){ if (keyRequired){
keyRequiredVisual = true; keyRequiredVisual = true;
} else { } else {
keyRequiredVisual = false; keyRequiredVisual = false;
} }
//----------------------------- Panel security variable //----------------------------- Panel security variable
if (EEPROM.read(9) == 1){ if (EEPROM.read(9) == 1){
isVerification = true; isVerification = true;
} else { } else {
@ -375,7 +379,8 @@ void setup() {
} else { } else {
keylessSilence = false; keylessSilence = false;
} }
smokeDetectorVerificationTime = EEPROM.read(77)*5000; smokeDetectorTimeout = EEPROM.read(77)*5000;
smokeDetectorPostRestartVerificationTime = EEPROM.read(28)*5000;
firstStageTime = EEPROM.read(75)*60000; firstStageTime = EEPROM.read(75)*60000;
verificationTime = EEPROM.read(10)*100; verificationTime = EEPROM.read(10)*100;
//resistorLenience = EEPROM.read(72)*4; DEPRECATED //resistorLenience = EEPROM.read(72)*4; DEPRECATED
@ -407,8 +412,25 @@ void setup() {
digitalWrite(silenceLed, LOW); digitalWrite(silenceLed, LOW);
digitalWrite(alarmLed, LOW); digitalWrite(alarmLed, LOW);
digitalWrite(smokeDetectorRelay, LOW); //turn on smoke relay digitalWrite(smokeDetectorRelay, LOW); //turn on smoke relay
lastPulse = millis(); //start last pulse
Serial.println("-=- STARTUP COMPLETE -=-"); Serial.println("-=- STARTUP COMPLETE -=-");
} else {
Serial.println("-=- ENTERING FAILSAFE MODE -=-");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ENTERING");
lcd.setCursor(0,1);
lcd.print("FAILSAFE...");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("FAILSAFE MODE");
lcd.setCursor(0,1);
lcd.print("SYSTEM NORMAL");
digitalWrite(readyLed, HIGH);
readyLedStatus = true;
digitalWrite(smokeDetectorRelay, LOW); //turn on smoke relay
}
lastPulse = millis(); //start last pulse
} }
@ -489,14 +511,28 @@ void checkKey(){
//----------------------------------------------------------------------------- CHECK ACTIVATION DEVICES [!THIS CODE MUST WORK!] //----------------------------------------------------------------------------- CHECK ACTIVATION DEVICES [!THIS CODE MUST WORK!]
void checkDevices(){ void checkDevices(){
if (walkTest == false){ if (walkTest == false){
if ((analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0) and horn != true and silenced==false){ if (possibleAlarm == false and fullAlarm == false and (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0)){ //reading a single zero flags as a possible alarm
possibleAlarm = true; possibleAlarm = true;
} }
if (possibleAlarm == true and horn != true and strobe != true and silenced==false){ if (possibleAlarm == true and fullAlarm == false){ //only execute if the panel flags a possible alarm and there isn't currently a full alarm
if (verification >= verificationTime or isVerification == false){ if (verification >= verificationTime or isVerification == false){ //execute the following code if verification surpasses the configured verification time OR verification is disabled
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){ if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){ //check once again if any zeros are read
if (smokeDetectorVerification == false or smokeDetectorCurrentlyInVerification == true){ // ----------------------------------- SMOKE DETECTOR VERIFICATION if (smokeDetectorVerification == false or smokeDetectorCurrentlyInVerification == true){ //if smoke detector verification is disabled, or a smoke detector has tripped *after* verification, activate NACs
if (analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){ //read the pins once more to check which zone is in alarm
zoneAlarm = 3; //both
} else if (analogRead(zone2Pin) == 0){
zoneAlarm = 2; //z2
} else {
zoneAlarm = 1; //z1
}
activateNAC();
possibleAlarm = false; //dismiss the possible alarm after activating the NACs
verification = 0;
} else if (smokeDetectorVerification == true and smokeDetectorCurrentlyInVerification == false){ //if smoke detector verifcaion is turned on, run this instead
smokeDetectorOn(false); //turn off the smoke detector relay
delay(100); //wait for 100 ms
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){ // if the alarm signal persists after turning off the smoke detectors, it is a pull station, activate the nacs
if (analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){ if (analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){
zoneAlarm = 3; //both zoneAlarm = 3; //both
} else if (analogRead(zone2Pin) == 0){ } else if (analogRead(zone2Pin) == 0){
@ -505,34 +541,20 @@ void checkDevices(){
zoneAlarm = 1; //z1 zoneAlarm = 1; //z1
} }
activateNAC(); activateNAC();
smokeDetectorOn(true); //re-enable the smoke detector relay after determining that a pull station was pulled.
possibleAlarm = false; possibleAlarm = false;
verification = 0; verification = 0;
} else if (smokeDetectorVerification == true and smokeDetectorCurrentlyInVerification == false){ } else { //if the signal *does not* persists after disabling the smoke detector relay, it was a smoke detector, run verification.
smokeDetectorOn(false);
delay(100);
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){ // if the alarm signal persists after turning off the smoke detectors, activate the nacs
if (analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){
zoneAlarm = 3; //both
} else if (analogRead(zone2Pin) == 0){
zoneAlarm = 2; //z2
} else {
zoneAlarm = 1; //z1
}
smokeDetectorOn(true);
activateNAC();
possibleAlarm = false;
verification = 0;
} else {
smokeDetectorPostRestartTimer = 0; smokeDetectorPostRestartTimer = 0;
smokeDetectorCurrentlyInVerification = true; //--------------------------FIGURE OUT HOW TO DO THE SECOND PART OF SMOKE DET VERIFICATION smokeDetectorCurrentlyInVerification = true; //tell the smokeDetector() function to run code
smokeDetectorTimer = 0; smokeDetectorTimer = 0; //reset the smoke detector timer
currentScreen = -1; currentScreen = -1; //update the screen to allow the displaying of smoke detector verification
digitalWrite(alarmLed, HIGH); digitalWrite(alarmLed, HIGH); //LED indicator
possibleAlarm = false; possibleAlarm = false;
verification = 0; verification = 0;
} }
} }
} else { } else { //if no zeros are read after verification, dismiss possible alarm
possibleAlarm = false; possibleAlarm = false;
verification = 0; verification = 0;
} }
@ -590,7 +612,7 @@ void checkDevices(){
} }
if ((analogRead(zone1Pin) == 4095 or analogRead(zone2Pin) == 4095) and eolResistor == true) { if ((analogRead(zone1Pin) == 4095 or analogRead(zone2Pin) == 4095) and eolResistor == true) {
if (troubleTimer >= 10){ if (troubleTimer >= 1000){
trouble = true; trouble = true;
troubleType=1; troubleType=1;
if (analogRead(zone1Pin) == 4095 and analogRead(zone2Pin) == 4095){ if (analogRead(zone1Pin) == 4095 and analogRead(zone2Pin) == 4095){
@ -730,7 +752,7 @@ void alarm(){
strobeOn(false); strobeOn(false);
} }
if (horn == true){ if (horn == true){
if (preAlarm == false or secondStage == true){ if (preAlarm == false or secondStage == true){ //yes, preAlarm == false is redundant but in the case that second stage == false, but pre-alarm is off, the full alarm will still sound
if (codeWheel == 0){ if (codeWheel == 0){
if (codeWheelTimer == 0){ //---------- temporal code 3 if (codeWheelTimer == 0){ //---------- temporal code 3
@ -971,7 +993,7 @@ void config(){
char *mainTesting[] = {"Walk Test","Silent Wlk Test","Strobe Test"}; //menu 1 char *mainTesting[] = {"Walk Test","Silent Wlk Test","Strobe Test"}; //menu 1
char *mainSettings[] = {"Fire Alarm","Panel"}; //menu 2 char *mainSettings[] = {"Fire Alarm","Panel"}; //menu 2
char *mainSettingsFireAlarmSettings[] = {"Coding","Verification","Pre-Alarm","Audible Sil.:","No-Key Sil.:"}; //menu 3 char *mainSettingsFireAlarmSettings[] = {"Coding","Verification","Pre-Alarm","Audible Sil.:","No-Key Sil.:"}; //menu 3
char *mainSettingsVerificationSettings[] = {"Verification:","V.Time:","Det.Verif:","Det.V.Time:"}; //menu 4 char *mainSettingsVerificationSettings[] = {"Verification:","V.Time:","Det.Verif.:","Det.Timeout:","Det.Verif.:"}; //menu 4
char *mainSettingsFireAlarmSettingsCoding[] = {"Temporal Three","Marchtime","4-4","Continuous","California","Slow Marchtime"}; //menu 5 char *mainSettingsFireAlarmSettingsCoding[] = {"Temporal Three","Marchtime","4-4","Continuous","California","Slow Marchtime"}; //menu 5
char *mainSettingsFireAlarmSettingsPreAlarmSettings[] = {"Pre-Alarm:","Stage1 Time:"}; //menu 6 char *mainSettingsFireAlarmSettingsPreAlarmSettings[] = {"Pre-Alarm:","Stage1 Time:"}; //menu 6
char *mainPanelSettings[] = {"Panel Name","Panel Security","LCD Dim:","Factory Reset","About"}; //menu 8 char *mainPanelSettings[] = {"Panel Name","Panel Security","LCD Dim:","Factory Reset","About"}; //menu 8
@ -1136,7 +1158,7 @@ void config(){
} else if (cursorPosition == 2) { } else if (cursorPosition == 2) {
cursorPosition = 3; cursorPosition = 3;
configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence; configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence;
if (keyRequired == true){ if (keyRequiredVisual == true){
configBottom = (String)mainSettingsFireAlarmSettings[4]+keylessSilence; configBottom = (String)mainSettingsFireAlarmSettings[4]+keylessSilence;
} else { } else {
configBottom = (String)mainSettingsFireAlarmSettings[4]+"off"; configBottom = (String)mainSettingsFireAlarmSettings[4]+"off";
@ -1147,7 +1169,7 @@ void config(){
configBottom.replace("0","$"); configBottom.replace("0","$");
} else if (cursorPosition == 3){ } else if (cursorPosition == 3){
cursorPosition = 4; cursorPosition = 4;
if (keyRequired == true){ if (keyRequiredVisual == true){
configTop = (String)mainSettingsFireAlarmSettings[4]+keylessSilence; configTop = (String)mainSettingsFireAlarmSettings[4]+keylessSilence;
} else { } else {
configTop = (String)mainSettingsFireAlarmSettings[4]+"off"; configTop = (String)mainSettingsFireAlarmSettings[4]+"off";
@ -1212,7 +1234,7 @@ void config(){
} }
EEPROM.commit(); EEPROM.commit();
configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence; configTop = (String)mainSettingsFireAlarmSettings[3]+audibleSilence;
if (keyRequired == true){ if (keyRequiredVisual == true){
configBottom = (String)mainSettingsFireAlarmSettings[4]+keylessSilence; configBottom = (String)mainSettingsFireAlarmSettings[4]+keylessSilence;
} else { } else {
configBottom = (String)mainSettingsFireAlarmSettings[4]+"off"; configBottom = (String)mainSettingsFireAlarmSettings[4]+"off";
@ -1221,7 +1243,7 @@ void config(){
configTop.replace("0","$"); configTop.replace("0","$");
configBottom.replace("1","*"); configBottom.replace("1","*");
configBottom.replace("0","$"); configBottom.replace("0","$");
} else if (cursorPosition == 4 and keyRequired == true){ } else if (cursorPosition == 4 and keyRequiredVisual == true){
if (keylessSilence == true){ if (keylessSilence == true){
keylessSilence = false; keylessSilence = false;
EEPROM.write(27,0); EEPROM.write(27,0);
@ -1530,10 +1552,10 @@ void config(){
cursorPosition = 2; cursorPosition = 2;
configTop = (String)mainSettingsVerificationSettings[2] + smokeDetectorVerification; configTop = (String)mainSettingsVerificationSettings[2] + smokeDetectorVerification;
if (smokeDetectorVerification == true){ if (smokeDetectorVerification == true){
if (smokeDetectorVerificationTime<60000){ if (smokeDetectorTimeout<60000){
configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/1000) + "s"; configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/1000) + "s";
} else { } else {
configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/60000) + "m"; configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/60000) + "m";
} }
} else { } else {
configBottom = (String)mainSettingsVerificationSettings[3] + "off"; configBottom = (String)mainSettingsVerificationSettings[3] + "off";
@ -1543,18 +1565,38 @@ void config(){
} else if (cursorPosition == 2) { } else if (cursorPosition == 2) {
cursorPosition = 3; cursorPosition = 3;
if (smokeDetectorVerification == true){ if (smokeDetectorVerification == true){
if (smokeDetectorVerificationTime<60000){ if (smokeDetectorTimeout<60000){
configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/1000) + "s"; configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/1000) + "s";
} else { } else {
configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/60000) + "m"; configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/60000) + "m";
} }
} else { } else {
configTop = (String)mainSettingsVerificationSettings[3] + "off"; configTop = (String)mainSettingsVerificationSettings[3] + "off";
} }
if (smokeDetectorVerification == true){
if (smokeDetectorPostRestartVerificationTime<60000){
configBottom = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/1000) + "s";
} else {
configBottom = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/60000) + "m";
}
} else {
configBottom = (String)mainSettingsVerificationSettings[4] + "off";
}
} else if (cursorPosition == 3) {
cursorPosition = 4;
if (smokeDetectorVerification == true){
if (smokeDetectorPostRestartVerificationTime<60000){
configTop = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/1000) + "s";
} else {
configTop = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/60000) + "m";
}
} else {
configTop = (String)mainSettingsVerificationSettings[4] + "off";
}
configBottom = (String)mainSettingsVerificationSettings[0] + isVerification; configBottom = (String)mainSettingsVerificationSettings[0] + isVerification;
configBottom.replace("1","*"); configBottom.replace("1","*");
configBottom.replace("0","$"); configBottom.replace("0","$");
} else if (cursorPosition == 3) { } else if (cursorPosition == 4) {
cursorPosition = 0; cursorPosition = 0;
configTop = (String)mainSettingsVerificationSettings[0] + isVerification; configTop = (String)mainSettingsVerificationSettings[0] + isVerification;
if (isVerification == false){ if (isVerification == false){
@ -1624,7 +1666,7 @@ void config(){
} else { } else {
EEPROM.write(76,0); //disable pre-alarm EEPROM.write(76,0); //disable pre-alarm
smokeDetectorVerification = false; smokeDetectorVerification = false;
smokeDetectorOn(true); //re-enable smoke detectors in the case that one turned off because it was in verification smokeDetectorOn(true); //re-enable smoke detectors in the case that smoke detectors are currently in timeout
digitalWrite(alarmLed, LOW); digitalWrite(alarmLed, LOW);
smokeDetectorCurrentlyInVerification=false; smokeDetectorCurrentlyInVerification=false;
smokeDetectorPostRestartTimer=0; smokeDetectorPostRestartTimer=0;
@ -1633,10 +1675,10 @@ void config(){
EEPROM.commit(); EEPROM.commit();
configTop = (String)mainSettingsVerificationSettings[2] + smokeDetectorVerification; configTop = (String)mainSettingsVerificationSettings[2] + smokeDetectorVerification;
if (smokeDetectorVerification == true){ if (smokeDetectorVerification == true){
if (smokeDetectorVerificationTime<60000){ if (smokeDetectorTimeout<60000){
configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/1000) + "s"; configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/1000) + "s";
} else { } else {
configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/60000) + "m"; configBottom = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/60000) + "m";
} }
} else { } else {
configBottom = (String)mainSettingsVerificationSettings[3] + "off"; configBottom = (String)mainSettingsVerificationSettings[3] + "off";
@ -1644,44 +1686,79 @@ void config(){
configTop.replace("1","*"); configTop.replace("1","*");
configTop.replace("0","$"); configTop.replace("0","$");
} else if (cursorPosition == 3 and smokeDetectorVerification == true) { } else if (cursorPosition == 3 and smokeDetectorVerification == true) {
if (smokeDetectorVerificationTime == 5000){ if (smokeDetectorTimeout == 5000){
EEPROM.write(77,2); EEPROM.write(77,2);
smokeDetectorVerificationTime = 10000; smokeDetectorTimeout = 10000;
} else if (smokeDetectorVerificationTime == 10000){ } else if (smokeDetectorTimeout == 10000){
EEPROM.write(77,3); EEPROM.write(77,3);
smokeDetectorVerificationTime = 15000; smokeDetectorTimeout = 15000;
} else if (smokeDetectorVerificationTime == 15000){ } else if (smokeDetectorTimeout == 15000){
EEPROM.write(77,4); EEPROM.write(77,4);
smokeDetectorVerificationTime = 20000; smokeDetectorTimeout = 20000;
} else if (smokeDetectorVerificationTime == 20000){ } else if (smokeDetectorTimeout == 20000){
EEPROM.write(77,6); EEPROM.write(77,6);
smokeDetectorVerificationTime = 30000; smokeDetectorTimeout = 30000;
} else if (smokeDetectorVerificationTime == 30000){ } else if (smokeDetectorTimeout == 30000){
EEPROM.write(77,9); EEPROM.write(77,9);
smokeDetectorVerificationTime = 45000; smokeDetectorTimeout = 45000;
} else if (smokeDetectorVerificationTime == 45000){ } else if (smokeDetectorTimeout == 45000){
EEPROM.write(77,18); EEPROM.write(77,12);
smokeDetectorVerificationTime = 60000; smokeDetectorTimeout = 60000;
} else if (smokeDetectorVerificationTime == 60000){ } else if (smokeDetectorTimeout == 60000){
EEPROM.write(77,24); EEPROM.write(77,24);
smokeDetectorVerificationTime = 120000; smokeDetectorTimeout = 120000;
} else if (smokeDetectorVerificationTime == 120000){ } else if (smokeDetectorTimeout == 120000){
EEPROM.write(77,60); EEPROM.write(77,60);
smokeDetectorVerificationTime = 300000; smokeDetectorTimeout = 300000;
} else if (smokeDetectorVerificationTime == 300000){ } else if (smokeDetectorTimeout == 300000){
EEPROM.write(77,120); EEPROM.write(77,120);
smokeDetectorVerificationTime = 600000; smokeDetectorTimeout = 600000;
} else if (smokeDetectorVerificationTime == 600000){ } else if (smokeDetectorTimeout == 600000){
EEPROM.write(77,1); EEPROM.write(77,1);
smokeDetectorVerificationTime = 5000; smokeDetectorTimeout = 5000;
} }
EEPROM.commit(); EEPROM.commit();
if (smokeDetectorVerificationTime<60000){ if (smokeDetectorTimeout<60000){
configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/1000) + "s"; configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/1000) + "s";
} else { } else {
configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorVerificationTime/60000) + "m"; configTop = (String)mainSettingsVerificationSettings[3] + (smokeDetectorTimeout/60000) + "m";
} }
configBottom = (String)mainSettingsVerificationSettings[0]+isVerification; if (smokeDetectorVerification == true){
if (smokeDetectorPostRestartVerificationTime<60000){
configBottom = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/1000) + "s";
} else {
configBottom = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/60000) + "m";
}
} else {
configBottom = (String)mainSettingsVerificationSettings[4] + "off";
}
} else if (cursorPosition == 4 and smokeDetectorVerification == true) {
if (smokeDetectorPostRestartVerificationTime == 60000){
EEPROM.write(28,24);
smokeDetectorPostRestartVerificationTime = 120000;
} else if (smokeDetectorPostRestartVerificationTime == 120000){
EEPROM.write(28,36);
smokeDetectorPostRestartVerificationTime = 180000;
} else if (smokeDetectorPostRestartVerificationTime == 180000){
EEPROM.write(28,48);
smokeDetectorPostRestartVerificationTime = 240000;
} else if (smokeDetectorPostRestartVerificationTime == 240000){
EEPROM.write(28,60);
smokeDetectorPostRestartVerificationTime = 300000;
} else if (smokeDetectorPostRestartVerificationTime == 300000){
EEPROM.write(28,60);
smokeDetectorPostRestartVerificationTime = 600000;
} else if (smokeDetectorPostRestartVerificationTime == 600000){
EEPROM.write(28,12);
smokeDetectorPostRestartVerificationTime = 60000;
}
EEPROM.commit();
if (smokeDetectorPostRestartVerificationTime<60000){
configTop = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/1000) + "s";
} else {
configTop = (String)mainSettingsVerificationSettings[4] + (smokeDetectorPostRestartVerificationTime/60000) + "m";
}
configBottom = (String)mainSettingsVerificationSettings[0] + isVerification;
configBottom.replace("1","*"); configBottom.replace("1","*");
configBottom.replace("0","$"); configBottom.replace("0","$");
} }
@ -1916,7 +1993,7 @@ void lcdBacklight(){
} else if (backlightOn == true) { } else if (backlightOn == true) {
lcdTimeoutTimer++; lcdTimeoutTimer++;
} }
if (drillPressed == true or silencePressed == true or resetPressed == true or fullAlarm == true or trouble == true or (keyInserted == true and keyRequired == true)){ if (drillPressed == true or silencePressed == true or resetPressed == true or fullAlarm == true or trouble == true or (keyInserted == true and keyRequired == true) or smokeDetectorCurrentlyInVerification == true){
lcdTimeoutTimer = 0; lcdTimeoutTimer = 0;
if (backlightOn == false){ if (backlightOn == false){
lcd.backlight(); lcd.backlight();
@ -1927,12 +2004,12 @@ void lcdBacklight(){
} }
void smokeDetector(){ void smokeDetector(){
if (smokeDetectorTimer >= smokeDetectorVerificationTime){ if (smokeDetectorTimer >= smokeDetectorTimeout){ //wait until the configured smoke timeout time has elapsed
smokeDetectorOn(true); smokeDetectorOn(true); //re-enable the smoke relay
if (smokeDetectorPostRestartTimer >= 60000){ if (smokeDetectorPostRestartTimer >= smokeDetectorPostRestartVerificationTime){ //wait for 120 seconds, during this time, smokeDetectorCurrentlyInVerification will be true, so any activating device will cause a full alarm
smokeDetectorCurrentlyInVerification = false; smokeDetectorCurrentlyInVerification = false; //stop smoke detector verification, causing the smoke detectors to require double activation again
currentScreen = -1; currentScreen = -1; //update screen
digitalWrite(alarmLed, LOW); digitalWrite(alarmLed, LOW); //disable LED
smokeDetectorTimer = 0; smokeDetectorTimer = 0;
} else { } else {
smokeDetectorPostRestartTimer++; smokeDetectorPostRestartTimer++;
@ -1942,10 +2019,57 @@ void smokeDetector(){
} }
} }
void failsafe(){ //--------------------------------------------- FAILSAFE MODE IN CASE PANEL CANT BOOT NORMALLY
if ((analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0) and fullAlarm == false){
fullAlarm = true;
silenced = false;
digitalWrite(alarmLed, HIGH);
digitalWrite(hornRelay, LOW);
digitalWrite(strobeRelay, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("FAILSAFE MODE");
lcd.setCursor(0,1);
lcd.print("FIRE ALARM");
}
if (digitalRead(silenceButtonPin) == HIGH and silenced == false and fullAlarm == true){
silenced = true;
digitalWrite(hornRelay, HIGH);
digitalWrite(silenceLed,HIGH);
digitalWrite(alarmLed,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("FAILSAFE MODE");
lcd.setCursor(0,1);
lcd.print("SILENCED");
}
if (digitalRead(resetButtonPin) == HIGH){
digitalWrite(smokeDetectorRelay, HIGH);
digitalWrite(hornRelay, HIGH);
digitalWrite(silenceLed,LOW);
digitalWrite(alarmLed,LOW);
digitalWrite(readyLed,LOW);
ESP.restart();
}
if (troubleLedTimer >= 2000){
if (readyLedStatus == true){
digitalWrite(readyLed, LOW);
readyLedStatus = false;
} else {
digitalWrite(readyLed, HIGH);
readyLedStatus = true;
}
troubleLedTimer = 0;
} else {
troubleLedTimer++;
}
}
void loop() { void loop() {
systemClock = millis(); //-------------------- SYSTEM CLOCK systemClock = millis(); //-------------------- SYSTEM CLOCK
if (systemClock-lastPulse >= 1){ if (systemClock-lastPulse >= 1){
if (failsafeMode == false){
lcdBacklight(); //------------------------------------------------------ CHECK LCD BACKLIGHT lcdBacklight(); //------------------------------------------------------ CHECK LCD BACKLIGHT
checkDevices(); //------------------------------------------------------ CHECK ACTIVATING DEVICES checkDevices(); //------------------------------------------------------ CHECK ACTIVATING DEVICES
@ -1954,7 +2078,7 @@ void loop() {
alarm(); //------------------------------------------------------------- ALARM CODEWHEEL alarm(); //------------------------------------------------------------- ALARM CODEWHEEL
if (smokeDetectorCurrentlyInVerification == true){ if (smokeDetectorCurrentlyInVerification == true and fullAlarm == false){ //if a smoke detector is in verification, execute this function
smokeDetector(); smokeDetector();
} }
@ -1994,7 +2118,9 @@ void loop() {
} else { } else {
buttonCheckTimer++; buttonCheckTimer++;
} }
} else {
failsafe();
}
lastPulse = millis(); //update last pulse lastPulse = millis(); //update last pulse
} }
} }