Skip to content

Commit

Permalink
Be a bit smarter about when to turn on/off.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjansen committed Dec 26, 2024
1 parent 9e8f716 commit 5bdf660
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/iotsaInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,26 @@ void CyclingButton::loop() {
}

bool CyclingButton::_pressedCallback() {
IotsaSerial.printf("CyclingButton callback for pressed %d repeat %d, state=%d\n", button.pressed, button.repeatCount, state);
if (button.pressed) {
// The button was pressed. We ignore the first press.
// We ignore the first press. We take action on repeat (turn on and increase level)
// or release (toggle on/off).
if (button.repeatCount == 0) return true;
// The button was pressed. We turn on the light if it was off.
if (!state) {
state = true;
if (stateVar) *stateVar = state;
if (stateCallback) stateCallback();
}
if (_changeValue(direction)) {
IotsaSerial.printf("CyclingButton reached limit, now dir=%d", direction);
direction = -direction;
}
} else {
// The button was released. If this was a short press we toggle on/off.
if (button.repeatCount == 0) {
state = !state;
IotsaSerial.printf("CyclingButton state=%d\n", state);
if (stateVar) *stateVar = state;
if (stateCallback) stateCallback();
}
Expand Down

0 comments on commit 5bdf660

Please sign in to comment.