Skip to content

Commit

Permalink
Add tap count support to simulator (#719)
Browse files Browse the repository at this point in the history
* Removed unused #define
* Added touchState.tapCount for double taps etc. to simulator
  • Loading branch information
jfrickmann authored Sep 14, 2021
1 parent cc0c530 commit 8d04b51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion radio/src/lua/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#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
#define EVT_TOUCH_SWIPE_TIMEOUT 50
Expand Down
17 changes: 17 additions & 0 deletions radio/src/targets/simu/opentxsimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
int16_t g_anas[Analogs::NUM_ANALOGS];
QVector<QIODevice *> OpenTxSimulator::tracebackDevices;

tmr10ms_t downTime = 0;
tmr10ms_t tapTime = 0;
short tapCount = 0;
#define TAP_TIME 25

uint16_t anaIn(uint8_t chan)
{
return g_anas[chan];
Expand Down Expand Up @@ -301,6 +306,9 @@ void OpenTxSimulator::rotaryEncoderEvent(int steps)

void OpenTxSimulator::touchEvent(int type, int x, int y)
{
tmr10ms_t now = get_tmr10ms();
touchState.tapCount = 0;

switch (type) {
case TouchDown:
TRACE_WINDOWS("[Mouse Press] %d %d", x, y);
Expand All @@ -309,6 +317,7 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
touchState.event = TE_DOWN;
touchState.startX = touchState.x = x;
touchState.startY = touchState.y = y;
downTime = now;
#endif
break;

Expand All @@ -320,6 +329,14 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
touchState.event = TE_UP;
touchState.x = touchState.startX;
touchState.y = touchState.startY;
if (now - downTime <= TAP_TIME) {
if (now - tapTime > TAP_TIME)
tapCount = 1;
else
tapCount++;
touchState.tapCount = tapCount;
tapTime = now;
}
} else {
touchState.event = TE_SLIDE_END;
}
Expand Down

0 comments on commit 8d04b51

Please sign in to comment.