Merge pull request #703 from jfrickmann/DoubleTap

Double tap
This commit is contained in:
Peter Feerick
2021-09-11 11:28:07 +10:00
committed by GitHub
4 changed files with 40 additions and 13 deletions
+11 -4
View File
@@ -25,6 +25,10 @@
#include "view_main.h"
#include "lcd.h"
#if defined(HARDWARE_TOUCH)
#include "touch.h"
#endif
constexpr uint32_t WIDGET_FOCUS_TIMEOUT = 10*1000; // 10 seconds
constexpr uint32_t FULLSCREEN_HINT_DELAY = 5*1000; // 5 seconds
@@ -81,11 +85,14 @@ bool Widget::onTouchEnd(coord_t x, coord_t y)
}
if (hasFocus()) {
onPress();
return true;
if (touchState.tapCount == 0)
onPress();
else if (touchState.tapCount > 1)
setFullscreen(true);
}
else {
setFocus();
}
setFocus();
return true;
}
+13 -9
View File
@@ -33,6 +33,7 @@
#define EVENT_BUFFER_SIZE 2
#if defined(HARDWARE_TOUCH)
#include "touch.h"
#define EVT_TOUCH_TAP_TIME 25
#define EVT_TOUCH_SWIPE_LOCK 4
#define EVT_TOUCH_SWIPE_SPEED 60
@@ -235,6 +236,7 @@ struct eventData {
coord_t startY;
coord_t slideX;
coord_t slideY;
short tapCount;
#endif
};
@@ -287,7 +289,7 @@ class LuaWidget: public Widget
static eventData events[EVENT_BUFFER_SIZE];
#if defined(HARDWARE_TOUCH)
static tmr10ms_t lastTouchDown;
static bool fingerDown;
static tmr10ms_t swipeTimeOut;
#endif
@@ -301,7 +303,7 @@ class LuaWidget: public Widget
eventData LuaWidget::events[EVENT_BUFFER_SIZE] = { 0 };
#if defined(HARDWARE_TOUCH)
tmr10ms_t LuaWidget::lastTouchDown = 0;
bool LuaWidget::fingerDown = false;
tmr10ms_t LuaWidget::swipeTimeOut = 0;
#endif
@@ -481,6 +483,7 @@ void LuaWidget::refresh(BitmapBuffer* dc)
lua_newtable(lsWidgets);
l_pushtableint("x", es->touchX);
l_pushtableint("y", es->touchY);
l_pushtableint("tapCount", es->tapCount);
if (es->event == EVT_TOUCH_SLIDE) {
l_pushtableint("startX", es->startX);
@@ -577,9 +580,9 @@ bool LuaWidget::onTouchStart(coord_t x, coord_t y)
{
TRACE_WINDOWS("LuaWidget received touch start (%d) x=%d;y=%d", hasFocus(), x, y);
// Only one EVT_TOUCH_FIRST at a time, and also start timer for possible TAP
// Only one EVT_TOUCH_FIRST at a time
if (fullscreen) {
if (lastTouchDown == 0) {
if (!fingerDown) {
eventData* es = findOpenEventSlot();
if (es) {
@@ -588,7 +591,7 @@ bool LuaWidget::onTouchStart(coord_t x, coord_t y)
es->touchY = y;
}
lastTouchDown = get_tmr10ms();
fingerDown = true;
}
return true;
@@ -605,15 +608,16 @@ bool LuaWidget::onTouchEnd(coord_t x, coord_t y)
eventData* es = findOpenEventSlot();
if (es) {
if (get_tmr10ms() - lastTouchDown <= EVT_TOUCH_TAP_TIME)
if (touchState.tapCount > 0) {
es->event = EVT_TOUCH_TAP;
else
es->tapCount = touchState.tapCount;
} else
es->event = EVT_TOUCH_BREAK;
es->touchX = x;
es->touchY = y;
}
lastTouchDown = 0;
fingerDown = false;
return true;
}
@@ -637,7 +641,7 @@ bool LuaWidget::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t start
es->slideY += slideY;
}
lastTouchDown = 0;
fingerDown = false;
return true;
}
+15
View File
@@ -409,6 +409,10 @@ volatile static bool touchEventOccured = false;
struct TouchData touchData;
uint16_t touchGT911fwver = 0;
uint32_t touchGT911hiccups = 0;
tmr10ms_t downTime = 0;
tmr10ms_t tapTime = 0;
short tapCount = 0;
#define TAP_TIME 25
I2C_HandleTypeDef hi2c1;
@@ -742,6 +746,8 @@ void touchPanelRead()
TRACE("touch state = 0x%x", state);
if (state & 0x80u) {
uint8_t pointsCount = (state & 0x0Fu);
tmr10ms_t now = get_tmr10ms();
touchState.tapCount = 0;
if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) {
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data,
@@ -758,6 +764,7 @@ void touchPanelRead()
touchState.event = TE_DOWN;
touchState.startX = touchState.x = touchData.points[0].x;
touchState.startY = touchState.y = touchData.points[0].y;
downTime = now;
} else {
touchState.deltaX = touchData.points[0].x - touchState.x;
touchState.deltaY = touchData.points[0].y - touchState.y;
@@ -774,6 +781,14 @@ void touchPanelRead()
touchState.event = TE_SLIDE_END;
} else if (touchState.event == TE_DOWN) {
touchState.event = TE_UP;
if (now - downTime <= TAP_TIME) {
if (now - tapTime > TAP_TIME)
tapCount = 1;
else
tapCount++;
touchState.tapCount = tapCount;
tapTime = now;
}
} else if (touchState.event != TE_SLIDE_END) {
touchState.event = TE_NONE;
}
+1
View File
@@ -41,6 +41,7 @@ struct TouchState
short deltaY;
short lastDeltaX;
short lastDeltaY;
short tapCount;
};
constexpr uint8_t SLIDE_RANGE = 6;