AndreasStgm / ESP32_Notifier

ESP-NOW 2-way messenger
0 stars 0 forks source link

Central module sometimes gets stuck in "single send" mode #2

Open AndreasStgm opened 8 months ago

AndreasStgm commented 8 months ago

I think this is an issue with the button presses being handled incorrectly (their state not properly being reset). Because when it is stuck a press of the reset button does not fix it.

AndreasStgm commented 7 months ago

This was caused because the button was being released faster than the specified debounceTime. This caused the button to be stuck in the PRESSED state when it was actually RELEASED. Since the ISR is fired on a change of the input pin, the next edge that it would detect would be the rising edge of the next press of the button. It then immediately goes to the single mode because the time between the two presses was longer than the longPressTime. On the release of the button it then gets put back into the PRESSED mode again.

This is not properly fixed yet, but changes were made so that a press of the reset switch will also reset both button states back to RELEASED.

sendButtonState = ButtonState::RELEASED;

I think this issue can be fixed in multiple ways:

  1. Changing the handling of the edges from CHANGE to two different ISR's: one for the RISING and one for the FALLING edge. This makes it so the new rising edge can not be interpreted as a falling edge and the state can not be set to LONG_PRESSED incorrectly.
  2. By reworking the code so when holding a button a timer is started to automatically set the mode to LONG_PRESS when the specified time has passed instead of waiting for the user to release the button after a certain amount of time will probably also fix this issue, but this was not done originally because I could not find a timer library that worked the way I wanted and could work properly with ISR's.

Method 1 is probably an easier solution to fix it now, but method 2 should be implemented eventually to make it more user-friendly.