mirror of
https://github.com/okalachev/flix.git
synced 2025-07-29 04:19:00 +00:00
Fix joystick work in simulation
Logic was broken as joystickGet never got called
This commit is contained in:
parent
2440c65c46
commit
43be27c43d
@ -14,7 +14,7 @@ public:
|
|||||||
SBUS(HardwareSerial& bus, const bool inv = true) {};
|
SBUS(HardwareSerial& bus, const bool inv = true) {};
|
||||||
SBUS(HardwareSerial& bus, const int8_t rxpin, const int8_t txpin, const bool inv = true) {};
|
SBUS(HardwareSerial& bus, const int8_t rxpin, const int8_t txpin, const bool inv = true) {};
|
||||||
void begin() {};
|
void begin() {};
|
||||||
bool read() { return joystickInitialized; };
|
bool read() { return joystickInit(); };
|
||||||
SBUSData data() {
|
SBUSData data() {
|
||||||
SBUSData data;
|
SBUSData data;
|
||||||
joystickGet(data.ch);
|
joystickGet(data.ch);
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
#define RC_CHANNEL_MODE 4
|
#define RC_CHANNEL_MODE 4
|
||||||
|
|
||||||
SDL_Joystick *joystick;
|
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);
|
SDL_Init(SDL_INIT_JOYSTICK);
|
||||||
joystick = SDL_JoystickOpen(0);
|
joystick = SDL_JoystickOpen(0);
|
||||||
if (joystick != NULL) {
|
if (joystick != NULL) {
|
||||||
@ -27,14 +30,10 @@ void joystickInit() {
|
|||||||
gzwarn << "Joystick not found, begin waiting for joystick..." << std::endl;
|
gzwarn << "Joystick not found, begin waiting for joystick..." << std::endl;
|
||||||
warnShown = true;
|
warnShown = true;
|
||||||
}
|
}
|
||||||
|
return joystickInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool joystickGet(int16_t ch[16]) {
|
bool joystickGet(int16_t ch[16]) {
|
||||||
if (!joystickInitialized) {
|
|
||||||
joystickInit();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < sizeof(channels) / sizeof(channels[0]); i++) {
|
for (uint8_t i = 0; i < sizeof(channels) / sizeof(channels[0]); i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user