-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.h
42 lines (31 loc) · 972 Bytes
/
protocol.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
#ifndef IR_H
#define IR_H
#include "mbed.h"
#include <map>
namespace IR {
#define GET_BIT(X, BIT) ((X & (1 << BIT)) >> BIT)
class BaseDecoder {
private:
friend void on_edge();
friend void decode_bit(BaseDecoder dec, uint8_t bit);
protected:
BaseDecoder(PinName pin, std::map<uint8_t, Callback<void()>> commands);
InterruptIn signal;
Timer clock;
int prev_signal_val = 1;
bool decoding = false;
uint16_t command = 0;
uint8_t cur_bit = 0;
void decode_bit(uint8_t bit);
virtual void decode_fall() = 0;
virtual void decode_rise() = 0;
virtual bool cmp_command(uint16_t cmd) = 0;
virtual bool final_bit() = 0;
virtual bool good_startcode(uint8_t) = 0;
virtual void decode_reset() = 0;
std::map<uint8_t, Callback<void()>> commands;
};
void add_decoder_to_list(BaseDecoder *dec);
void on_edge();
}
#endif