Compare commits

..

No commits in common. "c40e22c81c39f506263d17b944a8a52c33633455" and "29b33da68a6bc545ae8c59ce8b518b0920ba039a" have entirely different histories.

4 changed files with 77 additions and 3682 deletions

View File

@ -1,96 +1,78 @@
#include <XT_DAC_Audio.h>
#include "alarm.h"
#include "Arduino.h"
#include "sound.h"
#include "soc/rtc_io_reg.h"
#include "alarmSound.h"
#include "silentSound.h"
// XT_Wav_Class SirenSound(sampleSound);
XT_Wav_Class SirenSound(alarmSound);
XT_Wav_Class SilentSound(silentSound);
XT_DAC_Audio_Class DacAudio(25, 0);
uint32_t DemoCounter=0;
class Siren
{
class Siren{
private:
int sirenPin = 25;
AlarmStatus* status;
float sinVal;
int toneVal;
void playSound(){
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...
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);
}
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...
noTone(sirenPin);
// buzzer->noTone();
// ledcWrite(sirenPin,0); // No sound
// ledcDetach(sirenPin);
}
public:
Siren(AlarmStatus *statusRef)
{
Siren(AlarmStatus* statusRef){
status=statusRef;
}
/**
* Only use DAC enabled pinout (25 or 26)
*/
Siren(AlarmStatus *statusRef, int pin)
{
Siren(AlarmStatus* statusRef, int pin){
status=statusRef;
DacAudio = XT_DAC_Audio_Class(pin, 0);
sirenPin=pin;
}
void Init()
{
void Init(){
// pinMode(sirenPin, OUTPUT);
// DacAudio = XT_DAC_Audio_Class(sirenPin, 0);
}
void SoundSiren()
{
void SoundSiren(){
if(status->muted)
return;
if(status->silent){
playSilentSound();
return;
}
playSound();
// 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++);
}
};
// 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);
// }

View File

@ -10,8 +10,7 @@ DoorSensor doorSensor(&s);
LedController led(&s);
Siren siren(&s);
void printStatus()
{
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");
@ -20,49 +19,47 @@ void printStatus()
msg = msg + " | Muted: " + String(s.muted ? "Muted": "Not Muted");
Serial.println(msg);
}
void setup()
{
void setup() {
Serial.begin(115200);
printStatus();
doorSensor.Init();
led.Init();
siren.Init();
s.silent = true;
s.isArmed = doorSensor.IsDoorClosed();
// Serial.println("Alarm is " + String(s.isArmed ? "Armed" : "Disarmed"));
// WiFi.mode(WIFI_STA);
// WiFi.disconnect();
// delay(100);
printStatus();
}
void loop()
{
void loop() {
doorSensor.HandleDoor();
if (s.doorChanged)
{
if(s.doorChanged){
DoorEvent();
}
s.doorChanged=false;
if (s.isFired)
{
if(s.isFired){
s.silent = !s.silent;
siren.SoundSiren();
}
led.Update();
// delay(1000);
}
void DoorEvent()
{
if (doorSensor.IsDoorOpen())
{
void DoorEvent(){
if(doorSensor.IsDoorOpen()){
Serial.println("The door-opening");
if(!s.isArmed)
{
@ -71,9 +68,7 @@ void DoorEvent()
}
Serial.println("Alarm is armed, firing");
s.isFired=true;
}
else
{
}else{
// delay(500);
Serial.println("The door-closing");
s.isArmed=true;

View File

@ -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);
}
}
}

File diff suppressed because it is too large Load Diff