Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Simplify rc code Utilize the new method for getting channel values.

Oleg Kalachev518abf15550d
diff --git a/flix/rc.ino b/flix/rc.ino
index 8332e2d..ec02a30 100644
--- a/flix/rc.ino
+++ b/flix/rc.ino
@@ -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
- normalizeRC();
- controlTime = t;
- return true;
- }
- return false;
+ if (!rc.read()) return false;
+
+ rc.getChannels(channels);
+ normalizeRC();
+ controlTime = t;
+ return true;
}
void normalizeRC() {
diff --git a/gazebo/SBUS.h b/gazebo/SBUS.h
index 11161d7..d28dd3e 100644
--- a/gazebo/SBUS.h
+++ b/gazebo/SBUS.h
@@ -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;
};
};