LennartHennigs / Button2

Arduino/ESP button library that provides callback functions to track single, double, triple and long clicks. It also takes care of debouncing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with longpress behavior

juiplus opened this issue · comments

commented

I have tested the MultiHandler.ino example on an ESP8266.
In principle it works, only the behavior with a long click does not work as expected. If a long click (handler setLongClickDetectedHandler() used) is executed after a single click or double click, the old state is always output first, e.g. click(1) or click(2). Only when a long click is executed again is it recognized as longclick correctly.

Serial output:
Multi Handler Demo
click (1)
click (1) <-click loong, but click(1) will be recognized wrongly!?
longclick (1) <- that is correct

Please try to reproduce it, maybe there is a simple workaround.

commented

I have now been able to fix the problem. Before calling the callback routine longclick_detected_cb(), the last_click_type must also be set to long_click. Then everything works as expected:

void Button2::_checkForLongClick(long now){
..
  last_click_type = long_click; // <- added
  longclick_detected_cb(*this);
  longclick_detected = true;
}

Would be nice if you could adopt this.
Thanks and greetings
Jui

Hey Jui,
Thanks for reaching out.
I will definitely check it out.

Hey @juiplus,
you were right. Click count was also off. Updated the library.
Thanks again!