-
Notifications
You must be signed in to change notification settings - Fork 10
/
iBUSTelemetry.h
126 lines (104 loc) · 2.64 KB
/
iBUSTelemetry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* iBUSTelemetry.cpp - adis1313
*
* Libraries or parts of the code used in this project:
*
* SoftwareSerialWithHalfDuplex
* https://github.com/nickstedman/SoftwareSerialWithHalfDuplex
*
* iBUStelemetry
* https://github.com/Hrastovc/iBUStelemetry
*
* FlySkyI6
* https://github.com/qba667/FlySkyI6/blob/master/source/source/ibustelemetry.h
*
* Big thanks to the authors!
*/
#ifndef iBUSTelemetry_h
#define iBUSTelemetry_h_h
#include <inttypes.h>
#include <Stream.h>
#include <iBUSSensors.h>
#define _SS_MAX_RX_BUFF 64 // RX buffer size
#ifndef GCC_VERSION
# define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
class iBUSTelemetry : public Stream
{
private:
uint8_t _pin;
uint8_t _pinBitMask;
volatile uint8_t * _receivePortRegister;
volatile uint8_t * _transmitPortRegister;
volatile uint8_t * _pcint_maskreg;
uint8_t _pcint_maskvalue;
uint16_t _rx_delay_centering;
uint16_t _rx_delay_intrabit;
uint16_t _rx_delay_stopbit;
uint16_t _tx_delay;
bool _buffer_overflow;
static char _receive_buffer[_SS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;
static iBUSTelemetry * active_object;
void
recv() __attribute__((__always_inline__));
uint8_t
rx_pin_read();
void
setPin(uint8_t pin);
void
setRxIntMsk(bool enable) __attribute__((__always_inline__));
static uint16_t
subtract_cap(uint16_t num, uint16_t sub);
static inline void
tunedDelay(uint16_t delay);
uint8_t sensorCount;
typedef struct iBUSSensor {
uint8_t type;
int32_t value;
} iBUSSensor;
iBUSSensor sensorArray[MAX_SENS_COUNT];
uint8_t
getSensorSize(uint8_t type);
public:
iBUSTelemetry(uint8_t receivePin);
~iBUSTelemetry();
void
begin();
void
run();
bool
listen();
void
end();
bool
isListening(){ return this == active_object; }
bool
stopListening();
bool
overflow(){ bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; }
int
peek();
void
addSensor(uint8_t type);
void
setSensorValue(uint8_t adr, int32_t value);
void
setSensorValueFP(uint8_t adr, float value);
uint16_t
gpsStateValues(uint8_t firstVal, uint8_t secondVal);
virtual size_t
write(uint8_t byte);
virtual int
read();
virtual int
available();
virtual void
flush();
operator bool (){ return true; }
using Print::write;
static inline void
handle_interrupt() __attribute__((__always_inline__));
};
#endif // ifndef iBUSTelemetry_h