mirror of
https://github.com/ratgdo/esphome-ratgdo.git
synced 2025-03-03 04:19:56 +00:00
Added protocol traits
This commit is contained in:
parent
a52fccc1c6
commit
9a4cfe3c56
components/ratgdo
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ratgdo_state.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "ratgdo_state.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
@ -12,6 +12,42 @@ namespace ratgdo {
|
|||||||
|
|
||||||
class RATGDOComponent;
|
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 {
|
class Protocol {
|
||||||
public:
|
public:
|
||||||
virtual void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin);
|
virtual void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin);
|
||||||
@ -20,12 +56,14 @@ namespace ratgdo {
|
|||||||
|
|
||||||
virtual void sync();
|
virtual void sync();
|
||||||
|
|
||||||
|
virtual const ProtocolTraits& traits() const;
|
||||||
|
|
||||||
virtual void light_action(LightAction action);
|
virtual void light_action(LightAction action);
|
||||||
virtual void lock_action(LockAction action);
|
virtual void lock_action(LockAction action);
|
||||||
virtual void door_action(DoorAction action);
|
virtual void door_action(DoorAction action);
|
||||||
|
|
||||||
virtual protocol::Result call(protocol::Args args);
|
virtual protocol::Result call(protocol::Args args);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ratgdo
|
} // namespace ratgdo
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
@ -538,12 +538,11 @@ namespace ratgdo {
|
|||||||
|
|
||||||
this->door_action(delta > 0 ? DoorAction::OPEN : DoorAction::CLOSE);
|
this->door_action(delta > 0 ? DoorAction::OPEN : DoorAction::CLOSE);
|
||||||
set_timeout("move_to_position", operation_time, [=] {
|
set_timeout("move_to_position", operation_time, [=] {
|
||||||
#ifdef PROTOCOL_SECPLUSV2
|
if (this->protocol_->traits().has_door_stop()) {
|
||||||
this->ensure_door_action(DoorAction::STOP);
|
this->ensure_door_action(DoorAction::STOP);
|
||||||
#else
|
} else {
|
||||||
// STOP command is idempotent only on sec+2, don't use ensure_door_action otherwise
|
this->door_action(DoorAction::STOP);
|
||||||
this->door_action(DoorAction::STOP);
|
}
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ namespace secplus1 {
|
|||||||
this->rx_pin_ = rx_pin;
|
this->rx_pin_ = rx_pin;
|
||||||
|
|
||||||
this->sw_serial_.begin(1200, SWSERIAL_8E1, rx_pin->get_pin(), tx_pin->get_pin(), true);
|
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);
|
Result call(Args args);
|
||||||
|
|
||||||
|
const ProtocolTraits& traits() const { return this->traits_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void wall_panel_emulation(size_t index = 0);
|
void wall_panel_emulation(size_t index = 0);
|
||||||
|
|
||||||
@ -125,6 +127,8 @@ namespace secplus1 {
|
|||||||
uint32_t last_tx_ { 0 };
|
uint32_t last_tx_ { 0 };
|
||||||
uint32_t last_status_query_ { 0 };
|
uint32_t last_status_query_ { 0 };
|
||||||
|
|
||||||
|
ProtocolTraits traits_;
|
||||||
|
|
||||||
SoftwareSerial sw_serial_;
|
SoftwareSerial sw_serial_;
|
||||||
|
|
||||||
InternalGPIOPin* tx_pin_;
|
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_.begin(9600, SWSERIAL_8N1, rx_pin->get_pin(), tx_pin->get_pin(), true);
|
||||||
this->sw_serial_.enableIntTx(false);
|
this->sw_serial_.enableIntTx(false);
|
||||||
this->sw_serial_.enableAutoBaud(true);
|
this->sw_serial_.enableAutoBaud(true);
|
||||||
|
|
||||||
|
this->traits_.set_features(ProtocolTraits::all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,11 +91,13 @@ namespace secplus2 {
|
|||||||
|
|
||||||
Result call(Args args);
|
Result call(Args args);
|
||||||
|
|
||||||
|
const ProtocolTraits& traits() const { return this->traits_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
void increment_rolling_code_counter(int delta = 1);
|
void increment_rolling_code_counter(int delta = 1);
|
||||||
void set_rolling_code_counter(uint32_t counter);
|
void set_rolling_code_counter(uint32_t counter);
|
||||||
void set_client_id(uint64_t client_id);
|
void set_client_id(uint64_t client_id);
|
||||||
|
|
||||||
protected:
|
|
||||||
optional<Command> read_command();
|
optional<Command> read_command();
|
||||||
void handle_command(const Command& cmd);
|
void handle_command(const Command& cmd);
|
||||||
|
|
||||||
@ -128,6 +130,8 @@ namespace secplus2 {
|
|||||||
WirePacket tx_packet_;
|
WirePacket tx_packet_;
|
||||||
OnceCallbacks<void()> command_sent_;
|
OnceCallbacks<void()> command_sent_;
|
||||||
|
|
||||||
|
ProtocolTraits traits_;
|
||||||
|
|
||||||
SoftwareSerial sw_serial_;
|
SoftwareSerial sw_serial_;
|
||||||
|
|
||||||
InternalGPIOPin* tx_pin_;
|
InternalGPIOPin* tx_pin_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user