From 86a44366c48298a25adbf7c0e23365ddf974fc14 Mon Sep 17 00:00:00 2001 From: Paul Wieland
Date: Thu, 11 Jul 2024 16:38:47 -0400
Subject: [PATCH] en/dis able emulation mode
change wall panel emulation states from WAITING | ACTIVE to ENABLED | DISABLED.
Add set mode to protocol so the GUI switch can toggle the state between enabled or disabled.
Default mode is disabled. Removed code that watches for a wall panel to simplify.
---
.gitignore | 5 +++
.vscode/settings.json | 75 ++++++++++++++++++++++++++++++++++
components/ratgdo/protocol.h | 4 ++
components/ratgdo/secplus1.cpp | 32 +++++++--------
components/ratgdo/secplus1.h | 7 ++--
5 files changed, 102 insertions(+), 21 deletions(-)
create mode 100644 .gitignore
create mode 100644 .vscode/settings.json
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d8b4157
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+# Gitignore settings for ESPHome
+# This is an example and may include too much for your use-case.
+# You can modify this file to suit your needs.
+/.esphome/
+/secrets.yaml
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..cfeb942
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,75 @@
+{
+ "files.associations": {
+ "__bit_reference": "cpp",
+ "__config": "cpp",
+ "__debug": "cpp",
+ "__errc": "cpp",
+ "__hash_table": "cpp",
+ "__locale": "cpp",
+ "__mutex_base": "cpp",
+ "__node_handle": "cpp",
+ "__split_buffer": "cpp",
+ "__threading_support": "cpp",
+ "__verbose_abort": "cpp",
+ "array": "cpp",
+ "atomic": "cpp",
+ "bitset": "cpp",
+ "cctype": "cpp",
+ "charconv": "cpp",
+ "clocale": "cpp",
+ "cmath": "cpp",
+ "complex": "cpp",
+ "condition_variable": "cpp",
+ "cstdarg": "cpp",
+ "cstddef": "cpp",
+ "cstdint": "cpp",
+ "cstdio": "cpp",
+ "cstdlib": "cpp",
+ "cstring": "cpp",
+ "ctime": "cpp",
+ "cwchar": "cpp",
+ "cwctype": "cpp",
+ "deque": "cpp",
+ "exception": "cpp",
+ "initializer_list": "cpp",
+ "ios": "cpp",
+ "iosfwd": "cpp",
+ "istream": "cpp",
+ "limits": "cpp",
+ "locale": "cpp",
+ "mutex": "cpp",
+ "new": "cpp",
+ "numbers": "cpp",
+ "optional": "cpp",
+ "ostream": "cpp",
+ "queue": "cpp",
+ "ratio": "cpp",
+ "sstream": "cpp",
+ "stdexcept": "cpp",
+ "streambuf": "cpp",
+ "string": "cpp",
+ "string_view": "cpp",
+ "system_error": "cpp",
+ "thread": "cpp",
+ "tuple": "cpp",
+ "typeinfo": "cpp",
+ "unordered_map": "cpp",
+ "variant": "cpp",
+ "vector": "cpp",
+ "algorithm": "cpp",
+ "bit": "cpp",
+ "*.tcc": "cpp",
+ "chrono": "cpp",
+ "compare": "cpp",
+ "concepts": "cpp",
+ "functional": "cpp",
+ "iterator": "cpp",
+ "memory": "cpp",
+ "memory_resource": "cpp",
+ "numeric": "cpp",
+ "random": "cpp",
+ "type_traits": "cpp",
+ "utility": "cpp",
+ "cinttypes": "cpp"
+ }
+}
\ No newline at end of file
diff --git a/components/ratgdo/protocol.h b/components/ratgdo/protocol.h
index ca49aeb..76c62c9 100644
--- a/components/ratgdo/protocol.h
+++ b/components/ratgdo/protocol.h
@@ -58,6 +58,9 @@ namespace ratgdo {
struct SetClientID {
uint64_t client_id;
};
+ struct SetEnableEmulationMode {
+ bool enable_emulation_mode;
+ };
struct QueryStatus {
};
struct QueryOpenings {
@@ -80,6 +83,7 @@ namespace ratgdo {
(SetRollingCodeCounter, set_rolling_code_counter),
(GetRollingCodeCounter, get_rolling_code_counter),
(SetClientID, set_client_id),
+ (SetEnableEmulationMode, set_enable_emulation_mode),
(QueryStatus, query_status),
(QueryOpenings, query_openings),
(ActivateLearn, activate_learn),
diff --git a/components/ratgdo/secplus1.cpp b/components/ratgdo/secplus1.cpp
index ba5caf3..f01b37e 100644
--- a/components/ratgdo/secplus1.cpp
+++ b/components/ratgdo/secplus1.cpp
@@ -35,7 +35,7 @@ namespace ratgdo {
(millis() - this->last_tx_) > 200 && // don't send twice in a period
(millis() - this->last_rx_) > 50 && // time to send it
tx_cmd && // have pending command
- !(this->is_0x37_panel_ && tx_cmd.value() == CommandType::TOGGLE_LOCK_PRESS) && this->wall_panel_emulation_state_ != WallPanelEmulationState::RUNNING) {
+ !(this->is_0x37_panel_ && tx_cmd.value() == CommandType::TOGGLE_LOCK_PRESS) && this->wall_panel_emulation_state_ != WallPanelEmulationState::ENABLED) {
this->do_transmit_if_pending();
}
}
@@ -47,7 +47,6 @@ namespace ratgdo {
void Secplus1::sync()
{
- this->wall_panel_emulation_state_ = WallPanelEmulationState::WAITING;
this->wall_panel_emulation_start_ = millis();
this->door_state = DoorState::UNKNOWN;
this->light_state = LightState::UNKNOWN;
@@ -62,24 +61,17 @@ namespace ratgdo {
});
}
+ void Secplus1::set_enable_emulation_mode(bool state)
+ {
+ this->wall_panel_emulation_state_ = state ? WallPanelEmulationState::ENABLED : WallPanelEmulationState::DISABLED;
+ this->wall_panel_emulation();
+ }
+
void Secplus1::wall_panel_emulation(size_t index)
{
- if (this->wall_panel_emulation_state_ == WallPanelEmulationState::WAITING) {
- ESP_LOG1(TAG, "Looking for security+ 1.0 wall panel...");
-
- if (this->door_state != DoorState::UNKNOWN || this->light_state != LightState::UNKNOWN) {
- ESP_LOG1(TAG, "Wall panel detected");
- return;
- }
- if (millis() - this->wall_panel_emulation_start_ > 35000 && !this->wall_panel_starting_) {
- ESP_LOG1(TAG, "No wall panel detected. Switching to emulation mode.");
- this->wall_panel_emulation_state_ = WallPanelEmulationState::RUNNING;
- }
- this->scheduler_->set_timeout(this->ratgdo_, "wall_panel_emulation", 2000, [=] {
- this->wall_panel_emulation();
- });
- return;
- } else if (this->wall_panel_emulation_state_ == WallPanelEmulationState::RUNNING) {
+ if (this->wall_panel_emulation_state_ == WallPanelEmulationState::DISABLED){
+ ESP_LOGD(TAG, "Emulation mode is disabled");
+ } else if (this->wall_panel_emulation_state_ == WallPanelEmulationState::ENABLED) {
// ESP_LOG2(TAG, "[Wall panel emulation] Sending byte: [%02X]", secplus1_states[index]);
if (index < 15 || !this->do_transmit_if_pending()) {
@@ -205,6 +197,10 @@ namespace ratgdo {
Result Secplus1::call(Args args)
{
+ using Tag = Args::Tag;
+ if (args.tag == Tag::set_enable_emulation_mode) {
+ this->set_enable_emulation_mode(args.value.set_enable_emulation_mode.enable_emulation_mode);
+ }
return {};
}
diff --git a/components/ratgdo/secplus1.h b/components/ratgdo/secplus1.h
index 76e8dc9..f40f2e4 100644
--- a/components/ratgdo/secplus1.h
+++ b/components/ratgdo/secplus1.h
@@ -76,8 +76,8 @@ namespace ratgdo {
};
enum class WallPanelEmulationState {
- WAITING,
- RUNNING,
+ DISABLED,
+ ENABLED,
};
class Secplus1 : public Protocol {
@@ -104,6 +104,7 @@ namespace ratgdo {
protected:
void wall_panel_emulation(size_t index = 0);
+ void set_enable_emulation_mode(bool state);
optional