-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCPPM.h
More file actions
43 lines (32 loc) · 1.14 KB
/
CPPM.h
File metadata and controls
43 lines (32 loc) · 1.14 KB
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
#ifndef CPPM_H
#define CPPM_H
#include <inttypes.h>
#include <avr/interrupt.h>
#define ICP1 8 // Input capture pin 1
#define CPPM_MAX_CHANNELS 16
#define CPPM_FRAME_SIZE_IN_MS 27 // FrSky D4R-II CPPM frame size
#define CPPM_SYNC_PULSE_WIDTH_FLOOR 10000 // Minimum tolerable value
#define CPPM_SYNC_PULSE_WIDTH_CEIL 50000 // Maximum tolerable value
#define CPPM_CHAN_PULSE_WIDTH_MIN 2000 // Minimum expected value
#define CPPM_CHAN_PULSE_WIDTH_MAX 4000 // Maximum expected value
#define CPPM_CHAN_PULSE_WIDTH_FLOOR 1500 // Minimum tolerable value
#define CPPM_CHAN_PULSE_WIDTH_CEIL 4500 // Maximum tolerable value
ISR(TIMER1_CAPT_vect);
class CPPMReceiver
{
private:
enum PulseState { SYNC_PULSE, CHAN_PULSE };
uint8_t _numChannels;
volatile bool _synced;
volatile PulseState _state;
volatile int16_t _channels[CPPM_MAX_CHANNELS];
public:
CPPMReceiver() : _synced(false), _state(SYNC_PULSE) {};
void begin(uint8_t numChannels);
void end();
bool ok();
void read(int16_t *channels);
friend void TIMER1_CAPT_vect();
};
extern CPPMReceiver CPPM;
#endif