touch on/off with backlight on/off is now working for TX16s, untested, but implemented for NV14

simulator for tX16s and NV14 works
This commit is contained in:
gagarinlg
2021-11-16 11:21:04 +10:00
committed by Peter Feerick
parent ced9df9510
commit 8360434516
8 changed files with 82 additions and 58 deletions
+3 -2
View File
@@ -540,8 +540,9 @@ void checkBacklight()
resetBacklightTimeout();
}
}
#if defined(HARDWARE_TOUCH) && defined(PCBNV14)
if (touchPanelEventOccured() && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) {
#if defined(HARDWARE_TOUCH) /*&& defined(PCBNV14)*/
if (MainWindow::instance()->touchEventOccured() && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) {
resetBacklightTimeout();
}
#endif
+6 -1
View File
@@ -597,11 +597,16 @@ void backlightEnable(uint8_t dutyCycle = 0);
#else
#define BACKLIGHT_LEVEL_MIN 46
#endif
#if defined(SIMU)
#define BACKLIGHT_ENABLE()
#define BACKLIGHT_DISABLE()
#define isBacklightEnabled(...) true
#else
extern bool boardBacklightOn;
#define BACKLIGHT_ENABLE() {boardBacklightOn = true; backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : BACKLIGHT_LEVEL_MAX - currentBacklightBright);}
#define BACKLIGHT_DISABLE() {boardBacklightOn = false; backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : ((g_eeGeneral.blOffBright == BACKLIGHT_LEVEL_MIN) && (g_eeGeneral.backlightMode != e_backlight_mode_off)) ? 0 : g_eeGeneral.blOffBright);}
bool isBacklightEnabled();
#endif
#if !defined(SIMU)
void usbJoystickUpdate();
+1 -5
View File
@@ -416,7 +416,7 @@ short tapCount = 0;
I2C_HandleTypeDef hi2c1;
static TouchState internalTouchState ={};
static TouchState internalTouchState = {};
static void TOUCH_AF_ExtiStop(void)
{
@@ -810,10 +810,6 @@ struct TouchState touchPanelRead()
extern "C" void TOUCH_INT_EXTI_IRQHandler1(void)
{
if (EXTI_GetITStatus(TOUCH_INT_EXTI_LINE1) != RESET) {
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
// on touch turn the light on
resetBacklightTimeout();
}
touchEventOccured = true;
EXTI_ClearITPendingBit(TOUCH_INT_EXTI_LINE1);
}
+1 -1
View File
@@ -553,6 +553,6 @@ extern AuxSerialRxFifo auxSerialRxFifo;
// Touch panel driver
bool touchPanelEventOccured();
void touchPanelRead();
struct TouchState touchPanelRead();
#endif // _BOARD_H_
+33 -30
View File
@@ -48,6 +48,8 @@ tmr10ms_t tapTime = 0;
short tapCount = 0;
#define TAP_TIME 25
static TouchState internalTouchState = {};
void I2C_FreeBus()
{
GPIO_InitTypeDef GPIO_InitStructure;
@@ -468,33 +470,33 @@ void handleTouch()
touchX = tmp;
#endif
if (tEvent == FT6206_TOUCH_EVT_FLAG_CONTACT) {
int dx = touchX - touchState.x;
int dy = touchY - touchState.y;
int dx = touchX - internalTouchState.x;
int dy = touchY - internalTouchState.y;
touchState.x = touchX;
touchState.y = touchY;
internalTouchState.x = touchX;
internalTouchState.y = touchY;
if (touchState.event == TE_NONE || touchState.event == TE_UP || touchState.event == TE_SLIDE_END) {
touchState.startX = touchState.x;
touchState.startY = touchState.y;
touchState.event = TE_DOWN;
if (internalTouchState.event == TE_NONE || internalTouchState.event == TE_UP || internalTouchState.event == TE_SLIDE_END) {
internalTouchState.startX = internalTouchState.x;
internalTouchState.startY = internalTouchState.y;
internalTouchState.event = TE_DOWN;
}
else if (touchState.event == TE_DOWN) {
else if (internalTouchState.event == TE_DOWN) {
if (dx >= SLIDE_RANGE || dx <= -SLIDE_RANGE || dy >= SLIDE_RANGE || dy <= -SLIDE_RANGE) {
touchState.event = TE_SLIDE;
touchState.deltaX = (short) dx;
touchState.deltaY = (short) dy;
internalTouchState.event = TE_SLIDE;
internalTouchState.deltaX = (short) dx;
internalTouchState.deltaY = (short) dy;
}
else {
touchState.event = TE_DOWN;
touchState.deltaX = 0;
touchState.deltaY = 0;
internalTouchState.event = TE_DOWN;
internalTouchState.deltaX = 0;
internalTouchState.deltaY = 0;
}
}
else if (touchState.event == TE_SLIDE) {
touchState.event = TE_SLIDE; //no change
touchState.deltaX = (short) dx;
touchState.deltaY = (short) dy;
else if (internalTouchState.event == TE_SLIDE) {
internalTouchState.event = TE_SLIDE; //no change
internalTouchState.deltaX = (short) dx;
internalTouchState.deltaY = (short) dy;
}
}
@@ -513,39 +515,40 @@ bool touchPanelEventOccured()
return touchEventOccured;
}
void touchPanelRead()
TouchState touchPanelRead()
{
if (!touchEventOccured) return;
if (!touchEventOccured) return internalTouchState;
touchEventOccured = false;
tmr10ms_t now = get_tmr10ms();
touchState.tapCount = 0;
internalTouchState.tapCount = 0;
if (ft6x06_TS_DetectTouch(TOUCH_FT6236_I2C_ADDRESS)) {
handleTouch();
if (touchState.event == TE_DOWN && downTime == 0) {
if (internalTouchState.event == TE_DOWN && downTime == 0) {
downTime = now;
}
} else {
if (touchState.event == TE_DOWN) {
touchState.event = TE_UP;
if (internalTouchState.event == TE_DOWN) {
internalTouchState.event = TE_UP;
if (now - downTime <= TAP_TIME) {
if (now - tapTime > TAP_TIME) {
tapCount = 1;
} else {
tapCount++;
}
touchState.tapCount = tapCount;
internalTouchState.tapCount = tapCount;
tapTime = now;
} else {
touchState.tapCount = 0; // not a tap
internalTouchState.tapCount = 0; // not a tap
}
downTime = 0;
} else {
touchState.x = LCD_WIDTH;
touchState.y = LCD_HEIGHT;
touchState.event = TE_SLIDE_END;
internalTouchState.x = LCD_WIDTH;
internalTouchState.y = LCD_HEIGHT;
internalTouchState.event = TE_SLIDE_END;
}
}
return internalTouchState;
}
+21 -18
View File
@@ -315,7 +315,7 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
{
#if defined(HARDWARE_TOUCH)
tmr10ms_t now = get_tmr10ms();
touchState.tapCount = 0;
simTouchState.tapCount = 0;
#endif
switch (type) {
@@ -323,9 +323,9 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
TRACE_WINDOWS("[Mouse Press] %d %d", x, y);
#if defined(HARDWARE_TOUCH)
touchState.event = TE_DOWN;
touchState.startX = touchState.x = x;
touchState.startY = touchState.y = y;
simTouchState.event = TE_DOWN;
simTouchState.startX = simTouchState.x = x;
simTouchState.startY = simTouchState.y = y;
downTime = now;
#endif
break;
@@ -334,20 +334,20 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
TRACE_WINDOWS("[Mouse Release] %d %d", x, y);
#if defined(HARDWARE_TOUCH)
if (touchState.event == TE_DOWN) {
touchState.event = TE_UP;
touchState.x = touchState.startX;
touchState.y = touchState.startY;
if (simTouchState.event == TE_DOWN) {
simTouchState.event = TE_UP;
simTouchState.x = simTouchState.startX;
simTouchState.y = simTouchState.startY;
if (now - downTime <= TAP_TIME) {
if (now - tapTime > TAP_TIME)
tapCount = 1;
else
tapCount++;
touchState.tapCount = tapCount;
simTouchState.tapCount = tapCount;
tapTime = now;
}
} else {
touchState.event = TE_SLIDE_END;
simTouchState.event = TE_SLIDE_END;
}
#endif
break;
@@ -356,18 +356,21 @@ void OpenTxSimulator::touchEvent(int type, int x, int y)
TRACE_WINDOWS("[Mouse Move] %d %d", x, y);
#if defined(HARDWARE_TOUCH)
touchState.deltaX += x - touchState.x;
touchState.deltaY += y - touchState.y;
if (touchState.event == TE_SLIDE ||
abs(touchState.deltaX) >= SLIDE_RANGE ||
abs(touchState.deltaY) >= SLIDE_RANGE) {
touchState.event = TE_SLIDE;
touchState.x = x;
touchState.y = y;
simTouchState.deltaX += x - simTouchState.x;
simTouchState.deltaY += y - simTouchState.y;
if (simTouchState.event == TE_SLIDE ||
abs(simTouchState.deltaX) >= SLIDE_RANGE ||
abs(simTouchState.deltaY) >= SLIDE_RANGE) {
simTouchState.event = TE_SLIDE;
simTouchState.x = x;
simTouchState.y = y;
}
#endif
break;
}
#if defined(HARDWARE_TOUCH)
simTouchOccured=true;
#endif
}
void OpenTxSimulator::setTrainerTimeout(uint16_t ms)
+12 -1
View File
@@ -894,11 +894,22 @@ void check_intmodule_heartbeat()
}
#endif
#if defined(HARDWARE_TOUCH)
struct TouchState simTouchState = {};
bool simTouchOccured = false;
bool touchPanelEventOccured()
{
if(simTouchOccured)
{
simTouchOccured = false;
return true;
}
return false;
}
void touchPanelRead()
struct TouchState touchPanelRead()
{
return simTouchState;
}
#endif
+5
View File
@@ -321,4 +321,9 @@ void simuMain();
#define TRACE_SIMPGMSPACE(...)
#endif
#if defined(HARDWARE_TOUCH)
extern struct TouchState simTouchState;
extern bool simTouchOccured;
#endif
#endif // _SIMPGMSPACE_H_