Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LongClickDetectedHandler triggered after boot? #46

Closed
LennartHennigs opened this issue Nov 1, 2022 · 8 comments
Closed

LongClickDetectedHandler triggered after boot? #46

LennartHennigs opened this issue Nov 1, 2022 · 8 comments
Labels

Comments

@LennartHennigs
Copy link
Owner

LennartHennigs commented Nov 1, 2022

I tried to replace the setLongClickHandler(handler) ...which works fine (but you don't know if your press was long enough until you release the button), by setLongClickDetectedHandler(handler) and I noticed a side effect.
Look at the log below and my comments in bold.

And this side effect is consistent. You might want to look into it...

--- Terminal on /dev/ttyACM0 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default,
direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H

Starting MMT Power Supply Interface !!!

PG set to PG40
EEPROM Beginning : 0
EEPROM End : 16384
System Voltage Set Value : 10.000
Corresponding DAC Voltage Output : 1.65
Corresponding DAC Binary Voltage Output : 2047
System Current Set Value : 0.500
Corresponding DAC Current Output : 0.82
Corresponding DAC Binary Current Output : 1023
System Input Voltage        : 4.7820001
Output Voltage              : 7.4822955
System Output Current       : 0.0019200
Z Output                    : 3897.03
System Power W              : 0.0090394


(1)** <------------------------------------------------------------- this was a long click (not ok) ... it happens only once after boot-up, as if no case in the function (see function below) was satisfied.***
---long click (1)
**<------------------------------------------------------------- this was a long click  (ok)**
ENTERING SELECTION MODE NORMAL OPERATION

---long click (1)
**<------------------------------------------------------------- this was a long click  (ok)**
Getting out of the Parameter Selection function

ENTERING MODIFICATION MODE

---long click (1)
**<------------------------------------------------------------- this was a long click  (ok)**
System Voltage Set Value : 10.000
Corresponding DAC Voltage Output : 1.65
Corresponding DAC Binary Voltage Output : 2047
Getting out of the Parameter Modificaton function

---double click (2)
**<------------------------------------------------------------- this was a long click  (ok)**
ENTERING PRESET SELECTION MODE

----Set pointer to the selected window
Set Coordinates To Preset Window
SetCoordinatesToPresetWindow preset3V3
*****Highlight Preset Window
*****Initialize Preset Window
CW Direction -- Encoder Value : 1
*******1----Set pointer to the selected window
++++Give Preset Colors To Window : preset5V0
Set Coordinates To Preset Window
SetCoordinatesToPresetWindow preset5V0
*****Highlight Preset Window
*****Initialize Preset Window
---double click (1)
**<------------------------------------------------------------- this was a long click (not ok) ... it appens consistently.**
---long click (1)
**<------------------------------------------------------------- this was a long click  (ok)**
Preset Value Selected saved to EEPROM
System Voltage Set : 5.000
System Current Set : 0.500
System Input Voltage        : 4.7900000
Output Voltage              : 7.4725275
System Output Current       : 0.0019200
Z Output                    : 3891.94
System Power W              : 0.0095182
/*************************************************************************************************************************/
/* BUTTON SWITCH HANDLER SECTION */
/*************************************************************************************************************************/

void handler(Button2& btn) {
  switch (btn.getType()) {
    case long_click:
      myButtonState = ds.ButtonState::longClick;
      Serial.print("---long click ");
      //Serial.print(bf.buttonStatus.buttonState); Serial.print("\t");
    break;
  
    case double_click:
      myButtonState = ds.ButtonState::doubleclick;
      Serial.print("---double click ");
      //Serial.print(bf.buttonStatus.buttonState); Serial.print("\t");
    break;

    case triple_click:
      myButtonState = ds.ButtonState::tripleClick;
      Serial.print("---triple click");
      //Serial.print(bf.buttonStatus.buttonState); Serial.print("\t");
    break;
  
  case single_click:
    myButtonState = ds.ButtonState::click;
    Serial.print("---single click");
    //Serial.print(bf.buttonStatus.buttonState); Serial.print("\t");
  break;
  }

  Serial.print(" (");
  Serial.print(btn.getNumberOfClicks());
  Serial.println(")");
}
void FunctionProcessing::buttonSetup() {
  button.begin(ENCODER_SWITCH_PORT,INPUT_PULLUP,false,true); // byte
attachTo, byte buttonMode /* = INPUT_PULLUP */, boolean isCapacitive /* =
false */, boolean activeLow /* = true */

  button.setDebounceTime(50); //
  button.setLongClickTime(500);
  button.setDoubleClickTime(700);

  button.setClickHandler(handler);
  button.setLongClickDetectedHandler(handler); //setLongClickHandler(handler);
  button.setDoubleClickHandler(handler);
  button.setTripleClickHandler(handler);
}

Regards,
Rene-Jean

Originally posted by @renejeanmercier in #43 (comment)

@LennartHennigs
Copy link
Owner Author

Hey @renejeanmercier,

I had a hard time replicating your issue but I did refactor the main loop() and fixed another bug with the LongPress handling.

Please check out 2.2.0 and let me know if your error still persists.

Cheers
l.

@renejeanmercier
Copy link

renejeanmercier commented Dec 14, 2022 via email

@LennartHennigs
Copy link
Owner Author

LennartHennigs commented Dec 16, 2022

Hey @renejeanmercier,
now I think I understood the problem and was able to reproduce it.
Please try out 2.2.1.

I no longer (wrongly) dectect the second or third click of a multi click event as a long click.
And I always reset the long click detection, after any other click type is reported.

And also all the best to you and your family and very happy holidays.
And: happy tinkering!
Cheers
l.

@renejeanmercier
Copy link

renejeanmercier commented Dec 16, 2022 via email

@LennartHennigs
Copy link
Owner Author

Hey, I gave it another shot.
Fingers crossed, now, @renejeanmercier!

@renejeanmercier
Copy link

renejeanmercier commented Dec 16, 2022 via email

@LennartHennigs
Copy link
Owner Author

LennartHennigs commented Dec 17, 2022

Hey @renejeanmercier,

thank you!
You are very welcome.
It helped a lot that I refactored the loop code last week.
It was now "merely" a matter of reading the code and looking for the proper place to change things.
And in 2.2.1 I had my counts off – thinking helps in many instances ;-).

And thank you again for pointing out the bug and your persistence as well.
I will gladly close this bug for good.
Have happy holidays and feel free to let me know how your project is going.
All the best!

@renejeanmercier
Copy link

renejeanmercier commented Dec 17, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants