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,14 +27,12 @@ void setupRC() {
bool readRC() {
if (rcRxPin < 0) return false;
if (rc.read()) {
SBUSData data = rc.data();
for (int i = 0; i < 16; i++) channels[i] = data.ch[i]; // copy channels data
if (!rc.read()) return false;
rc.getChannels(channels);
normalizeRC();
controlTime = t;
return true;
}
return false;
}
void normalizeRC() {
+4 -5
View File
@@ -15,12 +15,11 @@ public:
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) {};
bool read() { return joystickInit(); };
SBUSData data() {
SBUSData data;
joystickGet(data.ch);
void getChannels(uint16_t (&channels)[16]) const {
int16_t ch[16];
joystickGet(ch);
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;
};
};