Skip to content

Commit

Permalink
feat(lua): deliver EVT_TOUCH_RELEASE event (#5587)
Browse files Browse the repository at this point in the history
  • Loading branch information
wimalopaan authored Oct 17, 2024
1 parent 1056ae2 commit 3c3a2df
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions radio/src/lua/lua_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void LuaEventHandler::event_cb(lv_event_t* e)
auto win = (Window*)lv_obj_get_user_data(obj);
if (!win) return;

lv_event_code_t code = lv_event_get_code(e);
const lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_KEY) {
uint32_t key = *(uint32_t*)lv_event_get_param(e);
if (key == LV_KEY_LEFT) {
Expand Down Expand Up @@ -90,9 +90,7 @@ void LuaEventHandler::event_cb(lv_event_t* e)

// If we already have a SLIDE going, then accumulate slide values instead
// of allocating an empty slot
LuaEventData* es = luaGetEventSlot(EVT_TOUCH_SLIDE);

if (es) {
if (LuaEventData* const es = luaGetEventSlot(EVT_TOUCH_SLIDE); es) {
es->event = EVT_TOUCH_SLIDE;
es->touchX = rel_pos.x;
es->touchY = rel_pos.y;
Expand All @@ -103,8 +101,7 @@ void LuaEventHandler::event_cb(lv_event_t* e)
TRACE("EVT_TOUCH_SLIDE [%d,%d]", rel_pos.x, rel_pos.y);
}
} else {
LuaEventData* es = luaGetEventSlot();
if (es) {
if (LuaEventData* const es = luaGetEventSlot(); es) {
es->event = EVT_TOUCH_FIRST;
es->touchX = rel_pos.x;
es->touchY = rel_pos.y;
Expand All @@ -117,6 +114,11 @@ void LuaEventHandler::event_cb(lv_event_t* e)
downTime = RTOS_GET_MS();
}
} else if (code == LV_EVENT_RELEASED) {
if (LuaEventData* const es = luaGetEventSlot(); es) {
es->event = EVT_TOUCH_BREAK;
TRACE("EVT_TOUCH_BREAK");
}

// tap count handling
uint32_t now = RTOS_GET_MS();
if (now - downTime <= LUA_TAP_TIME) {
Expand All @@ -142,19 +144,16 @@ void LuaEventHandler::onClicked()
lv_point_t point_act;
lv_indev_get_point(click_source, &point_act);

LuaEventData* es = luaGetEventSlot();
LuaEventData* const es = luaGetEventSlot();
if (!es) return;

if (tapCount > 0) {
es->event = EVT_TOUCH_TAP;
es->tapCount = tapCount;
} else {
es->event = EVT_TOUCH_BREAK;
es->touchX = point_act.x;
es->touchY = point_act.y;
}

es->touchX = point_act.x;
es->touchY = point_act.y;

_sliding = false;
return;
}
Expand Down

0 comments on commit 3c3a2df

Please sign in to comment.