mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00

Some checks are pending
CI / setup (check) (push) Waiting to run
CI / setup (esp32) (push) Waiting to run
CI / setup (esp32c3) (push) Waiting to run
CI / setup (esp32c6) (push) Waiting to run
CI / setup (esp32s3) (push) Waiting to run
CI / setup (nrf52840) (push) Waiting to run
CI / setup (rp2040) (push) Waiting to run
CI / setup (stm32) (push) Waiting to run
CI / check (push) Blocked by required conditions
CI / build-esp32 (push) Blocked by required conditions
CI / build-esp32-s3 (push) Blocked by required conditions
CI / build-esp32-c3 (push) Blocked by required conditions
CI / build-esp32-c6 (push) Blocked by required conditions
CI / build-nrf52 (push) Blocked by required conditions
CI / build-rpi2040 (push) Blocked by required conditions
CI / build-stm32 (push) Blocked by required conditions
CI / package-raspbian (push) Waiting to run
CI / package-raspbian-armv7l (push) Waiting to run
CI / package-native (push) Waiting to run
CI / after-checks (push) Blocked by required conditions
CI / gather-artifacts (esp32) (push) Blocked by required conditions
CI / gather-artifacts (esp32c3) (push) Blocked by required conditions
CI / gather-artifacts (esp32c6) (push) Blocked by required conditions
CI / gather-artifacts (esp32s3) (push) Blocked by required conditions
CI / gather-artifacts (nrf52840) (push) Blocked by required conditions
CI / gather-artifacts (rp2040) (push) Blocked by required conditions
CI / gather-artifacts (stm32) (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
CI / release-firmware (esp32) (push) Blocked by required conditions
CI / release-firmware (esp32c3) (push) Blocked by required conditions
CI / release-firmware (esp32c6) (push) Blocked by required conditions
CI / release-firmware (esp32s3) (push) Blocked by required conditions
CI / release-firmware (nrf52840) (push) Blocked by required conditions
CI / release-firmware (rp2040) (push) Blocked by required conditions
CI / release-firmware (stm32) (push) Blocked by required conditions
Flawfinder Scan / Flawfinder (push) Waiting to run
* Pass#2: Lots more savings in logs and string reduction surgery * Don't need Thread suffix either * Warn
78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
#pragma once
|
|
#include "PowerFSM.h"
|
|
#include "concurrency/OSThread.h"
|
|
#include "configuration.h"
|
|
#include "main.h"
|
|
#include "sleep.h"
|
|
|
|
#ifdef HAS_I2S
|
|
#include <AudioFileSourcePROGMEM.h>
|
|
#include <AudioGeneratorRTTTL.h>
|
|
#include <AudioOutputI2S.h>
|
|
#include <ESP8266SAM.h>
|
|
|
|
#define AUDIO_THREAD_INTERVAL_MS 100
|
|
|
|
class AudioThread : public concurrency::OSThread
|
|
{
|
|
public:
|
|
AudioThread() : OSThread("Audio") { initOutput(); }
|
|
|
|
void beginRttl(const void *data, uint32_t len)
|
|
{
|
|
setCPUFast(true);
|
|
rtttlFile = new AudioFileSourcePROGMEM(data, len);
|
|
i2sRtttl = new AudioGeneratorRTTTL();
|
|
i2sRtttl->begin(rtttlFile, audioOut);
|
|
}
|
|
|
|
bool isPlaying()
|
|
{
|
|
if (i2sRtttl != nullptr) {
|
|
return i2sRtttl->isRunning() && i2sRtttl->loop();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void stop()
|
|
{
|
|
if (i2sRtttl != nullptr) {
|
|
i2sRtttl->stop();
|
|
delete i2sRtttl;
|
|
i2sRtttl = nullptr;
|
|
}
|
|
if (rtttlFile != nullptr) {
|
|
delete rtttlFile;
|
|
rtttlFile = nullptr;
|
|
}
|
|
|
|
setCPUFast(false);
|
|
}
|
|
|
|
protected:
|
|
int32_t runOnce() override
|
|
{
|
|
canSleep = true; // Assume we should not keep the board awake
|
|
|
|
// if (i2sRtttl != nullptr && i2sRtttl->isRunning()) {
|
|
// i2sRtttl->loop();
|
|
// }
|
|
return AUDIO_THREAD_INTERVAL_MS;
|
|
}
|
|
|
|
private:
|
|
void initOutput()
|
|
{
|
|
audioOut = new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S);
|
|
audioOut->SetPinout(DAC_I2S_BCK, DAC_I2S_WS, DAC_I2S_DOUT);
|
|
audioOut->SetGain(0.2);
|
|
};
|
|
|
|
AudioGeneratorRTTTL *i2sRtttl = nullptr;
|
|
AudioOutputI2S *audioOut;
|
|
|
|
AudioFileSourcePROGMEM *rtttlFile;
|
|
};
|
|
|
|
#endif
|