mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-11 17:19:29 +00:00
WIP, Weather refactor, UI improv
This commit is contained in:
@@ -100,18 +100,13 @@ class FProtoSubGhzDAnsonic : public FProtoSubGhzDBase {
|
||||
cnt = data & 0xFFF;
|
||||
btn = ((data >> 1) & 0x3);
|
||||
}
|
||||
void get_string(char* output, size_t outSize) {
|
||||
void get_string(std::string& output) {
|
||||
subghz_protocol_ansonic_check_remote_controller();
|
||||
snprintf(
|
||||
output, outSize,
|
||||
"%dbit\r\n"
|
||||
"Key:%03lX\r\n"
|
||||
"Btn:%X\r\n"
|
||||
"DIP:" ANSONICDIP_PATTERN "\r\n",
|
||||
data_count_bit,
|
||||
(uint32_t)(data & 0xFFFFFFFF),
|
||||
btn,
|
||||
ANSONICCNT_TO_DIP(cnt));
|
||||
|
||||
/* output = to_string_dec_uint(data_count_bit) + " bit\r\n";
|
||||
output += "Key: " + to_string_hex((uint32_t)(data & 0xFFFFFFFF)) + "\r\n";
|
||||
output += "BTN: " + to_string_dec_uint(btn) + "\r\n";
|
||||
output += "DIP: " + ANSONICCNT_TO_DIP(cnt) + "\r\n";*/
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
|
||||
#ifndef __FPROTO_PRINCETON_H__
|
||||
#define __FPROTO_PRINCETON_H__
|
||||
|
||||
#include "subghzdbase.hpp"
|
||||
|
||||
typedef enum {
|
||||
PrincetonDecoderStepReset = 0,
|
||||
PrincetonDecoderStepSaveDuration,
|
||||
PrincetonDecoderStepCheckDuration,
|
||||
} PrincetonDecoderStep;
|
||||
|
||||
class FProtoSubGhzDPrinceton : public FProtoSubGhzDBase {
|
||||
public:
|
||||
FProtoSubGhzDPrinceton() {
|
||||
sensorType = FPS_ANSONIC;
|
||||
}
|
||||
|
||||
void feed(bool level, uint32_t duration) {
|
||||
switch (parser_step) {
|
||||
case PrincetonDecoderStepReset:
|
||||
if ((!level) && (DURATION_DIFF(duration, te_short * 36) < te_delta * 36)) {
|
||||
// Found Preambula
|
||||
parser_step = PrincetonDecoderStepSaveDuration;
|
||||
decode_data = 0;
|
||||
decode_count_bit = 0;
|
||||
te = 0;
|
||||
}
|
||||
break;
|
||||
case PrincetonDecoderStepSaveDuration:
|
||||
// save duration
|
||||
if (level) {
|
||||
te_last = duration;
|
||||
te += duration;
|
||||
parser_step = PrincetonDecoderStepCheckDuration;
|
||||
}
|
||||
break;
|
||||
case PrincetonDecoderStepCheckDuration:
|
||||
if (!level) {
|
||||
if (duration >= ((uint32_t)te_long * 2)) {
|
||||
parser_step = PrincetonDecoderStepSaveDuration;
|
||||
if (decode_count_bit ==
|
||||
min_count_bit_for_found) {
|
||||
if ((last_data == decode_data) &&
|
||||
last_data) {
|
||||
te /= (decode_count_bit * 4 + 1);
|
||||
|
||||
data = decode_data;
|
||||
data_count_bit = decode_count_bit;
|
||||
|
||||
if (callback) callback(this);
|
||||
}
|
||||
last_data = decode_data;
|
||||
}
|
||||
decode_data = 0;
|
||||
decode_count_bit = 0;
|
||||
te = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
te += duration;
|
||||
|
||||
if ((DURATION_DIFF(te_last, te_short) <
|
||||
te_delta) &&
|
||||
(DURATION_DIFF(duration, te_long) <
|
||||
te_delta * 3)) {
|
||||
subghz_protocol_blocks_add_bit(0);
|
||||
parser_step = PrincetonDecoderStepSaveDuration;
|
||||
} else if (
|
||||
(DURATION_DIFF(te_last, te_long) <
|
||||
te_delta * 3) &&
|
||||
(DURATION_DIFF(duration, te_short) <
|
||||
te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(1);
|
||||
parser_step = PrincetonDecoderStepSaveDuration;
|
||||
} else {
|
||||
parser_step = PrincetonDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
parser_step = PrincetonDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
void subghz_protocol_princeton_check_remote_controller() {
|
||||
serial = data >> 4;
|
||||
btn = data & 0xF;
|
||||
}
|
||||
void get_string(std::string& output) {
|
||||
subghz_protocol_princeton_check_remote_controller();
|
||||
uint32_t data_rev = FProtoGeneral::subghz_protocol_blocks_reverse_key(data, data_count_bit);
|
||||
|
||||
/* output = to_string_dec_uint(data_count_bit) + " bit\r\n";
|
||||
output += "Key: " + to_string_hex((uint32_t)(data & 0xFFFFFF)) + "\r\n";
|
||||
output += "Yek: " + to_string_hex(data_rev) + "\r\n";
|
||||
output += "SN: " + to_string_dec_uint(serial) + "\r\n";
|
||||
output += "BTN: " + to_string_dec_uint(btn) + "\r\n";
|
||||
output += "TE: " + to_string_dec_uint(te) + "\r\n"; */
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32_t te_short = 390;
|
||||
uint32_t te_long = 1170;
|
||||
uint32_t te_delta = 300;
|
||||
uint32_t min_count_bit_for_found = 24;
|
||||
|
||||
uint32_t te = 0;
|
||||
uint32_t last_data = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,7 @@ For comments in a protocol implementation check w-nexus-th.hpp
|
||||
#include "subghztypes.hpp"
|
||||
|
||||
#include <string>
|
||||
// default walues to indicate 'no value'
|
||||
// default values to indicate 'no value'
|
||||
#define SD_NO_ID 0xFFFFFFFF
|
||||
|
||||
class FProtoSubGhzDBase;
|
||||
@@ -23,10 +23,10 @@ class FProtoSubGhzDBase {
|
||||
virtual ~FProtoSubGhzDBase() {}
|
||||
virtual void feed(bool level, uint32_t duration) = 0; // need to be implemented on each protocol handler.
|
||||
void setCallback(SubGhzDProtocolDecoderBaseRxCallback cb) { callback = cb; } // this is called when there is a hit.
|
||||
|
||||
virtual void get_string(std::string& output) = 0;
|
||||
uint8_t getSensorType() { return sensorType; }
|
||||
uint32_t getSensorId() { return id; }
|
||||
FPROTO_SUBGHZD_MODULATION modulation = FPM_AM; // override this, if FM
|
||||
uint8_t modulation = FPM_AM; // override this, if FM
|
||||
protected:
|
||||
// Helper functions to keep it as compatible with flipper as we can, so adding new protos will be easy.
|
||||
void subghz_protocol_blocks_add_bit(uint8_t bit) {
|
||||
|
||||
@@ -11,6 +11,7 @@ So include here the .hpp, and add a new element to the protos vector in the cons
|
||||
#include "fprotolistgeneral.hpp"
|
||||
#include "subghzdbase.hpp"
|
||||
#include "s-ansonic.hpp"
|
||||
#include "s-princeton.hpp"
|
||||
|
||||
#ifndef __FPROTO_PROTOLISTSGZ_H__
|
||||
#define __FPROTO_PROTOLISTSGZ_H__
|
||||
@@ -19,7 +20,8 @@ class SubGhzDProtos : public FProtoListGeneral {
|
||||
public:
|
||||
SubGhzDProtos() {
|
||||
// add protos
|
||||
protos.push_back(std::make_unique<FProtoSubGhzDAnsonic>()); // 1
|
||||
protos.push_back(std::make_unique<FProtoSubGhzDAnsonic>()); // 1
|
||||
protos.push_back(std::make_unique<FProtoSubGhzDPrinceton>()); // 2
|
||||
|
||||
// set callback for them
|
||||
for (const auto& obj : protos) {
|
||||
|
||||
@@ -4,18 +4,17 @@
|
||||
|
||||
/*
|
||||
Define known protocols.
|
||||
These values must be present on the protocol's constructor, like FProtoWeatherAcurite592TXR() { sensorType = FPW_Acurite592TXR; }
|
||||
These values must be present on the protocol's constructor, like FProtoWeatherAcurite592TXR() { sensorType = FPS_ANSONIC; }
|
||||
Also it must have a switch-case element in the getSubGhzDSensorTypeName() function, to display it's name.
|
||||
*/
|
||||
|
||||
enum FPROTO_SUBGHZD_MODULATION {
|
||||
FPM_AM = 0,
|
||||
FPM_FM = 1,
|
||||
};
|
||||
#define FPM_AM 0
|
||||
#define FPM_FM 1
|
||||
|
||||
enum FPROTO_SUBGHZD_SENSOR {
|
||||
FPS_Invalid = 0,
|
||||
FPS_ANSONIC = 1,
|
||||
FPS_PRINCETON = 2,
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -12,12 +12,6 @@ For comments in a protocol implementation check w-nexus-th.hpp
|
||||
|
||||
#include <string>
|
||||
// default walues to indicate 'no value'
|
||||
#define WS_NO_ID 0xFFFFFFFF
|
||||
#define WS_NO_BATT 0xFF
|
||||
#define WS_NO_HUMIDITY 0xFF
|
||||
#define WS_NO_CHANNEL 0xFF
|
||||
#define WS_NO_BTN 0xFF
|
||||
#define WS_NO_TEMPERATURE -273.0f
|
||||
|
||||
class FProtoWeatherBase;
|
||||
typedef void (*SubGhzProtocolDecoderBaseRxCallback)(FProtoWeatherBase* instance);
|
||||
|
||||
@@ -7,6 +7,12 @@ Define known protocols.
|
||||
These values must be present on the protocol's constructor, like FProtoWeatherAcurite592TXR() { sensorType = FPW_Acurite592TXR; }
|
||||
Also it must have a switch-case element in the getWeatherSensorTypeName() function, to display it's name.
|
||||
*/
|
||||
#define WS_NO_ID 0xFFFFFFFF
|
||||
#define WS_NO_BATT 0xFF
|
||||
#define WS_NO_HUMIDITY 0xFF
|
||||
#define WS_NO_CHANNEL 0xFF
|
||||
#define WS_NO_BTN 0xFF
|
||||
#define WS_NO_TEMPERATURE -273.0f
|
||||
|
||||
enum FPROTO_WEATHER_SENSOR {
|
||||
FPW_Invalid = 0,
|
||||
|
||||
Reference in New Issue
Block a user