mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-15 10:44:34 -05:00
100 lines
3.3 KiB
C++
100 lines
3.3 KiB
C++
|
|
||
|
#ifndef __FPROTO_AuriolTH_H__
|
||
|
#define __FPROTO_AuriolTH_H__
|
||
|
|
||
|
#include "weatherbase.hpp"
|
||
|
|
||
|
#define AURIOL_TH_CONST_DATA 0b1110
|
||
|
|
||
|
typedef enum {
|
||
|
auriol_THDecoderStepReset = 0,
|
||
|
auriol_THDecoderStepSaveDuration,
|
||
|
auriol_THDecoderStepCheckDuration,
|
||
|
} auriol_THDecoderStep;
|
||
|
|
||
|
class FProtoWeatherAuriolTh : public FProtoWeatherBase {
|
||
|
public:
|
||
|
FProtoWeatherAuriolTh() {
|
||
|
sensorType = FPW_AuriolTH;
|
||
|
}
|
||
|
|
||
|
void feed(bool level, uint32_t duration) {
|
||
|
switch (parser_step) {
|
||
|
case auriol_THDecoderStepReset:
|
||
|
if ((!level) && (DURATION_DIFF(duration, te_short * 8) < te_delta)) {
|
||
|
// Found sync
|
||
|
parser_step = auriol_THDecoderStepSaveDuration;
|
||
|
decode_data = 0;
|
||
|
decode_count_bit = 0;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case auriol_THDecoderStepSaveDuration:
|
||
|
if (level) {
|
||
|
te_last = duration;
|
||
|
parser_step = auriol_THDecoderStepCheckDuration;
|
||
|
} else {
|
||
|
parser_step = auriol_THDecoderStepReset;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case auriol_THDecoderStepCheckDuration:
|
||
|
if (!level) {
|
||
|
if (DURATION_DIFF(duration, te_short * 8) <
|
||
|
te_delta) {
|
||
|
// Found sync
|
||
|
parser_step = auriol_THDecoderStepReset;
|
||
|
if ((decode_count_bit ==
|
||
|
min_count_bit_for_found) &&
|
||
|
ws_protocol_auriol_th_check()) {
|
||
|
if (callback) callback(this);
|
||
|
parser_step = auriol_THDecoderStepCheckDuration;
|
||
|
}
|
||
|
decode_data = 0;
|
||
|
decode_count_bit = 0;
|
||
|
|
||
|
break;
|
||
|
} else if (
|
||
|
(DURATION_DIFF(te_last, te_short) <
|
||
|
te_delta) &&
|
||
|
(DURATION_DIFF(duration, te_short * 2) <
|
||
|
te_delta)) {
|
||
|
subghz_protocol_blocks_add_bit(0);
|
||
|
parser_step = auriol_THDecoderStepSaveDuration;
|
||
|
} else if (
|
||
|
(DURATION_DIFF(te_last, te_short) <
|
||
|
te_delta) &&
|
||
|
(DURATION_DIFF(duration, te_short * 4) <
|
||
|
te_delta * 2)) {
|
||
|
subghz_protocol_blocks_add_bit(1);
|
||
|
parser_step = auriol_THDecoderStepSaveDuration;
|
||
|
} else {
|
||
|
parser_step = auriol_THDecoderStepReset;
|
||
|
}
|
||
|
} else {
|
||
|
parser_step = auriol_THDecoderStepReset;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
uint32_t te_short = 500;
|
||
|
uint32_t te_long = 2000;
|
||
|
uint32_t te_delta = 150;
|
||
|
uint32_t min_count_bit_for_found = 37;
|
||
|
|
||
|
bool ws_protocol_auriol_th_check() {
|
||
|
uint8_t type = (decode_data >> 8) & 0x0F;
|
||
|
|
||
|
if ((type == AURIOL_TH_CONST_DATA) && ((decode_data >> 4) != 0xffffffff)) {
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
#endif
|