Simplify rc code

Utilize the new method for getting channel values.
This commit is contained in:
Oleg Kalachev
2026-06-14 04:45:42 +03:00
parent 17df1c5396
commit 518abf1555
2 changed files with 10 additions and 13 deletions
+3 -5
View File
@@ -27,15 +27,13 @@ void setupRC() {
bool readRC() { bool readRC() {
if (rcRxPin < 0) return false; if (rcRxPin < 0) return false;
if (rc.read()) { if (!rc.read()) return false;
SBUSData data = rc.data();
for (int i = 0; i < 16; i++) channels[i] = data.ch[i]; // copy channels data rc.getChannels(channels);
normalizeRC(); normalizeRC();
controlTime = t; controlTime = t;
return true; return true;
} }
return false;
}
void normalizeRC() { void normalizeRC() {
float controls[16]; float controls[16];
+4 -5
View File
@@ -15,12 +15,11 @@ public:
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(int rxpin = -1, int txpin = -1, bool inv = true, bool fast = false) {}; void begin(int rxpin = -1, int txpin = -1, bool inv = true, bool fast = false) {};
bool read() { return joystickInit(); }; bool read() { return joystickInit(); };
SBUSData data() { void getChannels(uint16_t (&channels)[16]) const {
SBUSData data; int16_t ch[16];
joystickGet(data.ch); joystickGet(ch);
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
data.ch[i] = map(data.ch[i], -32768, 32767, 1000, 2000); // convert to pulse width style channels[i] = map(ch[i], -32768, 32767, 1000, 2000); // convert to pulse width style
} }
return data;
}; };
}; };