Implement touch disable/enable statemachine (#34)

* implemented a touch disable/enable statemachine

works as follows:
if touch is enabled, everything is processed
if touch is disabled, nothing is processed
when switching from disabled to enabled, and the display touched before, the TE_UP/TE_SLIDE_END ist ignored
when switching from enabled to disabled and the display is touched, the next TE_UP/TW_SLIDE_END will be processed, to leave nobody in a touch started but never ended state

* fix touch screen handling when staring touch while disabled and releasing touch when enabled

* touch on/off with backlight on/off is working

* setTouchEnable has to be #if defed for touch radios
This commit is contained in:
Malte Langermann
2021-11-15 21:07:56 +11:00
committed by GitHub
parent 40432653bd
commit 01f9e83117
2 changed files with 91 additions and 6 deletions
+71 -2
View File
@@ -39,15 +39,84 @@ void MainWindow::emptyTrash()
trash.clear();
}
#if defined(HARDWARE_TOUCH)
void MainWindow::setTouchEnabled(bool enable)
{
switch(touchEnableState)
{
case TouchOn:
if(!enable)
touchEnableState = TouchOff;
break;
case TouchOn_Touching:
if(!enable)
touchEnableState = TouchOnToOff_Touching;
break;
case TouchOnToOff_Touching:
if(enable)
touchEnableState = TouchOn_Touching;
break;
case TouchOff:
if(enable)
touchEnableState = TouchOn;
break;
case TouchOff_Touching:
if(enable)
touchEnableState = TouchOffToOn_Touching;
break;
case TouchOffToOn_Touching:
if(!enable)
touchEnableState = TouchOff_Touching;
break;
}
}
#endif
void MainWindow::checkEvents()
{
#if defined(HARDWARE_TOUCH)
if (touchPanelEventOccured()) {
touchPanelRead();
touchState = touchPanelRead();
} else {
touchState.event = TE_NONE;
}
if(!touchEnabled)
TouchEnableState currentState = touchEnableState;
switch(touchState.event)
{
case TE_DOWN:
case TE_SLIDE:
if(touchEnableState == TouchOn)
touchEnableState = TouchOn_Touching;
else if (touchEnableState == TouchOff)
touchEnableState = TouchOff_Touching;
break;
case TE_UP:
case TE_SLIDE_END:
if(touchEnableState == TouchOn_Touching)
touchEnableState = TouchOn;
else if (touchEnableState == TouchOff_Touching)
touchEnableState = TouchOff;
else if(touchEnableState == TouchOnToOff_Touching)
touchEnableState = TouchOff;
else if(touchEnableState == TouchOffToOn_Touching)
touchEnableState = TouchOn;
break;
default:
break;
}
if(touchState.event != TE_NONE)
_touchEventOccured = true;
if ( currentState == TouchOff
|| currentState == TouchOff_Touching
|| currentState == TouchOffToOn_Touching)
{
touchState.event = TE_NONE;
}
if (touchState.event == TE_DOWN) {
onTouchStart(touchState.x + scrollPositionX, touchState.y + scrollPositionY);
+20 -4
View File
@@ -65,9 +65,14 @@ class MainWindow: public Window
void checkEvents() override;
#if defined(HARDWARE_TOUCH)
void setTouchEnabled(bool enable)
{
touchEnabled = enable;
void setTouchEnabled(bool enable);
bool touchEventOccured() {
if(_touchEventOccured)
{
_touchEventOccured = false;
return true;
}
return false;
}
#endif
@@ -93,6 +98,17 @@ class MainWindow: public Window
rect_t invalidatedRect;
const char * shutdown = nullptr;
#if defined(HARDWARE_TOUCH)
bool touchEnabled = true;
bool lastTouchState = false;
bool _touchEventOccured = false;
enum TouchEnableState {
TouchOn,
TouchOn_Touching,
TouchOnToOff_Touching,
TouchOff,
TouchOff_Touching,
TouchOffToOn_Touching
};
TouchEnableState touchEnableState = TouchOn;
#endif
};