Skip to content

Feature: Configurable interval for retriggerable long clicks#90

Closed
michpro wants to merge 1 commit intoLennartHennigs:masterfrom
michpro:FEATURE-retrigger_interval
Closed

Feature: Configurable interval for retriggerable long clicks#90
michpro wants to merge 1 commit intoLennartHennigs:masterfrom
michpro:FEATURE-retrigger_interval

Conversation

@michpro
Copy link

@michpro michpro commented Mar 9, 2026

Problem

Currently, when using setLongClickDetectedRetriggerable(true), the interval between consecutive long click events is strictly bound to the initial longclick_time_ms.

In many UX scenarios, users expect a longer initial threshold to prevent accidental triggers (e.g., hold for 3 seconds to start an action) but a much faster retrigger interval while the button is held down (e.g., continuous scrolling every 500ms).

Hardware Compatibility Issue (Capacitive Sensors): This strict coupling also creates issues with popular capacitive touch sensor modules like the TTP223. These chips automatically recalibrate after being touched continuously for about 16 seconds, effectively cutting off the signal even if the user is still touching the sensor. If a developer sets a long initial press time (e.g., 3-4 seconds) to avoid accidental triggers, they would only get 3 to 4 retrigger events before the hardware forcibly ends the press state.

Solution

This PR introduces the ability to decouple the initial long press detection time from the continuous retrigger interval. This solves the hardware limitation mentioned above, allowing developers to trigger multiple fast events within the sensor's physical 16-second active window, while maintaining a safe, long initial hold threshold.

  • Added longclick_interval_ms property.
  • Added setLongClickInterval(unsigned int ms) and getLongClickInterval().
  • Modified the threshold logic in _checkForLongClick() to calculate timing based on the new interval.

Backward Compatibility: 100% maintained. If setLongClickInterval() is not explicitly called, the algorithm automatically falls back to using longclick_time_ms as the interval, preserving the exact behavior of existing sketches.

Example

A new example sketch (LongpressRetriggerInterval.ino) has been added to demonstrate this behavior:

button.setLongClickTime(3000);                 // Wait 3 seconds for the first trigger
button.setLongClickDetectedRetriggerable(true);
button.setLongClickInterval(500);              // Subsequent triggers happen every 500ms, easily fitting within the TTP223 16s limit

@LennartHennigs
Copy link
Owner

Thanks for this PR! The sentinel-value approach here (longclick_interval_ms = 0 as "not set") and the correct unsigned long types made it into the final implementation.

I've opened #91 as a hybrid — it takes the cleaner implementation approach from this PR and combines it with the bundled API style from #86 (setLongClickDetectedRetriggerable(bool, unsigned int) overload instead of a separate setter). Would love your review if you have a moment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants