Added protocol traits
This commit is contained in:
parent
a52fccc1c6
commit
9a4cfe3c56
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ratgdo_state.h"
|
||||
#include "common.h"
|
||||
#include "ratgdo_state.h"
|
||||
|
||||
namespace esphome {
|
||||
|
||||
|
@ -12,6 +12,42 @@ namespace ratgdo {
|
|||
|
||||
class RATGDOComponent;
|
||||
|
||||
const uint32_t HAS_DOOR_OPEN = 1 << 0; // has idempotent open door command
|
||||
const uint32_t HAS_DOOR_CLOSE = 1 << 1; // has idempotent close door command
|
||||
const uint32_t HAS_DOOR_STOP = 1 << 2; // has idempotent stop door command
|
||||
const uint32_t HAS_DOOR_STATUS = 1 << 3;
|
||||
|
||||
const uint32_t HAS_LIGHT_TOGGLE = 1 << 10; // some protocols might not support this
|
||||
|
||||
const uint32_t HAS_LOCK_TOGGLE = 1 << 20;
|
||||
|
||||
class ProtocolTraits {
|
||||
uint32_t value;
|
||||
|
||||
public:
|
||||
ProtocolTraits()
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool has_door_open() const { return this->value & HAS_DOOR_OPEN; }
|
||||
bool has_door_close() const { return this->value & HAS_DOOR_CLOSE; }
|
||||
bool has_door_stop() const { return this->value & HAS_DOOR_STOP; }
|
||||
bool has_door_status() const { return this->value & HAS_DOOR_STATUS; }
|
||||
|
||||
bool has_light_toggle() const { return this->value & HAS_LIGHT_TOGGLE; }
|
||||
|
||||
bool has_lock_toggle() const { return this->value & HAS_LOCK_TOGGLE; }
|
||||
|
||||
void set_features(uint32_t feature) { this->value |= feature; }
|
||||
void clear_features(uint32_t feature) { this->value &= ~feature; }
|
||||
|
||||
static uint32_t all()
|
||||
{
|
||||
return HAS_DOOR_CLOSE | HAS_DOOR_OPEN | HAS_DOOR_STOP | HAS_DOOR_STATUS | HAS_LIGHT_TOGGLE | HAS_LOCK_TOGGLE;
|
||||
}
|
||||
};
|
||||
|
||||
class Protocol {
|
||||
public:
|
||||
virtual void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin);
|
||||
|
@ -20,12 +56,14 @@ namespace ratgdo {
|
|||
|
||||
virtual void sync();
|
||||
|
||||
virtual const ProtocolTraits& traits() const;
|
||||
|
||||
virtual void light_action(LightAction action);
|
||||
virtual void lock_action(LockAction action);
|
||||
virtual void door_action(DoorAction action);
|
||||
|
||||
virtual protocol::Result call(protocol::Args args);
|
||||
};
|
||||
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -538,12 +538,11 @@ namespace ratgdo {
|
|||
|
||||
this->door_action(delta > 0 ? DoorAction::OPEN : DoorAction::CLOSE);
|
||||
set_timeout("move_to_position", operation_time, [=] {
|
||||
#ifdef PROTOCOL_SECPLUSV2
|
||||
this->ensure_door_action(DoorAction::STOP);
|
||||
#else
|
||||
// STOP command is idempotent only on sec+2, don't use ensure_door_action otherwise
|
||||
this->door_action(DoorAction::STOP);
|
||||
#endif
|
||||
if (this->protocol_->traits().has_door_stop()) {
|
||||
this->ensure_door_action(DoorAction::STOP);
|
||||
} else {
|
||||
this->door_action(DoorAction::STOP);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ namespace secplus1 {
|
|||
this->rx_pin_ = rx_pin;
|
||||
|
||||
this->sw_serial_.begin(1200, SWSERIAL_8E1, rx_pin->get_pin(), tx_pin->get_pin(), true);
|
||||
|
||||
|
||||
this->traits_.set_features(HAS_DOOR_STATUS | HAS_LIGHT_TOGGLE | HAS_LOCK_TOGGLE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@ namespace secplus1 {
|
|||
|
||||
Result call(Args args);
|
||||
|
||||
const ProtocolTraits& traits() const { return this->traits_; }
|
||||
|
||||
protected:
|
||||
void wall_panel_emulation(size_t index = 0);
|
||||
|
||||
|
@ -125,6 +127,8 @@ namespace secplus1 {
|
|||
uint32_t last_tx_ { 0 };
|
||||
uint32_t last_status_query_ { 0 };
|
||||
|
||||
ProtocolTraits traits_;
|
||||
|
||||
SoftwareSerial sw_serial_;
|
||||
|
||||
InternalGPIOPin* tx_pin_;
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace secplus2 {
|
|||
this->sw_serial_.begin(9600, SWSERIAL_8N1, rx_pin->get_pin(), tx_pin->get_pin(), true);
|
||||
this->sw_serial_.enableIntTx(false);
|
||||
this->sw_serial_.enableAutoBaud(true);
|
||||
|
||||
this->traits_.set_features(ProtocolTraits::all());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,11 +91,13 @@ namespace secplus2 {
|
|||
|
||||
Result call(Args args);
|
||||
|
||||
const ProtocolTraits& traits() const { return this->traits_; }
|
||||
|
||||
protected:
|
||||
void increment_rolling_code_counter(int delta = 1);
|
||||
void set_rolling_code_counter(uint32_t counter);
|
||||
void set_client_id(uint64_t client_id);
|
||||
|
||||
protected:
|
||||
optional<Command> read_command();
|
||||
void handle_command(const Command& cmd);
|
||||
|
||||
|
@ -128,6 +130,8 @@ namespace secplus2 {
|
|||
WirePacket tx_packet_;
|
||||
OnceCallbacks<void()> command_sent_;
|
||||
|
||||
ProtocolTraits traits_;
|
||||
|
||||
SoftwareSerial sw_serial_;
|
||||
|
||||
InternalGPIOPin* tx_pin_;
|
||||
|
|
Loading…
Reference in New Issue