-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrf_zeus_rx_internal.h
118 lines (102 loc) · 3.26 KB
/
rf_zeus_rx_internal.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
/*
* Class to receive and decode signals from wireless sensors of an old
* security system.
*
* See the README.md for more details.
*
* Copyright 2017 David M Kent.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RF_ZEUS_RX_h
#define RF_ZEUS_RX_h
#include <Arduino.h>
/*
* Radio access class. Provides functionality to block until we receive a valid
* signal then a method to read the resulting payload bytes out.
*
* Note: this relies heavily on near real-time interrupts on pin transition. As a
* result this generally needs the WiFi module powered down to achieve
* reasonable performance. This can be done with WiFi.forceSleepBegin()
*/
class RF_ZEUS_RX {
public:
/*
* Initialise the radio module.
*
* Should generally be called in setup().
*/
void init(unsigned int input_pin);
/*
* Set _buffer member pointer to buffer.
*
* This needs to point to a sufficiently large array of memory to read decoded bytes into.
*/
void set_buffer(byte* buffer);
/*
* Get number of bytes currently decoded.
*/
unsigned int get_byte_count();
/*
* Do not call manually. Used internally to handle transition interrups.
*/
void handle_interrupt();
/*
* Block until two transitions (a high pulse and a low pulse, i.e. one bit) have occured.
*
* This is the main primitive used by src/ZeusRfDecoder.
*
* Unsigned long types align with return of micros().
*/
void get_transition_pair(unsigned long* pos_start, unsigned long* pos_end,
unsigned long* width_high, unsigned long* width_low);
/*
* Advance position until we hit a HIGH pulse.
*/
void advance_to_high_pulse();
/*
* Handle recieve of sync bit
*/
void handle_sync_bit(unsigned long pos);
/*
* Handle a completed decoded data byte
*/
void handle_data_byte(unsigned long byte_start, unsigned long byte_end, byte data);
private:
/*
* Buffer is used to store decoded byte array, count indexes it.
*/
unsigned int count = 0;
byte* _buffer;
// Variables used in the ISR
volatile boolean found_transition = false;
volatile boolean is_high = true;
volatile boolean new_state = true;
// Pin used for input (interupts added on this pin)
unsigned int _input_pin;
/*
* Method to block until we change state on input.
*
* Note the yield statement; the ESP8266 has a watchdog timer
* that will reboot the system if we block too long. The yield
* allows the system to go and do other things, such as maintain
* wifi.
*/
inline void _block_until_transition();
};
/*
* The ISR used to flag we've had a transition on the input.
*/
void transition();
#endif // RF_ZEUS_RX_h