Merge pull request #717 from EdgeTX/simu-mouse

Add touch support to simulation
This commit is contained in:
Raphael Coeffic
2021-09-13 15:28:06 +02:00
committed by GitHub
10 changed files with 274 additions and 172 deletions
@@ -299,6 +299,51 @@ void OpenTxSimulator::rotaryEncoderEvent(int steps)
#endif // defined(ROTARY_ENCODER_NAVIGATION)
}
void OpenTxSimulator::touchEvent(int type, int x, int y)
{
switch (type) {
case TouchDown:
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;
#endif
break;
case TouchUp:
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;
} else {
touchState.event = TE_SLIDE_END;
}
#endif
break;
case TouchSlide:
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;
}
#endif
break;
}
}
void OpenTxSimulator::setTrainerTimeout(uint16_t ms)
{
ppmInputValidityTimer = ms;
+7
View File
@@ -35,6 +35,12 @@ class DLLEXPORT OpenTxSimulator : public SimulatorInterface
public:
enum TouchEvent {
TouchUp=0,
TouchDown,
TouchSlide
};
OpenTxSimulator();
virtual ~OpenTxSimulator();
@@ -64,6 +70,7 @@ class DLLEXPORT OpenTxSimulator : public SimulatorInterface
virtual void setTrainerInput(unsigned int inputNumber, int16_t value);
virtual void setInputValue(int type, uint8_t index, int16_t value);
virtual void rotaryEncoderEvent(int steps);
virtual void touchEvent(int type, int x, int y);
virtual void setTrainerTimeout(uint16_t ms);
virtual void sendTelemetry(const QByteArray data);
virtual void setLuaStateReloadPermanentScripts();