feat: melody assignment per channel/DM, dual ringtone slots, volume cleanup

Add second ringtone slot (ringtone2_*) to NodePrefs and DataStore.
Add per-channel and per-DM melody assignment (built-in / melody 1 / 2)
stored in NodePrefs bitmasks and DmMelodyEntry table.
Settings screen exposes DM/CH sound items; RingtoneEditorScreen supports
switching between slots. notify() uses buildMelodyFromPrefs() to select
the correct RTTTL string per contact.

Remove broken nRF52 volume control from buzzer.cpp: tone() uses
NRF_PWM2 with DECODER.MODE=Auto so TASKS_NEXTSTEP has no effect and
duty cannot be changed before the first DMA read without patching the
Arduino core. applyVolume() is now a no-op on nRF52.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-15 11:43:38 +02:00
parent 39731bb7fa
commit b3c6416874
6 changed files with 234 additions and 26 deletions

View File

@@ -32,11 +32,16 @@ bool genericBuzzer::isPlaying() {
}
void genericBuzzer::applyVolume() {
#if !defined(NRF52_PLATFORM)
// After tone() sets 50% duty, analogWrite overrides duty cycle on the same PWM channel.
// Level 4 = 50% (leave tone as-is), lower levels reduce duty = quieter output.
static const uint8_t duty[] = { 6, 20, 50, 90, 128 };
uint8_t d = duty[_volume_level < 5 ? _volume_level : 4];
if (d < 128) analogWrite(PIN_BUZZER, d);
#endif
// On nRF52, tone() uses NRF_PWM2 with DECODER.MODE=Auto. The DMA reads duty at SEQSTART
// before software can write, and TASKS_NEXTSTEP only works in NextStep mode — so duty
// cannot be changed mid-note without patching the Arduino core. Volume has no effect.
}
void genericBuzzer::setVolume(uint8_t level) {