35 #if defined(ARDUINO_ARCH_AVR)
36 #include <avr/interrupt.h>
53 static uint8_t _rxPin;
54 static uint32_t _tPulseBegin;
55 static uint16_t _tPinHigh;
56 static uint16_t _tPinLow;
58 static volatile uint32_t _rxData;
62 #if defined(ARDUINO_ARCH_AVR)
63 static uint8_t _rxPinPort;
64 static uint8_t _rxPinBit;
72 #define RF_RX_PIN_INIT(rfRxPin) { \
74 _rxPin = digitalPinToInterrupt(extIntPin); \
76 _rxPinPort = digitalPinToPort(extIntPin); \
77 _rxPinBit = digitalPinToBitMask(extIntPin); \
85 #define RF_RX_PIN_READ() (*portInputRegister(_rxPinPort) & _rxPinBit)
87 #elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
95 #define RF_RX_PIN_INIT(rfRxPin) { _rxPin = rfRxPin; }
102 #define RF_RX_PIN_READ() (digitalRead(_rxPin) ? HIGH : LOW)
105 #error "May work, but not tested on this target"
115 static void rxEnable()
127 static void rxDisable()
130 detachInterrupt(_rxPin);
146 static bool isPulseInRange(uint16_t tPulse, uint16_t tMin, uint16_t tMax)
149 if ((tPulse >= tMin) && (tPulse <= tMax)) {
163 static bool findSync()
166 if (isPulseInRange(_tPinHigh, T_SYNC_H_MIN, T_SYNC_H_MAX)) {
167 if (isPulseInRange(_tPinLow, T_SYNC_L_MIN_0, T_SYNC_L_MAX_0)) {
172 }
else if (isPulseInRange(_tPinLow, T_SYNC_L_MIN_1, T_SYNC_L_MAX_1)) {
189 static void storeBit(
bool one)
193 _rxData |= (1UL << _rxBit);
212 static void handlePulse()
214 if (isPulseInRange(_tPinHigh, T_BIT_SHORT_MIN, T_BIT_SHORT_MAX)) {
223 }
else if (isPulseInRange(_tPinHigh, T_BIT_LONG_MIN, T_BIT_LONG_MAX)) {
238 static void handleSpace()
241 if (isPulseInRange(_tPinLow, T_BIT_SHORT_MIN, T_BIT_SHORT_MAX)) {
250 }
else if (isPulseInRange(_tPinLow, T_BIT_LONG_MIN, T_BIT_LONG_MAX)) {
268 uint16_t _tPulseLength;
278 if (tNow > _tPulseBegin) {
279 _tPulseLength = tNow - _tPulseBegin;
281 _tPulseLength = _tPulseBegin - tNow;
285 if (_tPulseLength < T_RX_TOLERANCE_US) {
291 rfPinHigh = RF_RX_PIN_READ();
295 _tPinLow = _tPulseLength;
297 _tPinHigh = _tPulseLength;
327 RF_RX_PIN_INIT(extIntPin);
bool OregonTHN128_RawToData(uint32_t rawData, OregonTHN128Data_t *data)
Cnonvert 32-bit raw data to OregonTHN128Data_t structure.
bool OregonTHN128_CheckCRC(uint32_t rawData)
Verify checksum.
void rfPinChange(void)
RF pin level change.
bool OregonTHN128_Read(OregonTHN128Data_t *data)
Read data.
void OregonTHN128_RxEnable()
Receive enable.
void OregonTHN128_RxBegin(uint8_t extIntPin)
Initialize receiver pin.
void OregonTHN128_RxDisable()
Receive disable.
bool OregonTHN128_Available()
Check if data received.
Oregon THN128 433MHz temperature receive library for Arduino.