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.
This commit is contained in:
parent
01a4a41809
commit
86a44366c4
|
@ -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
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RxCommand> read_command();
|
||||
void handle_command(const RxCommand& cmd);
|
||||
|
@ -138,7 +139,7 @@ namespace ratgdo {
|
|||
|
||||
bool wall_panel_starting_ { false };
|
||||
uint32_t wall_panel_emulation_start_ { 0 };
|
||||
WallPanelEmulationState wall_panel_emulation_state_ { WallPanelEmulationState::WAITING };
|
||||
WallPanelEmulationState wall_panel_emulation_state_ { WallPanelEmulationState::DISABLED };
|
||||
|
||||
bool is_0x37_panel_ { false };
|
||||
std::priority_queue<TxCommand, std::vector<TxCommand>, FirstToSend> pending_tx_;
|
||||
|
|
Loading…
Reference in New Issue