my sbus
Fork of FutabaSBUS by
FutabaSBUS.h@0:6618cf21c95c, 2011-12-14 (annotated)
- Committer:
- Digixx
- Date:
- Wed Dec 14 20:46:10 2011 +0000
- Revision:
- 0:6618cf21c95c
- Child:
- 1:e3c92fba87f2
beta version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Digixx | 0:6618cf21c95c | 1 | /* mbed R/C Futaba SBUS Library |
Digixx | 0:6618cf21c95c | 2 | * Copyright (c) 2011-2012 digixx |
Digixx | 0:6618cf21c95c | 3 | * |
Digixx | 0:6618cf21c95c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Digixx | 0:6618cf21c95c | 5 | * of this software and associated documentation files (the "Software"), to deal |
Digixx | 0:6618cf21c95c | 6 | * in the Software without restriction, including without limitation the rights |
Digixx | 0:6618cf21c95c | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Digixx | 0:6618cf21c95c | 8 | * copies of the Software, and to permit persons to whom the Software is |
Digixx | 0:6618cf21c95c | 9 | * furnished to do so, subject to the following conditions: |
Digixx | 0:6618cf21c95c | 10 | * |
Digixx | 0:6618cf21c95c | 11 | * The above copyright notice and this permission notice shall be included in |
Digixx | 0:6618cf21c95c | 12 | * all copies or substantial portions of the Software. |
Digixx | 0:6618cf21c95c | 13 | * |
Digixx | 0:6618cf21c95c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Digixx | 0:6618cf21c95c | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Digixx | 0:6618cf21c95c | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Digixx | 0:6618cf21c95c | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Digixx | 0:6618cf21c95c | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Digixx | 0:6618cf21c95c | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Digixx | 0:6618cf21c95c | 20 | * THE SOFTWARE. |
Digixx | 0:6618cf21c95c | 21 | */ |
Digixx | 0:6618cf21c95c | 22 | |
Digixx | 0:6618cf21c95c | 23 | |
Digixx | 0:6618cf21c95c | 24 | #ifndef MBED_FUTABA_SBUS_H |
Digixx | 0:6618cf21c95c | 25 | #define MBED_FUTABA_SBUS_H |
Digixx | 0:6618cf21c95c | 26 | |
Digixx | 0:6618cf21c95c | 27 | #define SBUS_SIGNAL_OK 0x00 |
Digixx | 0:6618cf21c95c | 28 | #define SBUS_SIGNAL_LOST 0x01 |
Digixx | 0:6618cf21c95c | 29 | #define SBUS_SIGNAL_FAILSAFE 0x03 |
Digixx | 0:6618cf21c95c | 30 | |
Digixx | 0:6618cf21c95c | 31 | #include "MODSERIAL.h" |
Digixx | 0:6618cf21c95c | 32 | #include "mbed.h" |
Digixx | 0:6618cf21c95c | 33 | |
Digixx | 0:6618cf21c95c | 34 | /** SBUS control class, based on MODSERIAL |
Digixx | 0:6618cf21c95c | 35 | * |
Digixx | 0:6618cf21c95c | 36 | * Example: |
Digixx | 0:6618cf21c95c | 37 | * @code |
Digixx | 0:6618cf21c95c | 38 | * // Continuously sweep the servo through it's full range |
Digixx | 0:6618cf21c95c | 39 | * #include "FutabaSBUS.h" |
Digixx | 0:6618cf21c95c | 40 | * #include "mbed.h" |
Digixx | 0:6618cf21c95c | 41 | * |
Digixx | 0:6618cf21c95c | 42 | * FutabaSBUS sbus(p28, p27); |
Digixx | 0:6618cf21c95c | 43 | * |
Digixx | 0:6618cf21c95c | 44 | * int main() { |
Digixx | 0:6618cf21c95c | 45 | * sbus.passthrough(false); |
Digixx | 0:6618cf21c95c | 46 | * while(1) { |
Digixx | 0:6618cf21c95c | 47 | * for(int i=0; i<100; i++) { |
Digixx | 0:6618cf21c95c | 48 | * sbus.servo(1) = i/100.0; |
Digixx | 0:6618cf21c95c | 49 | * wait(0.01); |
Digixx | 0:6618cf21c95c | 50 | * } |
Digixx | 0:6618cf21c95c | 51 | * for(int i=100; i>0; i--) { |
Digixx | 0:6618cf21c95c | 52 | * sbus.servo(1) = i/100.0; |
Digixx | 0:6618cf21c95c | 53 | * wait(0.01); |
Digixx | 0:6618cf21c95c | 54 | * } |
Digixx | 0:6618cf21c95c | 55 | * } |
Digixx | 0:6618cf21c95c | 56 | * } |
Digixx | 0:6618cf21c95c | 57 | * @endcode |
Digixx | 0:6618cf21c95c | 58 | */ |
Digixx | 0:6618cf21c95c | 59 | |
Digixx | 0:6618cf21c95c | 60 | class FutabaSBUS { |
Digixx | 0:6618cf21c95c | 61 | public: |
Digixx | 0:6618cf21c95c | 62 | FutabaSBUS(PinName tx, PinName rx); |
Digixx | 0:6618cf21c95c | 63 | int16_t channel(uint8_t ch); |
Digixx | 0:6618cf21c95c | 64 | uint8_t digichannel(uint8_t ch); |
Digixx | 0:6618cf21c95c | 65 | void servo(uint8_t ch, int16_t position); |
Digixx | 0:6618cf21c95c | 66 | void digiservo(uint8_t ch, uint8_t position); |
Digixx | 0:6618cf21c95c | 67 | uint8_t failsafe(void); |
Digixx | 0:6618cf21c95c | 68 | void passthrough(bool mode); |
Digixx | 0:6618cf21c95c | 69 | bool passthrough(void); |
Digixx | 0:6618cf21c95c | 70 | |
Digixx | 0:6618cf21c95c | 71 | private: |
Digixx | 0:6618cf21c95c | 72 | MODSERIAL sbus_; |
Digixx | 0:6618cf21c95c | 73 | Ticker rxSBUS; |
Digixx | 0:6618cf21c95c | 74 | void SBUS_irq_rx(MODSERIAL_IRQ_INFO *q); |
Digixx | 0:6618cf21c95c | 75 | void rx_ticker_500us(void); |
Digixx | 0:6618cf21c95c | 76 | void update_channels(void); |
Digixx | 0:6618cf21c95c | 77 | void update_servos(void); |
Digixx | 0:6618cf21c95c | 78 | volatile int rx_timeout; |
Digixx | 0:6618cf21c95c | 79 | volatile int tx_timeout; |
Digixx | 0:6618cf21c95c | 80 | }; |
Digixx | 0:6618cf21c95c | 81 | |
Digixx | 0:6618cf21c95c | 82 | #endif |