forked from bolderflight/sbus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in SBUS timing, added options for non-inverted signals, and…
… simplified the class interfaces.
- Loading branch information
1 parent
7e2f061
commit 1c353d1
Showing
10 changed files
with
286 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Brian R Taylor | ||
* [email protected] | ||
* | ||
* Copyright (c) 2021 Bolder Flight Systems Inc | ||
* Copyright (c) 2022 Bolder Flight Systems Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the “Software”), to | ||
|
@@ -23,51 +23,40 @@ | |
* IN THE SOFTWARE. | ||
*/ | ||
|
||
/* | ||
* This example reads an SBUS packet from an SBUS receiver and writes it to an | ||
* SBUS compatible servo. The SBUS out capability (i.e. writing a command to | ||
* the servo) could be generated independently; however, the packet timing | ||
* would need to be controlled by the programmer, the write function simply | ||
* generates an SBUS packet and writes it to the servos. In this case the | ||
* packet timing is handled by the SBUS receiver and waiting for a good packet | ||
* read. | ||
*/ | ||
|
||
#include "sbus.h" | ||
|
||
/* SbusRx object on Serial1 */ | ||
bfs::SbusRx sbus_rx(&Serial1); | ||
/* SbusTx object on Serial1 */ | ||
bfs::SbusTx sbus_tx(&Serial1); | ||
/* Array for storing SBUS data */ | ||
std::array<int16_t, bfs::SbusRx::NUM_CH()> sbus_data; | ||
/* SBUS object, reading SBUS */ | ||
bfs::SbusRx sbus_rx(&Serial2); | ||
/* SBUS object, writing SBUS */ | ||
bfs::SbusTx sbus_tx(&Serial2); | ||
/* SBUS data */ | ||
bfs::SbusData data; | ||
|
||
void setup() { | ||
/* Serial to display the received data */ | ||
/* Serial to display data */ | ||
Serial.begin(115200); | ||
while (!Serial) {} | ||
/* Begin the SBUS communication */ | ||
sbus_rx.Begin(); | ||
sbus_tx.Begin(); | ||
} | ||
|
||
void loop() { | ||
void loop () { | ||
if (sbus_rx.Read()) { | ||
/* Grab the received data */ | ||
sbus_data = sbus_rx.ch(); | ||
data = sbus_rx.data(); | ||
/* Display the received data */ | ||
for (int8_t i = 0; i < bfs::SbusRx::NUM_CH(); i++) { | ||
Serial.print(sbus_data[i]); | ||
for (int8_t i = 0; i < data.NUM_CH; i++) { | ||
Serial.print(data.ch[i]); | ||
Serial.print("\t"); | ||
} | ||
/* Display lost frames and failsafe data */ | ||
Serial.print(sbus_rx.lost_frame()); | ||
Serial.print(data.lost_frame); | ||
Serial.print("\t"); | ||
Serial.println(sbus_rx.failsafe()); | ||
Serial.println(data.failsafe); | ||
/* Set the SBUS TX data to the received data */ | ||
sbus_tx.ch(sbus_data); | ||
sbus_tx.data(data); | ||
/* Write the data to the servos */ | ||
sbus_tx.Write(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Brian R Taylor | ||
* [email protected] | ||
* | ||
* Copyright (c) 2021 Bolder Flight Systems Inc | ||
* Copyright (c) 2022 Bolder Flight Systems Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the “Software”), to | ||
|
@@ -26,11 +26,11 @@ | |
#include "sbus.h" | ||
|
||
/* SBUS object, reading SBUS */ | ||
bfs::SbusRx sbus_rx(&Serial1); | ||
bfs::SbusRx sbus_rx(&Serial2); | ||
/* SBUS object, writing SBUS */ | ||
bfs::SbusTx sbus_tx(&Serial1); | ||
/* Array for storing SBUS data */ | ||
std::array<int16_t, bfs::SbusRx::NUM_CH()> sbus_data; | ||
bfs::SbusTx sbus_tx(&Serial2); | ||
/* SBUS data */ | ||
bfs::SbusData data; | ||
|
||
int main() { | ||
/* Serial to display data */ | ||
|
@@ -42,18 +42,18 @@ int main() { | |
while (1) { | ||
if (sbus_rx.Read()) { | ||
/* Grab the received data */ | ||
sbus_data = sbus_rx.ch(); | ||
data = sbus_rx.data(); | ||
/* Display the received data */ | ||
for (int8_t i = 0; i < bfs::SbusRx::NUM_CH(); i++) { | ||
Serial.print(sbus_data[i]); | ||
for (int8_t i = 0; i < data.NUM_CH; i++) { | ||
Serial.print(data.ch[i]); | ||
Serial.print("\t"); | ||
} | ||
/* Display lost frames and failsafe data */ | ||
Serial.print(sbus_rx.lost_frame()); | ||
Serial.print(data.lost_frame); | ||
Serial.print("\t"); | ||
Serial.println(sbus_rx.failsafe()); | ||
Serial.println(data.failsafe); | ||
/* Set the SBUS TX data to the received data */ | ||
sbus_tx.ch(sbus_data); | ||
sbus_tx.data(data); | ||
/* Write the data to the servos */ | ||
sbus_tx.Write(); | ||
} | ||
|
Oops, something went wrong.