many changes

This commit is contained in:
Lexzach 2022-09-29 17:39:07 -04:00
parent cb18179fcb
commit 8dde71bf6a
Signed by: Lexzach
GPG Key ID: B574880929E6F1F0
2 changed files with 161 additions and 100 deletions

View File

@ -52,9 +52,9 @@ int walkTestSmokeDetectorTimer = 0;
int currentScreen = -1; //update display if previous screen is not the same int currentScreen = -1; //update display if previous screen is not the same
int configPage = 0; //config page for the config menu int configPage = 0; //config page for the config menu
int cursorPosition = 0; //which menu item the cursor is over int cursorPosition = 0; //which menu item the cursor is over
int zerosCounted = 0; //verification variable int zone1Count = 0; //walk test variables
int walkTestCount = 0; //keep track of walk test activations int zone2Count = 0;
int zoneAlarm = 0; //which zone is in alarm 0 - none | 1 - zone 1 | 2 - zone 2 | 3 - zone 1 & 2 int zoneAlarm = 0; //which zone is in alarm 0 - none | 1 - zone 1 | 2 - zone 2 | 3 - zone 1 & 2 | 4 - drill
String configTop; //configuration menu strings for lcd String configTop; //configuration menu strings for lcd
String configBottom; String configBottom;
String currentConfigTop; //configuration menu strings for current lcd display String currentConfigTop; //configuration menu strings for current lcd display
@ -91,7 +91,7 @@ bool audibleSilence = true;
int smokeDetectorTimeout = 5; //how long should smoke detector pre-alarm wait before cancelling the pre-alarm 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 firstStageTime = 1; //time in minutes that first stage should last
int codeWheel = 0; //which alarm pattern to use, code-3 default int codeWheel = 0; //which alarm pattern to use, code-3 default
int verificationTime = 250; int verificationTime = 2500;
//int resistorLenience = 0; DEPRECATED //int resistorLenience = 0; DEPRECATED
int panelHomescreen = 0; int panelHomescreen = 0;
int lcdTimeout = 0; int lcdTimeout = 0;
@ -134,7 +134,7 @@ int sdaPin = 21;
//maybe instead of looking for 0s for activation, simply look for a dip in voltage //maybe instead of looking for 0s for activation, simply look for a dip in voltage
//REMOVE STUPID ZERO COUNTER, ITS OBSELETE
@ -385,7 +385,7 @@ void setup() {
} }
//---------------------------------------------------------------------------------------- functions for turning certain things on and off
void tone() { void tone() {
ledcSetup(0, 5000, 8); // setup beeper ledcSetup(0, 5000, 8); // setup beeper
ledcAttachPin(buzzerPin, 0); // attach beeper ledcAttachPin(buzzerPin, 0); // attach beeper
@ -396,6 +396,28 @@ void noTone() {
ledcAttachPin(buzzerPin, 0); // attach beeper ledcAttachPin(buzzerPin, 0); // attach beeper
ledcWriteTone(0, 0); // stop tone ledcWriteTone(0, 0); // stop tone
} }
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
void activateNAC(){ void activateNAC(){
horn = true; horn = true;
@ -434,23 +456,25 @@ void checkDevices(){
if (debug == true){ if (debug == true){
Serial.println(analogRead(zone1Pin)); Serial.println(analogRead(zone1Pin));
} }
if (walkTest == 0){ if (walkTest == false){
if ((analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0) and horn != true and silenced==false){ if ((analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0) and horn != true and silenced==false){
possibleAlarm = true; possibleAlarm = true;
} }
if (possibleAlarm == true and horn != true and strobe != true and silenced==false and isVerification == true){ //verification code if (possibleAlarm == true and horn != true and strobe != true and silenced==false and isVerification == true){ //verification code
if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){
zerosCounted++;
}
if (verification >= verificationTime){ if (verification >= verificationTime){
if (zerosCounted > 0.1*verificationTime and analogRead(zone1Pin) == 0 and analogRead(zone2Pin) == 0){ 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
}
definiteAlarm = true; definiteAlarm = true;
possibleAlarm = false; possibleAlarm = false;
zerosCounted = 0;
verification = 0; verification = 0;
} else { } else {
zerosCounted = 0;
possibleAlarm = false; possibleAlarm = false;
verification = 0; verification = 0;
} }
@ -459,29 +483,35 @@ void checkDevices(){
} }
} }
} else if (walkTest == true){ } else if (walkTest == true){
if (analogRead(zone1Pin) == 0){// or analogRead(zone2Pin) == 0){ if (analogRead(zone1Pin) == 0 or analogRead(zone2Pin) == 0){// or analogRead(zone2Pin) == 0){
walkTestCount++; if (analogRead(zone1Pin) == 0){
walkTestSmokeDetectorTimer = 0; zone1Count++;
while (analogRead(zone1Pin) == 0) {// or analogRead(zone2Pin) <= resistorLenience) { --------------------------------- SOMEHOW FIX THIS, terribly designed devices that add voltage into the system can screw this up smokeDetectorOn(false);
digitalWrite(strobeRelay, LOW); strobeOn(true);
if (silentWalkTest == false){ delay(500);
digitalWrite(hornRelay, LOW); hornOn(true);
delay(500);
hornOn(false);
delay(3000);
strobeOn(false);
smokeDetectorOn(true);
} else if (analogRead(zone2Pin) == 0){
zone2Count++;
smokeDetectorOn(false);
strobeOn(true);
delay(500);
hornOn(true);
delay(500);
hornOn(false);
delay(500);
hornOn(true);
delay(500);
hornOn(false);
delay(3000);
strobeOn(false);
smokeDetectorOn(true);
} }
digitalWrite(alarmLed, HIGH);
walkTestSmokeDetectorTimer++;
if (walkTestSmokeDetectorTimer >= 500){
digitalWrite(smokeDetectorRelay, HIGH);
}
delay(1);
}
digitalWrite(strobeRelay, HIGH);
if (silentWalkTest == false){
digitalWrite(hornRelay, HIGH);
}
digitalWrite(alarmLed, LOW);
currentScreen = -1; currentScreen = -1;
delay(250);
digitalWrite(smokeDetectorRelay, LOW);
} }
} }
@ -523,13 +553,6 @@ void troubleCheck(){
} }
} else { } else {
if (walkTest == false){
digitalWrite(readyLed, HIGH);
readyLedStatus = true;
}
if (troubleLedTimer != 0){
noTone();
}
troubleLedTimer=0; troubleLedTimer=0;
} }
} }
@ -545,9 +568,9 @@ void reboot(){
digitalWrite(readyLed, HIGH); //ready LED digitalWrite(readyLed, HIGH); //ready LED
digitalWrite(silenceLed, HIGH); //silence LED digitalWrite(silenceLed, HIGH); //silence LED
digitalWrite(alarmLed, HIGH); //alarm LED digitalWrite(alarmLed, HIGH); //alarm LED
digitalWrite(hornRelay, HIGH); //horn hornOn(false); //horn
digitalWrite(strobeRelay, HIGH); //strobe strobeOn(false); //strobe
digitalWrite(smokeDetectorRelay, HIGH); //smoke relay smokeDetectorOn(false); //smoke relay
lcd.backlight(); lcd.backlight();
delay(2500); delay(2500);
noTone(); noTone();
@ -561,14 +584,16 @@ void reboot(){
//----------------------------------------------------------------------------- BUTTON CHECK //----------------------------------------------------------------------------- BUTTON CHECK
void checkButtons(){ void checkButtons(){
if (digitalRead(resetButtonPin) == HIGH){ //RESET BUTTON if (digitalRead(resetButtonPin) == HIGH){ //-----------------------------------------------------------RESET BUTTON
reboot(); reboot();
} }
if (digitalRead(silenceButtonPin) == HIGH){ //SILENCE BUTTON if (digitalRead(silenceButtonPin) == HIGH){ //---------------------------------------------------------SILENCE BUTTON
if (horn == true){ //if horns are not silenced, silence the horns if (horn == true){ //if horns are not silenced, silence the horns
digitalWrite(silenceLed, HIGH); digitalWrite(silenceLed, HIGH);
digitalWrite(alarmLed, LOW); digitalWrite(alarmLed, LOW);
digitalWrite(readyLed, LOW);
readyLedStatus = false;
horn = false; horn = false;
if (audibleSilence == false){ if (audibleSilence == false){
strobe = false; strobe = false;
@ -596,8 +621,9 @@ void checkButtons(){
silencePressed = false; silencePressed = false;
} }
if (digitalRead(drillButtonPin) == HIGH and horn != true){ //DRILL BUTTON if (digitalRead(drillButtonPin) == HIGH and horn != true and silenced != true){ //------------------------------------------DRILL BUTTON
if (drill >= 5000){ if (drill >= 5000){
zoneAlarm = 4;
activateNAC(); activateNAC();
} else { } else {
drill++; drill++;
@ -614,25 +640,25 @@ void checkButtons(){
//----------------------------------------------------------------------------- NAC ACTIVATION //----------------------------------------------------------------------------- NAC ACTIVATION
void alarm(){ void alarm(){
if (strobe == true){ if (strobe == true){
digitalWrite(strobeRelay, LOW); strobeOn(true);
}else{ }else{
digitalWrite(strobeRelay,HIGH); strobeOn(false);
} }
if (horn == true){ if (horn == true){
if (codeWheel == 0){ if (codeWheel == 0){
if (codeWheelTimer == 0){ //temporal code 3 if (codeWheelTimer == 0){ //temporal code 3
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 500) { } else if (codeWheelTimer == 500) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 1000) { } else if (codeWheelTimer == 1000) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 1500) { } else if (codeWheelTimer == 1500) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 2000) { } else if (codeWheelTimer == 2000) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 2500) { } else if (codeWheelTimer == 2500) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 4000) { } else if (codeWheelTimer == 4000) {
codeWheelTimer = -1; codeWheelTimer = -1;
} }
@ -641,9 +667,9 @@ void alarm(){
} else if (codeWheel == 1) { } else if (codeWheel == 1) {
if (codeWheelTimer == 0){ //marchtime if (codeWheelTimer == 0){ //marchtime
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 250){ } else if (codeWheelTimer == 250){
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 500){ } else if (codeWheelTimer == 500){
codeWheelTimer = -1; codeWheelTimer = -1;
} }
@ -651,58 +677,58 @@ void alarm(){
} else if (codeWheel == 2) { //4-4 } else if (codeWheel == 2) { //4-4
if (codeWheelTimer == 0) { if (codeWheelTimer == 0) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 300) { } else if (codeWheelTimer == 300) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 600) { } else if (codeWheelTimer == 600) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 900) { } else if (codeWheelTimer == 900) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 1200) { } else if (codeWheelTimer == 1200) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 1500) { } else if (codeWheelTimer == 1500) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 1800) { } else if (codeWheelTimer == 1800) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 2100) { } else if (codeWheelTimer == 2100) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 2850) { } else if (codeWheelTimer == 2850) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 3150) { } else if (codeWheelTimer == 3150) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 3450) { } else if (codeWheelTimer == 3450) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 3750) { } else if (codeWheelTimer == 3750) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 4050) { } else if (codeWheelTimer == 4050) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 4350) { } else if (codeWheelTimer == 4350) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 4650) { } else if (codeWheelTimer == 4650) {
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 4950) { } else if (codeWheelTimer == 4950) {
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 14950) { } else if (codeWheelTimer == 14950) {
codeWheelTimer = -1; codeWheelTimer = -1;
} }
} else if (codeWheel == 3) { //continuous } else if (codeWheel == 3) { //continuous
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheel == 5) { } else if (codeWheel == 5) {
if (codeWheelTimer == 0){ //marchtime slower if (codeWheelTimer == 0){ //marchtime slower
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 500){ } else if (codeWheelTimer == 500){
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 1000){ } else if (codeWheelTimer == 1000){
codeWheelTimer = -1; codeWheelTimer = -1;
} }
} else if (codeWheel == 4) { } else if (codeWheel == 4) {
if (codeWheelTimer == 0){ //california code if (codeWheelTimer == 0){ //california code
digitalWrite(hornRelay, LOW); hornOn(true);
} else if (codeWheelTimer == 10000){ } else if (codeWheelTimer == 10000){
digitalWrite(hornRelay, HIGH); hornOn(false);
} else if (codeWheelTimer == 15000){ } else if (codeWheelTimer == 15000){
codeWheelTimer = -1; codeWheelTimer = -1;
} }
@ -710,20 +736,27 @@ void alarm(){
} }
codeWheelTimer++; codeWheelTimer++;
} else {
hornOn(false);
codeWheelTimer = 0;
}
if (fullAlarm == true){
alarmLedTimer++; alarmLedTimer++;
if (alarmLedTimer >= 750){ if (alarmLedTimer >= 750){
if (digitalRead(25) == false){ if (digitalRead(alarmLed) == false){
if (silenced == true){
tone();
}
digitalWrite(alarmLed, HIGH); digitalWrite(alarmLed, HIGH);
alarmLedTimer = 0;
} else { } else {
if (silenced == true){
noTone();
}
digitalWrite(alarmLed, LOW); digitalWrite(alarmLed, LOW);
}
alarmLedTimer = 0; alarmLedTimer = 0;
} }
} }
} else {
digitalWrite(hornRelay, HIGH);
codeWheelTimer = 0;
}
} }
//----------------------------------------------------------------------------- NAC ACTIVATION //----------------------------------------------------------------------------- NAC ACTIVATION
@ -765,16 +798,45 @@ void lcdUpdate(){
} else if (fullAlarm == true and silenced == false and currentScreen != 3){ } else if (fullAlarm == true and silenced == false and currentScreen != 3){
lcd.clear(); lcd.clear();
lcd.setCursor(1,0); lcd.setCursor(1,0);
if (keyRequired == true and keyInserted == false){
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.print("* FIRE ALARM *"); lcd.print("* FIRE ALARM *");
// lcd.setCursor(2,1); } else {
// lcd.print("Zone 1"); 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");
}
currentScreen = 3; currentScreen = 3;
} else if (silenced == true and currentScreen != 4){ } else if (silenced == true and currentScreen != 4){
lcd.clear(); lcd.clear();
lcd.setCursor(1,0); if (keyRequired == true and keyInserted == false){
lcd.print("* FIRE ALARM *"); lcd.setCursor(0,0);
lcd.setCursor(1,1); lcd.write(byte(0));
lcd.print("-- SILENCED --"); 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");
}
// lcd.setCursor(2,1); // lcd.setCursor(2,1);
// lcd.print("Zone 1"); // lcd.print("Zone 1");
currentScreen = 4; currentScreen = 4;
@ -783,13 +845,10 @@ void lcdUpdate(){
lcd.setCursor(0,0); lcd.setCursor(0,0);
lcd.print("* Supervisory *"); lcd.print("* Supervisory *");
lcd.setCursor(0,1); lcd.setCursor(0,1);
if (silentWalkTest == false){ lcd.print("Z1:"+(String)zone1Count+" Z2:"+(String)zone2Count);
lcd.print("Walk Test - "+(String)walkTestCount);
} else {
lcd.print("S. Wlk Test - "+(String)walkTestCount);
}
currentScreen = 5; currentScreen = 5;
digitalWrite(readyLed, LOW); //ready led off for walk test digitalWrite(readyLed, LOW); //ready led off for walk test
readyLedStatus = false;
} else if (drillPressed == true and fullAlarm == false and horn == false and strobe == false and walkTest == false and currentScreen != 6) { } else if (drillPressed == true and fullAlarm == false and horn == false and strobe == false and walkTest == false and currentScreen != 6) {
lcd.clear(); lcd.clear();
lcd.setCursor(0,0); lcd.setCursor(0,0);
@ -895,14 +954,16 @@ void config(){
silencePressed = true; silencePressed = true;
configMenu = false; configMenu = false;
currentScreen=-1; currentScreen=-1;
walkTestCount = 0; zone1Count = 0;
zone2Count = 0;
} else if (cursorPosition == 1) { } else if (cursorPosition == 1) {
walkTest = true; walkTest = true;
silentWalkTest = true; silentWalkTest = true;
silencePressed = true; silencePressed = true;
configMenu = false; configMenu = false;
currentScreen=-1; currentScreen=-1;
walkTestCount = 0; zone1Count = 0;
zone2Count = 0;
} else if (cursorPosition == 2) { } else if (cursorPosition == 2) {
if (strobe == false){ if (strobe == false){
strobe = true; strobe = true;
@ -1410,7 +1471,7 @@ void config(){
// if (configTop.indexOf("*")>0){ //replace any "*" with nothing, then add a check mark to the end // if (configTop.indexOf("*")>0){ //replace any "*" with nothing, then add a check mark to the end
// lcd.print("]" + configTop.replace("*","")); // lcd.print("]" + configTop.replace("*",""));
// } else { //---------------------------------------------------------------------------------------- experimental code for check // } else { //---------------------------------------------------------------------------------------- experimental code for check mark
lcd.print("]" + configTop); lcd.print("]" + configTop);
//} //}
} else { } else {

View File

@ -1 +1 @@
,lexzach,GLaDOS,27.09.2022 19:20,file:///home/lexzach/.config/libreoffice/4; ,lexzach,GLaDOS,29.09.2022 11:46,file:///home/lexzach/.config/libreoffice/4;