Skip to content

Commit

Permalink
Reset volume on boot
Browse files Browse the repository at this point in the history
Although the secondary microcontroller remembers the volume, it doesn't apply it on boot.
We therefore need to set it once we receive the response to the get_volume call we make on boot in order to avoid it defaulting to a setting which may not be what the user wants.
This also fixes the "first button press doesn't trigger chime" issue / closes #13.
  • Loading branch information
pauln committed Sep 23, 2020
1 parent 3dad5d9 commit 92d7df0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions linp-doorbell.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LinpDoorbell : public Component, CustomAPIDevice {
#ifdef LOG_SENSOR
bool isChiming = false;
#endif
bool hasSetVolume = false;

public:
#ifdef LOG_BINARY_SENSOR
Expand Down Expand Up @@ -77,6 +78,7 @@ class LinpDoorbell : public Component, CustomAPIDevice {

void setup() override {
Serial2.begin(115200);
hasSetVolume = false;
commandQueue.enqueue("down get_volume");
commandQueue.enqueue("down get_switch_list");

Expand Down Expand Up @@ -197,6 +199,15 @@ class LinpDoorbell : public Component, CustomAPIDevice {
ESP_LOGI("linp-doorbell", "Param received: %s = %s", param.c_str(), value.c_str());
#ifdef LOG_SENSOR
if (param.equals("volume")) {
if (!hasSetVolume) {
// Volume needs to be reset on boot to put it back to the last set value.
// This also jogs the doorbell to life so that it'll actually chime on first button press.
// If we don't do this, it won't chime on first press but will on subsequent presses.
int initialVolume = atoi(value.c_str());
ESP_LOGI("linp-doorbell", "Setting initial volume: %i", initialVolume);
hasSetVolume = true;
setVolume(initialVolume);
}
volume_sensor->publish_state(parse_float(value.c_str()).value());
} else if (param.equals("switch_list")) {
// Comma-separated list of button tunes.
Expand Down

0 comments on commit 92d7df0

Please sign in to comment.