From ced9df95102066f43f0ef53636433c4217ff6db1 Mon Sep 17 00:00:00 2001 From: gagarinlg Date: Sun, 31 Oct 2021 14:22:03 +0100 Subject: [PATCH] started implementing backlight tracking (unfinished) horus touch driver internally tracks touch state and returns the state on read to make in independed of the mainwindow touchState --- radio/src/main.cpp | 2 +- radio/src/targets/horus/board.cpp | 8 ++++ radio/src/targets/horus/board.h | 8 ++-- radio/src/targets/horus/tp_gt911.cpp | 56 ++++++++++++++-------------- radio/src/targets/horus/tp_gt911.h | 4 +- radio/src/touch.h | 7 ++-- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/radio/src/main.cpp b/radio/src/main.cpp index 280d857ee..e184cde8a 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -375,7 +375,7 @@ void guiMain(event_t evt) #endif #if defined(HARDWARE_TOUCH) MainWindow* mainWin = MainWindow::instance(); - mainWin->setTouchEnabled(!isFunctionActive(FUNCTION_DISABLE_TOUCH)); + mainWin->setTouchEnabled(!isFunctionActive(FUNCTION_DISABLE_TOUCH) && isBacklightEnabled()); #endif MainWindow::instance()->run(); diff --git a/radio/src/targets/horus/board.cpp b/radio/src/targets/horus/board.cpp index 036e943d8..1d30de74c 100644 --- a/radio/src/targets/horus/board.cpp +++ b/radio/src/targets/horus/board.cpp @@ -43,6 +43,7 @@ extern "C" { extern void flysky_hall_stick_init( void ); HardwareOptions hardwareOptions; +bool boardBacklightOn = false; void watchdogInit(unsigned int duration) { @@ -330,3 +331,10 @@ uint16_t getBatteryVoltage() int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose return (uint16_t)((instant_vbat * (1000 + g_eeGeneral.txVoltageCalibration)) / BATTERY_DIVIDER); } + +bool isBacklightEnabled() +{ + if(globalData.unexpectedShutdown) + return true; + return boardBacklightOn; +} diff --git a/radio/src/targets/horus/board.h b/radio/src/targets/horus/board.h index 5d7fc97ce..2b1c133ae 100644 --- a/radio/src/targets/horus/board.h +++ b/radio/src/targets/horus/board.h @@ -597,9 +597,11 @@ void backlightEnable(uint8_t dutyCycle = 0); #else #define BACKLIGHT_LEVEL_MIN 46 #endif -#define BACKLIGHT_ENABLE() backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : BACKLIGHT_LEVEL_MAX - currentBacklightBright) -#define BACKLIGHT_DISABLE() backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : ((g_eeGeneral.blOffBright == BACKLIGHT_LEVEL_MIN) && (g_eeGeneral.backlightMode != e_backlight_mode_off)) ? 0 : g_eeGeneral.blOffBright) -#define isBacklightEnabled() true + +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(); #if !defined(SIMU) void usbJoystickUpdate(); diff --git a/radio/src/targets/horus/tp_gt911.cpp b/radio/src/targets/horus/tp_gt911.cpp index b45c65a8c..1f0a439c1 100644 --- a/radio/src/targets/horus/tp_gt911.cpp +++ b/radio/src/targets/horus/tp_gt911.cpp @@ -22,7 +22,6 @@ #include "opentx.h" #include "i2c_driver.h" #include "tp_gt911.h" -#include "touch.h" #if defined (RADIO_T18) const uint8_t TOUCH_GT911_Cfg[] = { @@ -417,6 +416,8 @@ short tapCount = 0; I2C_HandleTypeDef hi2c1; +static TouchState internalTouchState ={}; + static void TOUCH_AF_ExtiStop(void) { SYSCFG_EXTILineConfig(TOUCH_INT_EXTI_PortSource, TOUCH_INT_EXTI_PinSource1); @@ -717,12 +718,12 @@ static const char* event2str(uint8_t ev) } #endif -void touchPanelRead() +struct TouchState touchPanelRead() { uint8_t state = 0; if (!touchEventOccured) - return; + return internalTouchState; touchEventOccured = false; @@ -734,7 +735,7 @@ void touchPanelRead() TRACE("GT911 I2C read XY error"); if (!I2C_ReInit()) TRACE("I2C B1 ReInit failed"); - return; + return internalTouchState; } if (state & 0x80u) { @@ -748,7 +749,7 @@ void touchPanelRead() if (state & 0x80u) { uint8_t pointsCount = (state & 0x0Fu); tmr10ms_t now = get_tmr10ms(); - touchState.tapCount = 0; + internalTouchState.tapCount = 0; if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) { if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data, @@ -758,40 +759,40 @@ void touchPanelRead() TRACE("GT911 I2C data read error"); if (!I2C_ReInit()) TRACE("I2C B1 ReInit failed"); - return; + return internalTouchState; } - if (touchState.event == TE_NONE || touchState.event == TE_UP || - touchState.event == TE_SLIDE_END) { - touchState.event = TE_DOWN; - touchState.startX = touchState.x = touchData.points[0].x; - touchState.startY = touchState.y = touchData.points[0].y; + if (internalTouchState.event == TE_NONE || internalTouchState.event == TE_UP || + internalTouchState.event == TE_SLIDE_END) { + internalTouchState.event = TE_DOWN; + internalTouchState.startX = internalTouchState.x = touchData.points[0].x; + internalTouchState.startY = internalTouchState.y = touchData.points[0].y; downTime = now; } else { - touchState.deltaX = touchData.points[0].x - touchState.x; - touchState.deltaY = touchData.points[0].y - touchState.y; - if (touchState.event == TE_SLIDE || - abs(touchState.deltaX) >= SLIDE_RANGE || - abs(touchState.deltaY) >= SLIDE_RANGE) { - touchState.event = TE_SLIDE; - touchState.x = touchData.points[0].x; - touchState.y = touchData.points[0].y; + internalTouchState.deltaX = touchData.points[0].x - internalTouchState.x; + internalTouchState.deltaY = touchData.points[0].y - internalTouchState.y; + if (internalTouchState.event == TE_SLIDE || + abs(internalTouchState.deltaX) >= SLIDE_RANGE || + abs(internalTouchState.deltaY) >= SLIDE_RANGE) { + internalTouchState.event = TE_SLIDE; + internalTouchState.x = touchData.points[0].x; + internalTouchState.y = touchData.points[0].y; } } } else { - if (touchState.event == TE_SLIDE) { - touchState.event = TE_SLIDE_END; - } else if (touchState.event == TE_DOWN) { - touchState.event = TE_UP; + if (internalTouchState.event == TE_SLIDE) { + internalTouchState.event = TE_SLIDE_END; + } else 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 if (touchState.event != TE_SLIDE_END) { - touchState.event = TE_NONE; + } else if (internalTouchState.event != TE_SLIDE_END) { + internalTouchState.event = TE_NONE; } } } @@ -802,7 +803,8 @@ void touchPanelRead() TRACE("GT911 ERROR: clearing XY register failed"); } - TRACE("touch event = %s", event2str(touchState.event)); + TRACE("touch event = %s", event2str(internalTouchState.event)); + return internalTouchState; } extern "C" void TOUCH_INT_EXTI_IRQHandler1(void) diff --git a/radio/src/targets/horus/tp_gt911.h b/radio/src/targets/horus/tp_gt911.h index fcf671245..239ea1277 100644 --- a/radio/src/targets/horus/tp_gt911.h +++ b/radio/src/targets/horus/tp_gt911.h @@ -21,6 +21,8 @@ #pragma once +#include "touch.h" + #define HAS_TOUCH_PANEL() touchGT911Flag == true extern bool touchGT911Flag; @@ -28,7 +30,7 @@ extern uint16_t touchGT911fwver; extern uint32_t touchGT911hiccups; extern bool touchPanelInit(); -void touchPanelRead(); +struct TouchState touchPanelRead(); bool touchPanelEventOccured(); #define GT911_TIMEOUT 3 // 3ms diff --git a/radio/src/touch.h b/radio/src/touch.h index 6e515810f..b04c796c5 100644 --- a/radio/src/touch.h +++ b/radio/src/touch.h @@ -45,8 +45,9 @@ struct TouchState short tapCount; }; -constexpr uint8_t SLIDE_RANGE = 6; -extern TouchState touchState; +#define SLIDE_RANGE 6 -#endif // _TOUCH_H_ \ No newline at end of file +extern struct TouchState touchState; + +#endif // _TOUCH_H_