mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 02:28:28 +02:00
Allow 64 bit codes and add nexa remote support. (#662)
* add nexa remote support. This is inspired by: https://github.com/sui77/rc-switch/pull/124 As described there: "The remotes sold in ClasOhlson in scandinavia have a slightly longer sync sequence(added a skip pulse field in the protocol) and a 64 bit code word. Part of the code gets lost but that seems to be OK until support for 64 bit codes is added." * add default value to ctor * allow 64bit codes * lint * make vars 64 bits
This commit is contained in:
committed by
Otto Winter
parent
f4f1164b94
commit
4d31ad3bdc
@@ -18,7 +18,7 @@ class RCSwitchBase {
|
||||
|
||||
void sync(RemoteTransmitData *dst) const;
|
||||
|
||||
void transmit(RemoteTransmitData *dst, uint32_t code, uint8_t len) const;
|
||||
void transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len) const;
|
||||
|
||||
bool expect_one(RemoteReceiveData &src) const;
|
||||
|
||||
@@ -26,20 +26,20 @@ class RCSwitchBase {
|
||||
|
||||
bool expect_sync(RemoteReceiveData &src) const;
|
||||
|
||||
bool decode(RemoteReceiveData &src, uint32_t *out_data, uint8_t *out_nbits) const;
|
||||
bool decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *out_nbits) const;
|
||||
|
||||
static void simple_code_to_tristate(uint16_t code, uint8_t nbits, uint32_t *out_code);
|
||||
static void simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_t *out_code);
|
||||
|
||||
static void type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint32_t *out_code,
|
||||
static void type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code,
|
||||
uint8_t *out_nbits);
|
||||
|
||||
static void type_b_code(uint8_t address_code, uint8_t channel_code, bool state, uint32_t *out_code,
|
||||
static void type_b_code(uint8_t address_code, uint8_t channel_code, bool state, uint64_t *out_code,
|
||||
uint8_t *out_nbits);
|
||||
|
||||
static void type_c_code(uint8_t family, uint8_t group, uint8_t device, bool state, uint32_t *out_code,
|
||||
static void type_c_code(uint8_t family, uint8_t group, uint8_t device, bool state, uint64_t *out_code,
|
||||
uint8_t *out_nbits);
|
||||
|
||||
static void type_d_code(uint8_t group, uint8_t device, bool state, uint32_t *out_code, uint8_t *out_nbits);
|
||||
static void type_d_code(uint8_t group, uint8_t device, bool state, uint64_t *out_code, uint8_t *out_nbits);
|
||||
|
||||
protected:
|
||||
uint32_t sync_high_{};
|
||||
@@ -51,11 +51,11 @@ class RCSwitchBase {
|
||||
bool inverted_{};
|
||||
};
|
||||
|
||||
extern RCSwitchBase rc_switch_protocols[8];
|
||||
extern RCSwitchBase rc_switch_protocols[9];
|
||||
|
||||
uint32_t decode_binary_string(const std::string &data);
|
||||
uint64_t decode_binary_string(const std::string &data);
|
||||
|
||||
uint32_t decode_binary_string_mask(const std::string &data);
|
||||
uint64_t decode_binary_string_mask(const std::string &data);
|
||||
|
||||
template<typename... Ts> class RCSwitchRawAction : public RemoteTransmitterActionBase<Ts...> {
|
||||
public:
|
||||
@@ -64,7 +64,7 @@ template<typename... Ts> class RCSwitchRawAction : public RemoteTransmitterActio
|
||||
|
||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
||||
auto code = this->code_.value(x...);
|
||||
uint32_t the_code = decode_binary_string(code);
|
||||
uint64_t the_code = decode_binary_string(code);
|
||||
uint8_t nbits = code.size();
|
||||
|
||||
auto proto = this->protocol_.value(x...);
|
||||
@@ -86,7 +86,7 @@ template<typename... Ts> class RCSwitchTypeAAction : public RemoteTransmitterAct
|
||||
uint8_t u_group = decode_binary_string(group);
|
||||
uint8_t u_device = decode_binary_string(device);
|
||||
|
||||
uint32_t code;
|
||||
uint64_t code;
|
||||
uint8_t nbits;
|
||||
RCSwitchBase::type_a_code(u_group, u_device, state, &code, &nbits);
|
||||
|
||||
@@ -107,7 +107,7 @@ template<typename... Ts> class RCSwitchTypeBAction : public RemoteTransmitterAct
|
||||
auto channel = this->channel_.value(x...);
|
||||
auto state = this->state_.value(x...);
|
||||
|
||||
uint32_t code;
|
||||
uint64_t code;
|
||||
uint8_t nbits;
|
||||
RCSwitchBase::type_b_code(address, channel, state, &code, &nbits);
|
||||
|
||||
@@ -132,7 +132,7 @@ template<typename... Ts> class RCSwitchTypeCAction : public RemoteTransmitterAct
|
||||
|
||||
auto u_family = static_cast<uint8_t>(tolower(family[0]) - 'a');
|
||||
|
||||
uint32_t code;
|
||||
uint64_t code;
|
||||
uint8_t nbits;
|
||||
RCSwitchBase::type_c_code(u_family, group, device, state, &code, &nbits);
|
||||
|
||||
@@ -154,7 +154,7 @@ template<typename... Ts> class RCSwitchTypeDAction : public RemoteTransmitterAct
|
||||
|
||||
auto u_group = static_cast<uint8_t>(tolower(group[0]) - 'a');
|
||||
|
||||
uint32_t code;
|
||||
uint64_t code;
|
||||
uint8_t nbits;
|
||||
RCSwitchBase::type_d_code(u_group, device, state, &code, &nbits);
|
||||
|
||||
@@ -166,7 +166,7 @@ template<typename... Ts> class RCSwitchTypeDAction : public RemoteTransmitterAct
|
||||
class RCSwitchRawReceiver : public RemoteReceiverBinarySensorBase {
|
||||
public:
|
||||
void set_protocol(const RCSwitchBase &a_protocol) { this->protocol_ = a_protocol; }
|
||||
void set_code(uint32_t code) { this->code_ = code; }
|
||||
void set_code(uint64_t code) { this->code_ = code; }
|
||||
void set_code(const std::string &code) {
|
||||
this->code_ = decode_binary_string(code);
|
||||
this->mask_ = decode_binary_string_mask(code);
|
||||
@@ -194,8 +194,8 @@ class RCSwitchRawReceiver : public RemoteReceiverBinarySensorBase {
|
||||
bool matches(RemoteReceiveData src) override;
|
||||
|
||||
RCSwitchBase protocol_;
|
||||
uint32_t code_;
|
||||
uint32_t mask_{0xFFFFFFFF};
|
||||
uint64_t code_;
|
||||
uint64_t mask_{0xFFFFFFFFFFFFFFFF};
|
||||
uint8_t nbits_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user