mirror of
https://github.com/okalachev/flix.git
synced 2026-06-27 21:46:38 +00:00
Simplify rc code
Utilize the new method for getting channel values.
This commit is contained in:
+3
-5
@@ -27,14 +27,12 @@ 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() {
|
||||||
|
|||||||
+4
-5
@@ -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;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user