my sbus

Dependents:   Drone_air

Fork of FutabaSBUS by Uwe Gartmann

Committer:
okini3939
Date:
Thu May 19 08:56:30 2016 +0000
Revision:
3:50e10bf74374
Parent:
2:07dbb77a6f1a
added start();

Who changed what in which revision?

UserRevisionLine numberNew 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
okini3939 2:07dbb77a6f1a 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 1:e3c92fba87f2 62 /** create a FutabaSBUS object connected to the specified serial pins
Digixx 1:e3c92fba87f2 63 *
Digixx 1:e3c92fba87f2 64 * &param pin serial tx,rx to connect to
Digixx 1:e3c92fba87f2 65 */
Digixx 0:6618cf21c95c 66 FutabaSBUS(PinName tx, PinName rx);
okini3939 3:50e10bf74374 67
okini3939 3:50e10bf74374 68 void start ();
Digixx 1:e3c92fba87f2 69
Digixx 1:e3c92fba87f2 70 /** Read channel(1..16), digital raw data
Digixx 1:e3c92fba87f2 71 *
Digixx 1:e3c92fba87f2 72 * &param raw data from receiver range from 0 to 4096, normal from 352 1696
Digixx 1:e3c92fba87f2 73 */
Digixx 0:6618cf21c95c 74 int16_t channel(uint8_t ch);
Digixx 1:e3c92fba87f2 75
Digixx 1:e3c92fba87f2 76 /** Read digital channel(1..2), range 0..1
Digixx 1:e3c92fba87f2 77 *
Digixx 1:e3c92fba87f2 78 * &param range 0..1
Digixx 1:e3c92fba87f2 79 */
Digixx 0:6618cf21c95c 80 uint8_t digichannel(uint8_t ch);
Digixx 1:e3c92fba87f2 81
Digixx 1:e3c92fba87f2 82 /** Set servo position, raw data, range 200..2000?
Digixx 1:e3c92fba87f2 83 *
Digixx 1:e3c92fba87f2 84 * &param raw data 0..2048
Digixx 1:e3c92fba87f2 85 */
Digixx 0:6618cf21c95c 86 void servo(uint8_t ch, int16_t position);
Digixx 1:e3c92fba87f2 87
Digixx 1:e3c92fba87f2 88 /** Set digital channel, 0..1
Digixx 1:e3c92fba87f2 89 *
Digixx 1:e3c92fba87f2 90 * &param range 0..1
Digixx 1:e3c92fba87f2 91 */
Digixx 0:6618cf21c95c 92 void digiservo(uint8_t ch, uint8_t position);
Digixx 1:e3c92fba87f2 93
Digixx 1:e3c92fba87f2 94 /** Read failsafe condition
Digixx 1:e3c92fba87f2 95 *
Digixx 1:e3c92fba87f2 96 * &param 0=no failsafe 1=lost signal 3=failsafe
Digixx 1:e3c92fba87f2 97 */
Digixx 0:6618cf21c95c 98 uint8_t failsafe(void);
Digixx 1:e3c92fba87f2 99
okini3939 2:07dbb77a6f1a 100 void failsafe(uint8_t status);
okini3939 2:07dbb77a6f1a 101
Digixx 1:e3c92fba87f2 102 /** Set logical data passtrough - servo values are ignored, using received data
Digixx 1:e3c92fba87f2 103 *
Digixx 1:e3c92fba87f2 104 * &param bool
Digixx 1:e3c92fba87f2 105 */
Digixx 0:6618cf21c95c 106 void passthrough(bool mode);
Digixx 1:e3c92fba87f2 107
Digixx 1:e3c92fba87f2 108 /** Read logical data passtrough
Digixx 1:e3c92fba87f2 109 *
Digixx 1:e3c92fba87f2 110 * &param bool
Digixx 1:e3c92fba87f2 111 */
Digixx 0:6618cf21c95c 112 bool passthrough(void);
Digixx 0:6618cf21c95c 113
Digixx 0:6618cf21c95c 114 private:
okini3939 2:07dbb77a6f1a 115 RawSerial sbus_;
Digixx 0:6618cf21c95c 116 Ticker rxSBUS;
okini3939 2:07dbb77a6f1a 117 // void SBUS_irq_rx(MODSERIAL_IRQ_INFO *q);
okini3939 2:07dbb77a6f1a 118 void SBUS_irq_rx(void);
Digixx 0:6618cf21c95c 119 void rx_ticker_500us(void);
Digixx 0:6618cf21c95c 120 void update_channels(void);
Digixx 0:6618cf21c95c 121 void update_servos(void);
Digixx 0:6618cf21c95c 122 volatile int rx_timeout;
Digixx 0:6618cf21c95c 123 volatile int tx_timeout;
Digixx 0:6618cf21c95c 124 };
Digixx 0:6618cf21c95c 125
Digixx 0:6618cf21c95c 126 #endif