mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-27 07:18:11 +00:00
Settings: add buzzer volume control (5 levels, like brightness)
- NodePrefs: add buzzer_volume field (0=min..4=max, default 4) - DataStore: persist buzzer_volume at end of prefs file (backward-compat) - buzzer: setVolume()/getVolume(); applyVolume() sets PWM duty cycle via analogWrite() after each rtttl::play() call to control output amplitude - Settings UI: new BzrVol bar item in Sound section (left/right to adjust) - UITask: apply saved volume on startup alongside brightness Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,8 +31,24 @@ bool genericBuzzer::isPlaying() {
|
||||
return rtttl::isPlaying();
|
||||
}
|
||||
|
||||
void genericBuzzer::applyVolume() {
|
||||
// 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);
|
||||
}
|
||||
|
||||
void genericBuzzer::setVolume(uint8_t level) {
|
||||
_volume_level = level < 5 ? level : 4;
|
||||
if (isPlaying()) applyVolume();
|
||||
}
|
||||
|
||||
void genericBuzzer::loop() {
|
||||
if (!rtttl::done()) rtttl::play();
|
||||
if (!rtttl::done()) {
|
||||
rtttl::play();
|
||||
if (_volume_level < 4) applyVolume();
|
||||
}
|
||||
}
|
||||
|
||||
void genericBuzzer::startup() {
|
||||
|
||||
Reference in New Issue
Block a user