Compare commits
No commits in common. "c40e22c81c39f506263d17b944a8a52c33633455" and "29b33da68a6bc545ae8c59ce8b518b0920ba039a" have entirely different histories.
c40e22c81c
...
29b33da68a
124
esp32/Siren.h
124
esp32/Siren.h
@ -1,96 +1,78 @@
|
|||||||
#include <XT_DAC_Audio.h>
|
#include <XT_DAC_Audio.h>
|
||||||
|
|
||||||
#include "alarm.h"
|
#include "alarm.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "sound.h"
|
||||||
#include "soc/rtc_io_reg.h"
|
#include "soc/rtc_io_reg.h"
|
||||||
#include "alarmSound.h"
|
#include "alarmSound.h"
|
||||||
#include "silentSound.h"
|
|
||||||
|
|
||||||
XT_Wav_Class SirenSound(alarmSound);
|
// XT_Wav_Class SirenSound(sampleSound);
|
||||||
XT_Wav_Class SilentSound(silentSound);
|
XT_Wav_Class SirenSound(alarmSound);
|
||||||
XT_DAC_Audio_Class DacAudio(25, 0);
|
XT_DAC_Audio_Class DacAudio(25, 0);
|
||||||
|
uint32_t DemoCounter=0;
|
||||||
|
|
||||||
class Siren
|
class Siren{
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
|
int sirenPin = 25;
|
||||||
AlarmStatus* status;
|
AlarmStatus* status;
|
||||||
|
float sinVal;
|
||||||
|
int toneVal;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void playSound(){
|
void playSound(){
|
||||||
DacAudio.FillBuffer(); // Fill the sound buffer with data
|
int max = 180;
|
||||||
if (SirenSound.Playing == false) // if not playing,
|
Serial.println("Sound on " + String(sirenPin));
|
||||||
DacAudio.Play(&SirenSound); // play it, this will cause it to repeat and repeat...
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSilentSound(){
|
|
||||||
DacAudio.FillBuffer(); // Fill the sound buffer with data
|
|
||||||
if (SilentSound.Playing == false) // if not playing,
|
|
||||||
DacAudio.Play(&SilentSound); // play it, this will cause it to repeat and repeat...
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Siren(AlarmStatus *statusRef)
|
Siren(AlarmStatus* statusRef){
|
||||||
{
|
status=statusRef;
|
||||||
status = statusRef;
|
}
|
||||||
|
|
||||||
|
Siren(AlarmStatus* statusRef, int pin){
|
||||||
|
status=statusRef;
|
||||||
|
sirenPin=pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Only use DAC enabled pinout (25 or 26)
|
void Init(){
|
||||||
*/
|
// pinMode(sirenPin, OUTPUT);
|
||||||
Siren(AlarmStatus *statusRef, int pin)
|
// DacAudio = XT_DAC_Audio_Class(sirenPin, 0);
|
||||||
{
|
|
||||||
status = statusRef;
|
|
||||||
DacAudio = XT_DAC_Audio_Class(pin, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Init()
|
void SoundSiren(){
|
||||||
{
|
if(status->muted)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SoundSiren()
|
|
||||||
{
|
|
||||||
if (status->muted)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(status->silent){
|
// playSound();
|
||||||
playSilentSound();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
playSound();
|
|
||||||
// delay(500);
|
// 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++);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
};
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
// }
|
|
@ -10,72 +10,67 @@ DoorSensor doorSensor(&s);
|
|||||||
LedController led(&s);
|
LedController led(&s);
|
||||||
Siren siren(&s);
|
Siren siren(&s);
|
||||||
|
|
||||||
void printStatus()
|
void printStatus(){
|
||||||
{
|
|
||||||
String msg = String("Door: ") + String(doorSensor.IsDoorOpen() ? "Open" : "Closed");
|
String msg = String("Door: ") + String(doorSensor.IsDoorOpen() ? "Open" : "Closed");
|
||||||
msg = msg + " | Alarm: " + String(s.isArmed ? "Armed" : "Disarmed");
|
msg = msg + " | Alarm: " + String(s.isArmed ? "Armed": "Disarmed");
|
||||||
msg = msg + " | Is Fired: " + String(s.isFired ? "Fired" : "Not Fired");
|
msg = msg + " | Is Fired: " + String(s.isFired ? "Fired": "Not Fired");
|
||||||
msg = msg + " | Led: " + String(s.ledOn ? "On" : "Off");
|
msg = msg + " | Led: " + String(s.ledOn ? "On": "Off");
|
||||||
msg = msg + " | Silent: " + String(s.silent ? "Silent" : "Loud");
|
msg = msg + " | Silent: " + String(s.silent ? "Silent": "Loud");
|
||||||
msg = msg + " | Muted: " + String(s.muted ? "Muted" : "Not Muted");
|
msg = msg + " | Muted: " + String(s.muted ? "Muted": "Not Muted");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
}
|
}
|
||||||
|
void setup() {
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
printStatus();
|
||||||
doorSensor.Init();
|
doorSensor.Init();
|
||||||
led.Init();
|
led.Init();
|
||||||
siren.Init();
|
siren.Init();
|
||||||
|
|
||||||
s.silent = true;
|
|
||||||
s.isArmed = doorSensor.IsDoorClosed();
|
s.isArmed = doorSensor.IsDoorClosed();
|
||||||
|
// Serial.println("Alarm is " + String(s.isArmed ? "Armed" : "Disarmed"));
|
||||||
// WiFi.mode(WIFI_STA);
|
// WiFi.mode(WIFI_STA);
|
||||||
// WiFi.disconnect();
|
// WiFi.disconnect();
|
||||||
// delay(100);
|
// delay(100);
|
||||||
|
|
||||||
printStatus();
|
printStatus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
|
||||||
doorSensor.HandleDoor();
|
doorSensor.HandleDoor();
|
||||||
|
|
||||||
if (s.doorChanged)
|
if(s.doorChanged){
|
||||||
{
|
|
||||||
DoorEvent();
|
DoorEvent();
|
||||||
}
|
}
|
||||||
s.doorChanged = false;
|
s.doorChanged=false;
|
||||||
|
|
||||||
if (s.isFired)
|
|
||||||
{
|
if(s.isFired){
|
||||||
|
s.silent = !s.silent;
|
||||||
siren.SoundSiren();
|
siren.SoundSiren();
|
||||||
}
|
}
|
||||||
|
|
||||||
led.Update();
|
led.Update();
|
||||||
|
|
||||||
|
|
||||||
// delay(1000);
|
// delay(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoorEvent()
|
void DoorEvent(){
|
||||||
{
|
if(doorSensor.IsDoorOpen()){
|
||||||
if (doorSensor.IsDoorOpen())
|
|
||||||
{
|
|
||||||
Serial.println("The door-opening");
|
Serial.println("The door-opening");
|
||||||
if (!s.isArmed)
|
if(!s.isArmed)
|
||||||
{
|
{
|
||||||
Serial.println("Alarm is dissarmed, not fireing");
|
Serial.println("Alarm is dissarmed, not fireing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("Alarm is armed, firing");
|
Serial.println("Alarm is armed, firing");
|
||||||
s.isFired = true;
|
s.isFired=true;
|
||||||
}
|
}else{
|
||||||
else
|
|
||||||
{
|
|
||||||
// delay(500);
|
// delay(500);
|
||||||
Serial.println("The door-closing");
|
Serial.println("The door-closing");
|
||||||
s.isArmed = true;
|
s.isArmed=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
TaskHandle_t Task1;
|
|
||||||
TaskHandle_t Task2;
|
|
||||||
const int led1 = 2;
|
|
||||||
const int led2 = 4;
|
|
||||||
|
|
||||||
void stp(){
|
|
||||||
pinMode(led1, OUTPUT);
|
|
||||||
pinMode(led2, OUTPUT);
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
|
||||||
Task1code, /* Task function. */
|
|
||||||
"Task1", /* name of task. */
|
|
||||||
10000, /* Stack size of task */
|
|
||||||
NULL, /* parameter of the task */
|
|
||||||
1, /* priority of the task */
|
|
||||||
&Task1, /* Task handle to keep track of created task */
|
|
||||||
0); /* pin task to core 0 */
|
|
||||||
// xTaskCreate(Task1code, "task1", 1000, NULL, 1, NULL);
|
|
||||||
delay(500);
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
|
||||||
Task2code, /* Task function. */
|
|
||||||
"Task2", /* name of task. */
|
|
||||||
10000, /* Stack size of task */
|
|
||||||
NULL, /* parameter of the task */
|
|
||||||
1, /* priority of the task */
|
|
||||||
&Task2, /* Task handle to keep track of created task */
|
|
||||||
1); /* pin task to core 1 */
|
|
||||||
// xTaskCreate(Task2code, "task2", 1000, NULL, 1, NULL);
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Task1code: blinks an LED every 1000 ms
|
|
||||||
void Task1code( void * pvParameters ){
|
|
||||||
Serial.print("Task1 running on core ");
|
|
||||||
Serial.println(xPortGetCoreID());
|
|
||||||
|
|
||||||
for(;;){
|
|
||||||
digitalWrite(led1, HIGH);
|
|
||||||
delay(1000);
|
|
||||||
digitalWrite(led1, LOW);
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Task2code: blinks an LED every 700 ms
|
|
||||||
void Task2code( void * pvParameters ){
|
|
||||||
Serial.print("Task2 running on core ");
|
|
||||||
Serial.println(xPortGetCoreID());
|
|
||||||
|
|
||||||
for(;;){
|
|
||||||
digitalWrite(led2, HIGH);
|
|
||||||
delay(700);
|
|
||||||
if(!s.isFired){
|
|
||||||
digitalWrite(led2, LOW);
|
|
||||||
delay(700);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void killOne(){
|
|
||||||
// Kill task1 if it's running
|
|
||||||
if(Task1 != NULL) {
|
|
||||||
eTaskState taskState= eTaskGetState(Task1 );
|
|
||||||
if(taskState == eDeleted){
|
|
||||||
Serial.println("Task deleted");
|
|
||||||
}else{
|
|
||||||
Serial.println("No more green");
|
|
||||||
vTaskDelete(Task1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
3506
esp32/silentSound.h
3506
esp32/silentSound.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user