8 static const char *
const TAG =
"rtttl";
10 static const uint32_t DOUBLE_NOTE_GAP_MS = 10;
13 static const uint16_t NOTES[] = {0, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
14 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047,
15 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217,
16 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951};
33 ESP_LOGE(TAG,
"Missing ':' when looking for name.");
38 ESP_LOGD(TAG,
"Playing song %s",
name.c_str());
42 if (position_ == std::string::npos) {
43 ESP_LOGE(TAG,
"Missing 'd='");
52 position_ =
rtttl_.find(
"o=", position_);
53 if (position_ == std::string::npos) {
54 ESP_LOGE(TAG,
"Missing 'o=");
59 if (num >= 3 && num <= 7)
63 position_ =
rtttl_.find(
"b=", position_);
64 if (position_ == std::string::npos) {
65 ESP_LOGE(TAG,
"Missing b=");
73 position_ =
rtttl_.find(
':', position_);
74 if (position_ == std::string::npos) {
75 ESP_LOGE(TAG,
"Missing second ':'");
94 ESP_LOGD(TAG,
"Playback finished");
101 while (
rtttl_[position_] ==
',' ||
rtttl_[position_] ==
' ')
115 switch (
rtttl_[position_]) {
144 if (
rtttl_[position_] ==
'#') {
150 if (
rtttl_[position_] ==
'.') {
162 auto note_index = (scale - 4) * 12 + note;
163 if (note_index < 0 || note_index >= (
int)
sizeof(NOTES)) {
164 ESP_LOGE(TAG,
"Note out of valid range");
167 auto freq = NOTES[note_index];
172 delay(DOUBLE_NOTE_GAP_MS);
177 ESP_LOGVV(TAG,
"playing note: %d for %dms", note,
note_duration_);
void play(std::string rtttl)
void dump_config() override
CallbackManager< void()> on_finished_playback_callback_
uint32_t IRAM_ATTR HOT millis()
void set_level(float state)
Set the level of this float output, this is called from the front-end.
uint16_t default_duration_
output::FloatOutput * output_
virtual void update_frequency(float frequency)
Set the frequency of the output for PWM outputs.
void IRAM_ATTR HOT delay(uint32_t ms)