Driver for Spektrum (tm) serial receiver, for radio controlled helicopters etc.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spektRx.h Source File

spektRx.h

00001 /* Driver for Spektrum satellite Rx
00002  * M. Nentwig
00003  * version 0.1, 25.10.2011
00004  * Connections:
00005  * - orange wire to 3.3V regulated out
00006  * - black wire to GND
00007  * - grey wire to pin 10 (for example)
00008  * - Serial serIn(p9, p10);
00009  * - serIn.baud(115200);
00010  * - see also http://diydrones.ning.com/profiles/blog/show?id=705844%3ABlogPost%3A64228
00011  */
00012 #ifndef SPEKTRX_H
00013 #define SPEKTRX_H
00014 
00015 typedef struct _spektRx {
00016     char state;
00017     unsigned char data[14];
00018     unsigned short out[7];
00019     bool valid;
00020     long frameNum;
00021 } spektRx_t;
00022 
00023 /* Initialize the spektRx */
00024 void spektRx_init(spektRx_t* self);
00025 
00026 /* Feed a single byte of received data into the spektRx */
00027 void spektRx_runChar(spektRx_t* self, unsigned char c);
00028 
00029 /* alternatively, let it loose on the serial input
00030  * checks readable -> non-blocking
00031  */
00032 void spektRx_runSerial(spektRx_t* self, Serial* s);
00033 
00034 /* Check, whether a frame has been received */
00035 bool spektRx_hasValidFrame(spektRx_t* self);
00036 
00037 /* If a valid frame is available, retrieve one channel
00038  * and convert to float (quick-and-dirty option)  */
00039 unsigned short* spektRx_getChannelData(spektRx_t* self);
00040 
00041 /* Gets pointer to array with all 7 input channels as 
00042 * 10-bit unsigned float (preferred way of reading) */
00043 float spektRx_getChannelValue(spektRx_t* self, char ixChan);
00044 
00045 /* Get the number of the currently received frame. 
00046 * Starts with 1 */
00047 long spektRx_getFrameNum(spektRx_t* self);
00048 
00049 /* Mark the current frame as invalid.
00050 * spektRx_haseValidFrame() will return false, until
00051 * the next frame has been received */
00052 void spektRx_invalidateFrame(spektRx_t* self);
00053 #endif