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() {
|
||||
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
@@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user