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
This commit is contained in:
gagarinlg
2021-11-16 11:21:04 +10:00
committed by Peter Feerick
parent 52013da098
commit ced9df9510
6 changed files with 50 additions and 35 deletions
+1 -1
View File
@@ -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();
+8
View File
@@ -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;
}
+5 -3
View File
@@ -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();
+29 -27
View File
@@ -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)
+3 -1
View File
@@ -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
+4 -3
View File
@@ -45,8 +45,9 @@ struct TouchState
short tapCount;
};
constexpr uint8_t SLIDE_RANGE = 6;
extern TouchState touchState;
#define SLIDE_RANGE 6
#endif // _TOUCH_H_
extern struct TouchState touchState;
#endif // _TOUCH_H_