Compare commits

..

No commits in common. "5f57eea889f508a03ad919e9019348152ed4c586" and "8a419375aa33a29b76c5d7092ca20246aa2f27bc" have entirely different histories.

7 changed files with 17 additions and 2955 deletions

View File

@ -4,7 +4,7 @@ class LedController {
private:
int bluePin = 32;
int redPin = 33;
int greenPin = 27;
int greenPin = 25;
AlarmStatus* status;
void turnOn(int led){

View File

@ -1,78 +1,2 @@
#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++);
}
};

View File

@ -4,13 +4,11 @@
const int DOOR_OPEN = HIGH;
const int DOOR_CLOSED = LOW;
struct AlarmStatus{
int doorStatus =DOOR_OPEN;
bool doorChanged =false;
bool isArmed = false;
bool isFired =false;
bool ledOn =true;
bool muted =false;
bool silent =false; //low sound
int doorStatus;
bool doorChanged;
bool isArmed;
bool isFired;
bool ledOn;
};
#endif

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -12,14 +12,11 @@ public:
static const int DEFAULT_DOOR_SENSOR_PIN=23;
DoorSensor(AlarmStatus* statusObj, int doorSensorPin){
DoorSensor(int doorSensorPin, AlarmStatus* statusObj){
Serial.println("const.");
DOOR_SENSOR_PIN = doorSensorPin;
status = statusObj;
}
DoorSensor(AlarmStatus* statusObj){
DOOR_SENSOR_PIN = DEFAULT_DOOR_SENSOR_PIN;
status = statusObj;
}
void Init(){
pinMode(DOOR_SENSOR_PIN, INPUT_PULLUP);
status->doorStatus = digitalRead(DOOR_SENSOR_PIN);

View File

@ -1,22 +1,17 @@
#include <Arduino.h>
#include "alarm.h"
#include "DoorSensor.h"
#include "doorSensor.h"
#include "LedController.h"
#include "Siren.h"
// #include <WiFi.h>
AlarmStatus s;
DoorSensor doorSensor(&s);
AlarmStatus s = {DOOR_OPEN, false, false, false, true};
DoorSensor doorSensor(DoorSensor::DEFAULT_DOOR_SENSOR_PIN, &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() {
@ -25,15 +20,16 @@ void setup() {
printStatus();
doorSensor.Init();
led.Init();
siren.Init();
printStatus();
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);
printStatus();
Serial.println("Stp Done");
}
@ -46,15 +42,10 @@ void loop() {
s.doorChanged=false;
if(s.isFired){
s.silent = !s.silent;
siren.SoundSiren();
}
led.Update();
// delay(1000);
delay(1000);
}
@ -69,7 +60,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;
}