2025-04-13 22:53:18 -03:00
|
|
|
#include <XT_DAC_Audio.h>
|
|
|
|
|
2025-04-13 14:59:01 -03:00
|
|
|
#include "alarm.h"
|
2025-04-13 22:53:18 -03:00
|
|
|
#include "soc/rtc_io_reg.h"
|
|
|
|
#include "alarmSound.h"
|
2025-04-14 11:19:55 -03:00
|
|
|
#include "silentSound.h"
|
2025-04-13 22:53:18 -03:00
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
XT_Wav_Class SirenSound(alarmSound);
|
|
|
|
XT_Wav_Class SilentSound(silentSound);
|
2025-04-13 22:53:18 -03:00
|
|
|
XT_DAC_Audio_Class DacAudio(25, 0);
|
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
class Siren
|
|
|
|
{
|
2025-04-13 22:53:18 -03:00
|
|
|
private:
|
|
|
|
AlarmStatus* status;
|
|
|
|
|
|
|
|
|
|
|
|
void playSound(){
|
2025-04-14 11:19:55 -03:00
|
|
|
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...
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
2025-04-13 22:53:18 -03:00
|
|
|
}
|
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
|
|
|
|
|
2025-04-13 22:53:18 -03:00
|
|
|
public:
|
2025-04-14 11:19:55 -03:00
|
|
|
Siren(AlarmStatus *statusRef)
|
|
|
|
{
|
|
|
|
status = statusRef;
|
2025-04-13 22:53:18 -03:00
|
|
|
}
|
2025-04-14 11:19:55 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Only use DAC enabled pinout (25 or 26)
|
|
|
|
*/
|
|
|
|
Siren(AlarmStatus *statusRef, int pin)
|
|
|
|
{
|
|
|
|
status = statusRef;
|
|
|
|
DacAudio = XT_DAC_Audio_Class(pin, 0);
|
2025-04-13 22:53:18 -03:00
|
|
|
}
|
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
void Init()
|
|
|
|
{
|
2025-04-13 22:53:18 -03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
void SoundSiren()
|
|
|
|
{
|
|
|
|
if (status->muted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(status->silent){
|
|
|
|
playSilentSound();
|
2025-04-13 22:53:18 -03:00
|
|
|
return;
|
2025-04-14 11:19:55 -03:00
|
|
|
}
|
2025-04-13 22:53:18 -03:00
|
|
|
|
2025-04-14 11:19:55 -03:00
|
|
|
playSound();
|
2025-04-13 22:53:18 -03:00
|
|
|
// delay(500);
|
2025-04-13 14:59:01 -03:00
|
|
|
|
2025-04-13 22:53:18 -03:00
|
|
|
}
|
2025-04-14 11:19:55 -03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
// }
|