Fix joystick work in simulation

Logic was broken as joystickGet never got called
This commit is contained in:
Oleg Kalachev 2024-12-27 15:34:33 +03:00
parent 2440c65c46
commit 43be27c43d
2 changed files with 7 additions and 8 deletions

View File

@ -14,7 +14,7 @@ public:
SBUS(HardwareSerial& bus, const bool inv = true) {};
SBUS(HardwareSerial& bus, const int8_t rxpin, const int8_t txpin, const bool inv = true) {};
void begin() {};
bool read() { return joystickInitialized; };
bool read() { return joystickInit(); };
SBUSData data() {
SBUSData data;
joystickGet(data.ch);

View File

@ -15,9 +15,12 @@
#define RC_CHANNEL_MODE 4
SDL_Joystick *joystick;
bool joystickInitialized = false, warnShown = false;
void joystickInit() {
bool joystickInit() {
static bool joystickInitialized = false;
static bool warnShown = false;
if (joystickInitialized) return true;
SDL_Init(SDL_INIT_JOYSTICK);
joystick = SDL_JoystickOpen(0);
if (joystick != NULL) {
@ -27,14 +30,10 @@ void joystickInit() {
gzwarn << "Joystick not found, begin waiting for joystick..." << std::endl;
warnShown = true;
}
return joystickInitialized;
}
bool joystickGet(int16_t ch[16]) {
if (!joystickInitialized) {
joystickInit();
return false;
}
SDL_JoystickUpdate();
for (uint8_t i = 0; i < sizeof(channels) / sizeof(channels[0]); i++) {