Driver for Spektrum (tm) serial receiver, for radio controlled helicopters etc.
spektRx.h@0:80f1104f405a, 2011-10-25 (annotated)
- Committer:
- offroad
- Date:
- Tue Oct 25 18:15:55 2011 +0000
- Revision:
- 0:80f1104f405a
Initial release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
offroad | 0:80f1104f405a | 1 | /* Driver for Spektrum satellite Rx |
offroad | 0:80f1104f405a | 2 | * M. Nentwig |
offroad | 0:80f1104f405a | 3 | * version 0.1, 25.10.2011 |
offroad | 0:80f1104f405a | 4 | * Connections: |
offroad | 0:80f1104f405a | 5 | * - orange wire to 3.3V regulated out |
offroad | 0:80f1104f405a | 6 | * - black wire to GND |
offroad | 0:80f1104f405a | 7 | * - grey wire to pin 10 (for example) |
offroad | 0:80f1104f405a | 8 | * - Serial serIn(p9, p10); |
offroad | 0:80f1104f405a | 9 | * - serIn.baud(115200); |
offroad | 0:80f1104f405a | 10 | * - see also http://diydrones.ning.com/profiles/blog/show?id=705844%3ABlogPost%3A64228 |
offroad | 0:80f1104f405a | 11 | */ |
offroad | 0:80f1104f405a | 12 | #ifndef SPEKTRX_H |
offroad | 0:80f1104f405a | 13 | #define SPEKTRX_H |
offroad | 0:80f1104f405a | 14 | |
offroad | 0:80f1104f405a | 15 | typedef struct _spektRx { |
offroad | 0:80f1104f405a | 16 | char state; |
offroad | 0:80f1104f405a | 17 | unsigned char data[14]; |
offroad | 0:80f1104f405a | 18 | unsigned short out[7]; |
offroad | 0:80f1104f405a | 19 | bool valid; |
offroad | 0:80f1104f405a | 20 | long frameNum; |
offroad | 0:80f1104f405a | 21 | } spektRx_t; |
offroad | 0:80f1104f405a | 22 | |
offroad | 0:80f1104f405a | 23 | /* Initialize the spektRx */ |
offroad | 0:80f1104f405a | 24 | void spektRx_init(spektRx_t* self); |
offroad | 0:80f1104f405a | 25 | |
offroad | 0:80f1104f405a | 26 | /* Feed a single byte of received data into the spektRx */ |
offroad | 0:80f1104f405a | 27 | void spektRx_runChar(spektRx_t* self, unsigned char c); |
offroad | 0:80f1104f405a | 28 | |
offroad | 0:80f1104f405a | 29 | /* alternatively, let it loose on the serial input |
offroad | 0:80f1104f405a | 30 | * checks readable -> non-blocking |
offroad | 0:80f1104f405a | 31 | */ |
offroad | 0:80f1104f405a | 32 | void spektRx_runSerial(spektRx_t* self, Serial* s); |
offroad | 0:80f1104f405a | 33 | |
offroad | 0:80f1104f405a | 34 | /* Check, whether a frame has been received */ |
offroad | 0:80f1104f405a | 35 | bool spektRx_hasValidFrame(spektRx_t* self); |
offroad | 0:80f1104f405a | 36 | |
offroad | 0:80f1104f405a | 37 | /* If a valid frame is available, retrieve one channel |
offroad | 0:80f1104f405a | 38 | * and convert to float (quick-and-dirty option) */ |
offroad | 0:80f1104f405a | 39 | unsigned short* spektRx_getChannelData(spektRx_t* self); |
offroad | 0:80f1104f405a | 40 | |
offroad | 0:80f1104f405a | 41 | /* Gets pointer to array with all 7 input channels as |
offroad | 0:80f1104f405a | 42 | * 10-bit unsigned float (preferred way of reading) */ |
offroad | 0:80f1104f405a | 43 | float spektRx_getChannelValue(spektRx_t* self, char ixChan); |
offroad | 0:80f1104f405a | 44 | |
offroad | 0:80f1104f405a | 45 | /* Get the number of the currently received frame. |
offroad | 0:80f1104f405a | 46 | * Starts with 1 */ |
offroad | 0:80f1104f405a | 47 | long spektRx_getFrameNum(spektRx_t* self); |
offroad | 0:80f1104f405a | 48 | |
offroad | 0:80f1104f405a | 49 | /* Mark the current frame as invalid. |
offroad | 0:80f1104f405a | 50 | * spektRx_haseValidFrame() will return false, until |
offroad | 0:80f1104f405a | 51 | * the next frame has been received */ |
offroad | 0:80f1104f405a | 52 | void spektRx_invalidateFrame(spektRx_t* self); |
offroad | 0:80f1104f405a | 53 | #endif |