feat: alarm support
This commit is contained in:
parent
282675a487
commit
5f57eea889
@ -4,7 +4,7 @@ class LedController {
|
||||
private:
|
||||
int bluePin = 32;
|
||||
int redPin = 33;
|
||||
int greenPin = 25;
|
||||
int greenPin = 27;
|
||||
AlarmStatus* status;
|
||||
|
||||
void turnOn(int led){
|
||||
|
@ -1,2 +1,78 @@
|
||||
#include "alarm.h"
|
||||
#include <XT_DAC_Audio.h>
|
||||
|
||||
#include "alarm.h"
|
||||
#include "Arduino.h"
|
||||
#include "sound.h"
|
||||
#include "soc/rtc_io_reg.h"
|
||||
#include "alarmSound.h"
|
||||
|
||||
// XT_Wav_Class SirenSound(sampleSound);
|
||||
XT_Wav_Class SirenSound(alarmSound);
|
||||
XT_DAC_Audio_Class DacAudio(25, 0);
|
||||
uint32_t DemoCounter=0;
|
||||
|
||||
class Siren{
|
||||
private:
|
||||
int sirenPin = 25;
|
||||
AlarmStatus* status;
|
||||
float sinVal;
|
||||
int toneVal;
|
||||
|
||||
|
||||
|
||||
void playSound(){
|
||||
int max = 180;
|
||||
Serial.println("Sound on " + String(sirenPin));
|
||||
|
||||
if(status->silent)
|
||||
max = 2;
|
||||
for(int x = 0; x < max ; x++){
|
||||
//convert angle of sinusoidal to radian measure
|
||||
sinVal = (sin(x*(3.1412/180)));
|
||||
//generate sound of different frequencies by sinusoidal value
|
||||
toneVal = 2000+(int(sinVal*1000));
|
||||
//Set a frequency for Pin-out 8
|
||||
|
||||
// ledcAttach(sirenPin, toneVal, 3);
|
||||
tone(sirenPin, toneVal, 3);
|
||||
// buzzer->tone(toneVal, 3);
|
||||
// TimerFreeTone(TONE_PIN, toneVal, 2, 5);
|
||||
delay(2);
|
||||
}
|
||||
noTone(sirenPin);
|
||||
// buzzer->noTone();
|
||||
// ledcWrite(sirenPin,0); // No sound
|
||||
// ledcDetach(sirenPin);
|
||||
}
|
||||
|
||||
public:
|
||||
Siren(AlarmStatus* statusRef){
|
||||
status=statusRef;
|
||||
}
|
||||
|
||||
Siren(AlarmStatus* statusRef, int pin){
|
||||
status=statusRef;
|
||||
sirenPin=pin;
|
||||
}
|
||||
|
||||
|
||||
void Init(){
|
||||
// pinMode(sirenPin, OUTPUT);
|
||||
// DacAudio = XT_DAC_Audio_Class(sirenPin, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SoundSiren(){
|
||||
if(status->muted)
|
||||
return;
|
||||
|
||||
// playSound();
|
||||
// delay(500);
|
||||
|
||||
DacAudio.FillBuffer(); // Fill the sound buffer with data
|
||||
if(SirenSound.Playing==false) // if not playing,
|
||||
DacAudio.Play(&SirenSound); // play it, this will cause it to repeat and repeat...
|
||||
Serial.println(DemoCounter++);
|
||||
}
|
||||
};
|
@ -1,17 +1,22 @@
|
||||
#include <Arduino.h>
|
||||
#include "alarm.h"
|
||||
#include "doorSensor.h"
|
||||
#include "DoorSensor.h"
|
||||
#include "LedController.h"
|
||||
#include "Siren.h"
|
||||
// #include <WiFi.h>
|
||||
|
||||
AlarmStatus s = {DOOR_OPEN, false, false, false, true};
|
||||
DoorSensor doorSensor(DoorSensor::DEFAULT_DOOR_SENSOR_PIN, &s);
|
||||
AlarmStatus s;
|
||||
DoorSensor doorSensor(&s);
|
||||
LedController led(&s);
|
||||
Siren siren(&s);
|
||||
|
||||
void printStatus(){
|
||||
String msg = String("Door: ") + String(doorSensor.IsDoorOpen() ? "Open" : "Closed");
|
||||
msg = msg + " | Alarm: " + String(s.isArmed ? "Armed": "Disarmed");
|
||||
msg = msg + " | Is Fired: " + String(s.isFired ? "Fired": "Not Fired");
|
||||
msg = msg + " | Led: " + String(s.ledOn ? "On": "Off");
|
||||
msg = msg + " | Silent: " + String(s.silent ? "Silent": "Loud");
|
||||
msg = msg + " | Muted: " + String(s.muted ? "Muted": "Not Muted");
|
||||
Serial.println(msg);
|
||||
}
|
||||
void setup() {
|
||||
@ -20,16 +25,15 @@ void setup() {
|
||||
printStatus();
|
||||
doorSensor.Init();
|
||||
led.Init();
|
||||
printStatus();
|
||||
|
||||
siren.Init();
|
||||
|
||||
s.isArmed = doorSensor.IsDoorClosed();
|
||||
Serial.println("Alarm is " + String(s.isArmed ? "Armed" : "Disarmed"));
|
||||
// Serial.println("Alarm is " + String(s.isArmed ? "Armed" : "Disarmed"));
|
||||
// WiFi.mode(WIFI_STA);
|
||||
// WiFi.disconnect();
|
||||
// delay(100);
|
||||
|
||||
Serial.println("Stp Done");
|
||||
printStatus();
|
||||
|
||||
}
|
||||
|
||||
@ -42,10 +46,15 @@ void loop() {
|
||||
s.doorChanged=false;
|
||||
|
||||
|
||||
if(s.isFired){
|
||||
s.silent = !s.silent;
|
||||
siren.SoundSiren();
|
||||
}
|
||||
|
||||
led.Update();
|
||||
|
||||
|
||||
delay(1000);
|
||||
// delay(1000);
|
||||
|
||||
}
|
||||
|
||||
@ -60,7 +69,7 @@ void DoorEvent(){
|
||||
Serial.println("Alarm is armed, firing");
|
||||
s.isFired=true;
|
||||
}else{
|
||||
delay(500);
|
||||
// delay(500);
|
||||
Serial.println("The door-closing");
|
||||
s.isArmed=true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user