Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions src/touch/gestures.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static void _reset_state(void)

/********************************** GESTURE DETECTION **********************************/

typedef bool (*gesture_detect_fn)(uint8_t location);

static bool _is_continuous_tap(uint8_t location)
{
return _state[location].max_slide_travel < TAP_SLIDE_TOLERANCE &&
Expand Down Expand Up @@ -192,55 +194,13 @@ static void _gesture_emit_event(uint8_t id, slider_location_t location)
emit_event(&event);
}

static void _emit_continuous_slide_event(void)
{
if (_is_continuous_slide(top_slider)) {
_gesture_emit_event(EVENT_SLIDE, top_slider);
}
if (_is_continuous_slide(bottom_slider)) {
_gesture_emit_event(EVENT_SLIDE, bottom_slider);
}
}

static void _emit_slide_release_event(void)
{
if (_is_slide_released(top_slider)) {
_gesture_emit_event(EVENT_SLIDE_RELEASED, top_slider);
}
if (_is_slide_released(bottom_slider)) {
_gesture_emit_event(EVENT_SLIDE_RELEASED, bottom_slider);
}
}

static void _emit_long_tap_event(void)
{
if (_is_long_tap_release(top_slider)) {
_gesture_emit_event(EVENT_LONG_TAP, top_slider);
}
if (_is_long_tap_release(bottom_slider)) {
_gesture_emit_event(EVENT_LONG_TAP, bottom_slider);
}
}

static void _emit_short_tap_event(void)
{
if (_is_tap_release(top_slider)) {
_gesture_emit_event(EVENT_SHORT_TAP, top_slider);
}
if (_is_tap_release(bottom_slider)) {
_gesture_emit_event(EVENT_SHORT_TAP, bottom_slider);
}
}

static void _emit_continuous_tap_event(void)
{
if (_is_continuous_tap(top_slider)) {
_gesture_emit_event(EVENT_CONTINUOUS_TAP, top_slider);
}
if (_is_continuous_tap(bottom_slider)) {
_gesture_emit_event(EVENT_CONTINUOUS_TAP, bottom_slider);
}
}
static gesture_detect_fn _emit_event_detect_fns[EVENT_ENUM_MAX] = {
[EVENT_SLIDE] = _is_continuous_slide,
[EVENT_SLIDE_RELEASED] = _is_slide_released,
[EVENT_CONTINUOUS_TAP] = _is_continuous_tap,
[EVENT_LONG_TAP] = _is_long_tap_release,
[EVENT_SHORT_TAP] = _is_tap_release,
};

/********************************** MEASURE, DETECT and CALLBACK **********************************/

Expand All @@ -263,11 +223,13 @@ static void _measure_and_emit(void)
}

if (gesture_detected) {
_emit_continuous_slide_event();
_emit_slide_release_event();
_emit_long_tap_event();
_emit_short_tap_event();
_emit_continuous_tap_event();
for (int location = 0; location < TOUCH_NUM_SLIDERS; location++) {
for (int event_idx = 0; event_idx < EVENT_ENUM_MAX; event_idx++) {
if (_emit_event_detect_fns[event_idx](location)) {
_gesture_emit_event(event_idx, location);
}
}
}
Comment on lines -266 to +232
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of events is changed. Could that have an impact somewhere?

}

bool both_sliders_released_or_inactive = true;
Expand Down
1 change: 1 addition & 0 deletions src/ui/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum {
EVENT_CONTINUOUS_TAP,
EVENT_LONG_TAP,
EVENT_SHORT_TAP,
EVENT_ENUM_MAX, // MAX must always be last, indicates the number of items in the enumration
};

typedef struct {
Expand Down