my sbus
Fork of FutabaSBUS by
Diff: FutabaSBUS.h
- Revision:
- 0:6618cf21c95c
- Child:
- 1:e3c92fba87f2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FutabaSBUS.h Wed Dec 14 20:46:10 2011 +0000 @@ -0,0 +1,82 @@ +/* mbed R/C Futaba SBUS Library + * Copyright (c) 2011-2012 digixx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MBED_FUTABA_SBUS_H +#define MBED_FUTABA_SBUS_H + +#define SBUS_SIGNAL_OK 0x00 +#define SBUS_SIGNAL_LOST 0x01 +#define SBUS_SIGNAL_FAILSAFE 0x03 + +#include "MODSERIAL.h" +#include "mbed.h" + +/** SBUS control class, based on MODSERIAL + * + * Example: + * @code + * // Continuously sweep the servo through it's full range + * #include "FutabaSBUS.h" + * #include "mbed.h" + * + * FutabaSBUS sbus(p28, p27); + * + * int main() { + * sbus.passthrough(false); + * while(1) { + * for(int i=0; i<100; i++) { + * sbus.servo(1) = i/100.0; + * wait(0.01); + * } + * for(int i=100; i>0; i--) { + * sbus.servo(1) = i/100.0; + * wait(0.01); + * } + * } + * } + * @endcode + */ + +class FutabaSBUS { +public: + FutabaSBUS(PinName tx, PinName rx); + int16_t channel(uint8_t ch); + uint8_t digichannel(uint8_t ch); + void servo(uint8_t ch, int16_t position); + void digiservo(uint8_t ch, uint8_t position); + uint8_t failsafe(void); + void passthrough(bool mode); + bool passthrough(void); + +private: + MODSERIAL sbus_; + Ticker rxSBUS; + void SBUS_irq_rx(MODSERIAL_IRQ_INFO *q); + void rx_ticker_500us(void); + void update_channels(void); + void update_servos(void); + volatile int rx_timeout; + volatile int tx_timeout; +}; + +#endif \ No newline at end of file