my sbus
Fork of FutabaSBUS by
FutabaSBUS.h@2:07dbb77a6f1a, 2016-02-08 (annotated)
- Committer:
- okini3939
- Date:
- Mon Feb 08 08:47:36 2016 +0000
- Revision:
- 2:07dbb77a6f1a
- Parent:
- 1:e3c92fba87f2
- Child:
- 3:50e10bf74374
fix serial;
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 | |
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 | * ¶m pin serial tx,rx to connect to |
Digixx | 1:e3c92fba87f2 | 65 | */ |
Digixx | 0:6618cf21c95c | 66 | FutabaSBUS(PinName tx, PinName rx); |
Digixx | 1:e3c92fba87f2 | 67 | |
Digixx | 1:e3c92fba87f2 | 68 | /** Read channel(1..16), digital raw data |
Digixx | 1:e3c92fba87f2 | 69 | * |
Digixx | 1:e3c92fba87f2 | 70 | * ¶m raw data from receiver range from 0 to 4096, normal from 352 1696 |
Digixx | 1:e3c92fba87f2 | 71 | */ |
Digixx | 0:6618cf21c95c | 72 | int16_t channel(uint8_t ch); |
Digixx | 1:e3c92fba87f2 | 73 | |
Digixx | 1:e3c92fba87f2 | 74 | /** Read digital channel(1..2), range 0..1 |
Digixx | 1:e3c92fba87f2 | 75 | * |
Digixx | 1:e3c92fba87f2 | 76 | * ¶m range 0..1 |
Digixx | 1:e3c92fba87f2 | 77 | */ |
Digixx | 0:6618cf21c95c | 78 | uint8_t digichannel(uint8_t ch); |
Digixx | 1:e3c92fba87f2 | 79 | |
Digixx | 1:e3c92fba87f2 | 80 | /** Set servo position, raw data, range 200..2000? |
Digixx | 1:e3c92fba87f2 | 81 | * |
Digixx | 1:e3c92fba87f2 | 82 | * ¶m raw data 0..2048 |
Digixx | 1:e3c92fba87f2 | 83 | */ |
Digixx | 0:6618cf21c95c | 84 | void servo(uint8_t ch, int16_t position); |
Digixx | 1:e3c92fba87f2 | 85 | |
Digixx | 1:e3c92fba87f2 | 86 | /** Set digital channel, 0..1 |
Digixx | 1:e3c92fba87f2 | 87 | * |
Digixx | 1:e3c92fba87f2 | 88 | * ¶m range 0..1 |
Digixx | 1:e3c92fba87f2 | 89 | */ |
Digixx | 0:6618cf21c95c | 90 | void digiservo(uint8_t ch, uint8_t position); |
Digixx | 1:e3c92fba87f2 | 91 | |
Digixx | 1:e3c92fba87f2 | 92 | /** Read failsafe condition |
Digixx | 1:e3c92fba87f2 | 93 | * |
Digixx | 1:e3c92fba87f2 | 94 | * ¶m 0=no failsafe 1=lost signal 3=failsafe |
Digixx | 1:e3c92fba87f2 | 95 | */ |
Digixx | 0:6618cf21c95c | 96 | uint8_t failsafe(void); |
Digixx | 1:e3c92fba87f2 | 97 | |
okini3939 | 2:07dbb77a6f1a | 98 | void failsafe(uint8_t status); |
okini3939 | 2:07dbb77a6f1a | 99 | |
Digixx | 1:e3c92fba87f2 | 100 | /** Set logical data passtrough - servo values are ignored, using received data |
Digixx | 1:e3c92fba87f2 | 101 | * |
Digixx | 1:e3c92fba87f2 | 102 | * ¶m bool |
Digixx | 1:e3c92fba87f2 | 103 | */ |
Digixx | 0:6618cf21c95c | 104 | void passthrough(bool mode); |
Digixx | 1:e3c92fba87f2 | 105 | |
Digixx | 1:e3c92fba87f2 | 106 | /** Read logical data passtrough |
Digixx | 1:e3c92fba87f2 | 107 | * |
Digixx | 1:e3c92fba87f2 | 108 | * ¶m bool |
Digixx | 1:e3c92fba87f2 | 109 | */ |
Digixx | 0:6618cf21c95c | 110 | bool passthrough(void); |
Digixx | 0:6618cf21c95c | 111 | |
Digixx | 0:6618cf21c95c | 112 | private: |
okini3939 | 2:07dbb77a6f1a | 113 | RawSerial sbus_; |
Digixx | 0:6618cf21c95c | 114 | Ticker rxSBUS; |
okini3939 | 2:07dbb77a6f1a | 115 | // void SBUS_irq_rx(MODSERIAL_IRQ_INFO *q); |
okini3939 | 2:07dbb77a6f1a | 116 | void SBUS_irq_rx(void); |
Digixx | 0:6618cf21c95c | 117 | void rx_ticker_500us(void); |
Digixx | 0:6618cf21c95c | 118 | void update_channels(void); |
Digixx | 0:6618cf21c95c | 119 | void update_servos(void); |
Digixx | 0:6618cf21c95c | 120 | volatile int rx_timeout; |
Digixx | 0:6618cf21c95c | 121 | volatile int tx_timeout; |
Digixx | 0:6618cf21c95c | 122 | }; |
Digixx | 0:6618cf21c95c | 123 | |
Digixx | 0:6618cf21c95c | 124 | #endif |