From 151686f6a31c47400f0a221ea88eaef7d5fb2201 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Jun 2023 18:14:13 -0500 Subject: [PATCH] button --- components/ratgdo/ratgdo.cpp | 138 +++++++++++++---------------------- components/ratgdo/ratgdo.h | 19 +---- 2 files changed, 55 insertions(+), 102 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 7432750..eaabacf 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -284,32 +284,67 @@ namespace ratgdo { void RATGDOComponent::statusUpdateLoop() { - if (this->doorState != this->previousDoorState) - sendDoorStatus(); - this->previousDoorState = this->doorState; - if (this->lightState != this->previousLightState) - sendLightStatus(); - this->previousLightState = this->lightState; - if (this->lockState != this->previousLockState) - sendLockStatus(); - this->previousLockState = this->lockState; - if (this->obstructionState != this->previousObstructionState) - sendObstructionStatus(); - this->previousObstructionState = this->obstructionState; + if (this->doorState != this->previousDoorState) { + DoorState val = static_cast(this->doorState); + ESP_LOGD(TAG, "Door state: %s", door_state_to_string(val)); + for (auto* child : this->children_) { + child->on_door_state(val); + } + this->previousDoorState = this->doorState; + } + if (this->lightState != this->previousLightState) { + LightState val = static_cast(this->lightState); + ESP_LOGD(TAG, "Light state %s (%d)", light_state_to_string(val), this->lightState); + for (auto* child : this->children_) { + child->on_light_state(val); + } + this->previousLightState = this->lightState; + } + if (this->lockState != this->previousLockState) { + LockState val = static_cast(this->lockState); + ESP_LOGD(TAG, "Lock state %s", lock_state_to_string(val)); + for (auto* child : this->children_) { + child->on_lock_state(val); + } + this->previousLockState = this->lockState; + } + if (this->obstructionState != this->previousObstructionState){ + ObstructionState val = static_cast(this->obstructionState); + ESP_LOGD(TAG, "Obstruction state %s", obstruction_state_to_string(val)); + for (auto* child : this->children_) { + child->on_obstruction_state(val); + } + this->previousObstructionState = this->obstructionState; + } if (this->motorState != this->previousMotorState) { - sendMotorStatus(); + MotorState val = static_cast(this->motorState); + ESP_LOGD(TAG, "Motor state %s", motor_state_to_string(val)); + for (auto* child : this->children_) { + child->on_motor_state(val); + } this->previousMotorState = this->motorState; } if (this->motionState == MotionState::MOTION_STATE_DETECTED) { - sendMotionStatus(); + MotionState val = static_cast(this->motionState); + ESP_LOGD(TAG, "Motion state %s", motion_state_to_string(val)); + for (auto* child : this->children_) { + child->on_motion_state(val); + } this->motionState = MotionState::MOTION_STATE_CLEAR; } if (this->buttonState != this->previousButtonState) { - sendButtonStatus(); + ButtonState val = static_cast(this->buttonState); + ESP_LOGD(TAG, "Button state %s", button_state_to_string(val)); + for (auto* child : this->children_) { + child->on_button_state(val); + } this->previousButtonState = this->buttonState; } if (this->openings != this->previousOpenings) { - sendOpenings(); + ESP_LOGD(TAG, "Openings: %d", this->openings); + for (auto* child : this->children_) { + child->on_openings_change(this->openings); + } this->previousOpenings = this->openings; } } @@ -320,77 +355,6 @@ namespace ratgdo { sendCommandAndSaveCounter(Command.REBOOT2); } - void RATGDOComponent::sendOpenings() - { - ESP_LOGD(TAG, "Openings: %d", this->openings); - for (auto* child : this->children_) { - child->on_openings_change(this->openings); - } - } - - void RATGDOComponent::sendDoorStatus() - { - DoorState val = static_cast(this->doorState); - ESP_LOGD(TAG, "Door state: %s", door_state_to_string(val)); - for (auto* child : this->children_) { - child->on_door_state(val); - } - } - - void RATGDOComponent::sendLightStatus() - { - LightState val = static_cast(this->lightState); - ESP_LOGD(TAG, "Light state %s (%d)", light_state_to_string(val), this->lightState); - for (auto* child : this->children_) { - child->on_light_state(val); - } - } - - void RATGDOComponent::sendLockStatus() - { - LockState val = static_cast(this->lockState); - ESP_LOGD(TAG, "Lock state %s", lock_state_to_string(val)); - for (auto* child : this->children_) { - child->on_lock_state(val); - } - } - - void RATGDOComponent::sendMotionStatus() - { - MotionState val = static_cast(this->motionState); - ESP_LOGD(TAG, "Motion state %s", motion_state_to_string(val)); - for (auto* child : this->children_) { - child->on_motion_state(val); - } - } - - void RATGDOComponent::sendButtonStatus() - { - ButtonState val = static_cast(this->buttonState); - ESP_LOGD(TAG, "Button state %s", button_state_to_string(val)); - for (auto* child : this->children_) { - child->on_button_state(val); - } - } - - void RATGDOComponent::sendMotorStatus() - { - MotorState val = static_cast(this->motorState); - ESP_LOGD(TAG, "Motor state %s", motor_state_to_string(val)); - for (auto* child : this->children_) { - child->on_motor_state(val); - } - } - - void RATGDOComponent::sendObstructionStatus() - { - ObstructionState val = static_cast(this->obstructionState); - ESP_LOGD(TAG, "Obstruction state %s", obstruction_state_to_string(val)); - for (auto* child : this->children_) { - child->on_obstruction_state(val); - } - } - /************************* DOOR COMMUNICATION *************************/ /* * Transmit a message to the door opener over uart1 diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 7045624..bc8cf4a 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -113,36 +113,26 @@ namespace ratgdo { void transmit(cmd command); void sync(); + void gdoStateLoop(); void obstructionLoop(); - void sendObstructionStatus(); - - void sendOpenings(); + void statusUpdateLoop(); + void sendCommandAndSaveCounter(cmd command); void toggleDoor(); void openDoor(); void closeDoor(); void stopDoor(); - void sendDoorStatus(); - void toggleLight(); void lightOn(); void lightOff(); bool isLightOn(); - void sendLightStatus(); - void toggleLock(); void lock(); void unlock(); - void sendLockStatus(); - void sendButtonStatus(); - void sendMotionStatus(); - void sendMotorStatus(); void query(); - void doorStateLoop(); + void printRollingCode(); void getRollingCode(cmd command); - void gdoStateLoop(); - void statusUpdateLoop(); void readRollingCode( bool& isStatus, uint8_t& door, @@ -156,7 +146,6 @@ namespace ratgdo { void incrementRollingCodeCounter(); void sendRollingCodeChanged(); void setRollingCodeCounter(uint32_t counter); - void sendCommandAndSaveCounter(cmd command); LightState getLightState(); /** Register a child component. */ void register_child(RATGDOClient* obj);