Page 1 of 1

single iot-button with a range of long-hold intervals for different modes

Posted: Sat Feb 10, 2024 1:29 pm
by cmorgan
I have a use case but it isn't clear if this is something iot-button can accommodate directly.

What I'd like is to use long holds to enable selecting multiple actions on a single button.

For example if the user presses the button there is a beep, if they continue to hold for 5 seconds I'd like to beep and flash, holds for 10 seconds, two beeps and two flashes etc. If they release from t0 -> 4.99 seconds they get 'action 1', if they release from 5 seconds to 9.99s they get 'action 2', and from 10 seconds on if they release they get 'action 3'.

Is this possible by setting and adjusting the long hold duration after the long hold callback has expired?

I'm new to iot-button and its unclear whether I should try to assign multiple iot-button instances to the same gpio with different hold durations to implement this instead.

Re: single iot-button with a range of long-hold intervals for different modes

Posted: Mon Feb 12, 2024 1:39 am
by cmorgan
Ended up not being able to use espressif iot-button as I'm already using esp-idf-lib and that has a 'button' component as well. Apparently there isn't a way to disambiguate two components with the same name.

What I ended up doing is using esp-idf-lib's button module and wrapping it in a state machine, and using esp timers to handle the long press such that if I have a series of intervals like:

[1500][1500][2000]

This describes intervals from [0 to 1500ms][1500 to 3000ms][3000 to 5000ms].

Upon pressed I start an esp timer with the interval, when that expires I generate a 'long press' event with the interval index, index++, and start the timer for the next interval. Upon release the timer is stopped and a 'released' event with the interval index is generated.

This enables the user of the code to handle the transitions between intervals as well as take action when the release occurs during the particular interval.

Re: single iot-button with a range of long-hold intervals for different modes

Posted: Sat Feb 24, 2024 6:37 am
by ashelman-ec
I need similar functionality (distinguishing between press durations).

Espressif had a quite sophisticated "touchpad" component in esp-iot-solution v1.0 (see code). It was used to support the ESP32-Sense development board. It allows registration of multiple callbacks for presses of different durations. But touchpad seems to have been later removed: it is not on the master branch, and I haven't been able to find it being maintained elsewhere.

If anyone has info on using the "touchpad", I'd be interested!