1 #ifndef SiKRadioController_h
2 #define SiKRadioController_h
7 #include <OSCMessage.h>
8 #include <SLIPEncodedSerial.h>
13 SiKRadioController(HardwareSerial &serial) :
16 memset(&state,
'\0',
sizeof(state));
17 memset(&event,
'\0',
sizeof(event));
23 xTaskCreatePinnedToCore(
34 SLIPEncodedSerial fSLIP;
39 uint32_t lastEvent = 0;
44 if (fSLIP.available())
46 while (!fSLIP.endofPacket())
48 while (fSLIP.available())
50 msg.fill(fSLIP.read());
53 Serial.println(
"RADIO CONNECTED");
61 state.analog.stick.lx = map(msg.getInt(0), 0, 1024, 127, -128);
62 state.analog.stick.ly = map(msg.getInt(1), 0, 1024, 127, -128);
63 state.analog.button.l2 = 255;
64 int32_t b = msg.getInt(2);
65 state.button.left = ((b & (1<<1)) != 0);
66 state.button.up = ((b & (1<<2)) != 0);
67 state.button.right = ((b & (1<<3)) != 0);
68 state.button.down = ((b & (1<<4)) != 0);
69 state.button.select= ((b & (1<<0)) != 0);
74 if (fConnected && lastEvent + 200 < millis())
76 Serial.println(
"NO RADIO DATA for 200ms");
83 static void joyLoopTask(
void* arg)
85 RadioController* ctrl = (RadioController*)arg;
89 static int map(
int x,
int in_min,
int in_max,
int out_min,
int out_max)
91 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;