Skip to content

Commit

Permalink
Trying to get receiver packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Evangelista committed Nov 14, 2018
1 parent 5a7468d commit d2ea464
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
37 changes: 37 additions & 0 deletions TESTS/receiver/simple/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
TESTS/receiver/simple/main.cpp
Spektrum receiver test
D Evangelista, 2018
*/

#include "mbed.h"
#include "rtos.h"
#include "spektrum.h"
#include "unity.h"

Serial pc(USBTX, USBRX);
Spektrum receiver(p13, p14);
char c;



int main(){

pc.printf("Spektrum receiver simple test\r\n");
pc.printf("Be sure to connect orange to p13, gray to p14, blk to gnd\r\n");
pc.printf("Receiver should have already been bound to transmitter\r\n");

pc.printf("Successful (y/n)? ");
pc.scanf(" %c",&c);
TEST_ASSERT_EQUAL_MESSAGE('y',c,"receiver simple test failed.\r\n");

} // main() for TESTS/receiver/simple









2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#bfb43799afe571b26895d021f9932c274cff58c6
https://github.com/ARMmbed/mbed-os/#aab3ade2b7b38996fd73b855f1c5bc46e2877313
9 changes: 8 additions & 1 deletion spektrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
The receiver should first be bound using a BindPlug object.
*/
Spektrum::Spektrum(PinName tx, PinName rx): _receiver(tx, rx){
Spektrum::Spektrum(PinName tx, PinName rx, PinName rx_led): _receiver(tx, rx), _rx_led(rx_led){
_receiver.baud(SPEKTRUM_BAUD); // Spektrum uses 125000 8N1 or 115200 8N1

_receiver.attach(callback(this,&Spektrum::_rx_callback));
} // Spektrum(tx, rx) constructor

Spektrum::~Spektrum(){
} // ~Spektrum() destructor

void Spektrum::_rx_callback(void){
_rx_led.write(!_rx_led.read());
_buf[_i] = _receiver.getc();
_i = (_i+1) % SPEKTRUM_PACKET_SIZE;
} // _packet_callback()



Expand Down
15 changes: 10 additions & 5 deletions spektrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define SPEKTRUM_INT_DSMX_11MS 9
#define SPEKTRUM_EXT_DSMX_11MS 10
// DSM2 bind modes not recommended, not implemented
// EXT(ernal) bind modes don't really work on solitary satellite receiver

// field definitions
// #define SPEKTRUM_MASK_1024_CHANID 0xfc00
Expand All @@ -27,19 +28,23 @@
#define SPEKTRUM_BAUD 125000
// Spektrum baud is 125000, but if this doesn't work 115200 should work too.


#define SPEKTRUM_PACKET_SIZE 16

class Spektrum{
public:
unsigned int fades;
unsigned int system;
unsigned int servo[7];
bool is_bound;
Spektrum(PinName tx, PinName rx); // constructor
unsigned int fades;
unsigned int channel[12];
Spektrum(PinName tx, PinName rx, PinName rx_led=LED1); // constructor
~Spektrum(); // destructor

private:
Serial _receiver;
DigitalOut _rx_led;

char _buf[SPEKTRUM_PACKET_SIZE];
int _i;
void _rx_callback(void);
};


Expand Down

0 comments on commit d2ea464

Please sign in to comment.