Reshuffle some code

This commit is contained in:
Marius Muja 2024-01-18 19:08:40 -08:00
parent 181b563b96
commit 794957027a
7 changed files with 55 additions and 58 deletions

View File

@ -1,51 +1,4 @@
#pragma once
#include <cstdint>
#include <functional>
#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<uint32_t>* value; };
SUM_TYPE(Result,
(RollingCodeCounter, rolling_code_counter),
)
} // namespace protocol
} // namespace ratgdo
} // namespace esphome

View File

@ -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_;

View File

@ -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<uint32_t>* 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

View File

@ -171,7 +171,7 @@ namespace ratgdo {
protected:
RATGDOStore isr_store_ {};
Protocol* protocol_;
protocol::Protocol* protocol_;
bool obstruction_from_status_ { false };
InternalGPIOPin* output_gdo_pin_;

View File

@ -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_;

View File

@ -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());
}

View File

@ -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<void()> on_command_sent_;
ProtocolTraits traits_;
Traits traits_;
SoftwareSerial sw_serial_;