diff --git a/components/ratgdo/common.h b/components/ratgdo/common.h index c010a29..1926c22 100644 --- a/components/ratgdo/common.h +++ b/components/ratgdo/common.h @@ -1,51 +1,4 @@ #pragma once -#include -#include -#include "macros.h" -#include "observable.h" #define ESP_LOG1 ESP_LOGD -#define ESP_LOG2 ESP_LOGD - - -namespace esphome { -namespace ratgdo { - -namespace protocol { - -struct SetRollingCodeCounter { uint32_t counter; }; -struct GetRollingCodeCounter {}; -struct SetClientID { uint64_t client_id; }; -struct QueryStatus{}; -struct QueryOpenings{}; -struct ActivateLearn {}; -struct InactivateLearn {}; -struct QueryPairedDevices { PairedDevice kind; }; -struct QueryPairedDevicesAll {}; -struct ClearPairedDevices { PairedDevice kind; }; - - -// a poor man's sum-type, because C++ -SUM_TYPE(Args, - (SetRollingCodeCounter, set_rolling_code_counter), - (GetRollingCodeCounter, get_rolling_code_counter), - (SetClientID, set_client_id), - (QueryStatus, query_status), - (QueryOpenings, query_openings), - (ActivateLearn, activate_learn), - (InactivateLearn, inactivate_learn), - (QueryPairedDevices, query_paired_devices), - (QueryPairedDevicesAll, query_paired_devices_all), - (ClearPairedDevices, clear_paired_devices), -) - - -struct RollingCodeCounter { observable* value; }; - -SUM_TYPE(Result, - (RollingCodeCounter, rolling_code_counter), -) - -} // namespace protocol -} // namespace ratgdo -} // namespace esphome +#define ESP_LOG2 ESP_LOGD \ No newline at end of file diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h index d4c3446..a898aaa 100644 --- a/components/ratgdo/dry_contact.h +++ b/components/ratgdo/dry_contact.h @@ -32,7 +32,11 @@ namespace dry_contact { Result call(Args args); + const Traits& traits() const { return this->traits_; } + protected: + Traits traits_; + InternalGPIOPin* tx_pin_; InternalGPIOPin* rx_pin_; diff --git a/components/ratgdo/protocol.h b/components/ratgdo/protocol.h index 67a91d6..190a777 100644 --- a/components/ratgdo/protocol.h +++ b/components/ratgdo/protocol.h @@ -12,6 +12,8 @@ namespace ratgdo { class RATGDOComponent; +namespace protocol { + 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 @@ -21,11 +23,11 @@ namespace ratgdo { const uint32_t HAS_LOCK_TOGGLE = 1 << 20; - class ProtocolTraits { + class Traits { uint32_t value; public: - ProtocolTraits() + Traits() : value(0) { } @@ -48,6 +50,43 @@ namespace ratgdo { } }; + + + struct SetRollingCodeCounter { uint32_t counter; }; + struct GetRollingCodeCounter {}; + struct SetClientID { uint64_t client_id; }; + struct QueryStatus{}; + struct QueryOpenings{}; + struct ActivateLearn {}; + struct InactivateLearn {}; + struct QueryPairedDevices { PairedDevice kind; }; + struct QueryPairedDevicesAll {}; + struct ClearPairedDevices { PairedDevice kind; }; + + + // a poor man's sum-type, because C++ + SUM_TYPE(Args, + (SetRollingCodeCounter, set_rolling_code_counter), + (GetRollingCodeCounter, get_rolling_code_counter), + (SetClientID, set_client_id), + (QueryStatus, query_status), + (QueryOpenings, query_openings), + (ActivateLearn, activate_learn), + (InactivateLearn, inactivate_learn), + (QueryPairedDevices, query_paired_devices), + (QueryPairedDevicesAll, query_paired_devices_all), + (ClearPairedDevices, clear_paired_devices), + ) + + + struct RollingCodeCounter { observable* value; }; + + SUM_TYPE(Result, + (RollingCodeCounter, rolling_code_counter), + ) + + + class Protocol { public: virtual void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin); @@ -56,7 +95,7 @@ namespace ratgdo { virtual void sync(); - virtual const ProtocolTraits& traits() const; + virtual const Traits& traits() const; virtual void light_action(LightAction action); virtual void lock_action(LockAction action); @@ -65,5 +104,6 @@ namespace ratgdo { virtual protocol::Result call(protocol::Args args); }; +} } // namespace ratgdo } // namespace esphome diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 1e50a86..e0bbc6a 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -171,7 +171,7 @@ namespace ratgdo { protected: RATGDOStore isr_store_ {}; - Protocol* protocol_; + protocol::Protocol* protocol_; bool obstruction_from_status_ { false }; InternalGPIOPin* output_gdo_pin_; diff --git a/components/ratgdo/secplus1.h b/components/ratgdo/secplus1.h index c9812ac..2c7cc3e 100644 --- a/components/ratgdo/secplus1.h +++ b/components/ratgdo/secplus1.h @@ -83,7 +83,7 @@ namespace secplus1 { Result call(Args args); - const ProtocolTraits& traits() const { return this->traits_; } + const Traits& traits() const { return this->traits_; } protected: void wall_panel_emulation(size_t index = 0); @@ -129,7 +129,7 @@ namespace secplus1 { uint32_t last_tx_ { 0 }; uint32_t last_status_query_ { 0 }; - ProtocolTraits traits_; + Traits traits_; SoftwareSerial sw_serial_; diff --git a/components/ratgdo/secplus2.cpp b/components/ratgdo/secplus2.cpp index c15fca8..4b8aaa1 100644 --- a/components/ratgdo/secplus2.cpp +++ b/components/ratgdo/secplus2.cpp @@ -37,7 +37,7 @@ namespace secplus2 { this->sw_serial_.enableIntTx(false); this->sw_serial_.enableAutoBaud(true); - this->traits_.set_features(ProtocolTraits::all()); + this->traits_.set_features(Traits::all()); } diff --git a/components/ratgdo/secplus2.h b/components/ratgdo/secplus2.h index 1f8050c..6530b61 100644 --- a/components/ratgdo/secplus2.h +++ b/components/ratgdo/secplus2.h @@ -30,7 +30,7 @@ namespace secplus2 { (STATUS, 0x081), (OBST_1, 0x084), // sent when an obstruction happens? (OBST_2, 0x085), // sent when an obstruction happens? - (BATTERY_STATUS, 0x9d), + (BATTERY_STATUS, 0x09d), (PAIR_3, 0x0a0), (PAIR_3_RESP, 0x0a1), @@ -91,7 +91,7 @@ namespace secplus2 { Result call(Args args); - const ProtocolTraits& traits() const { return this->traits_; } + const Traits& traits() const { return this->traits_; } protected: void increment_rolling_code_counter(int delta = 1); @@ -129,7 +129,7 @@ namespace secplus2 { WirePacket tx_packet_; OnceCallbacks on_command_sent_; - ProtocolTraits traits_; + Traits traits_; SoftwareSerial sw_serial_;