This commit is contained in:
J. Nick Koston 2023-06-09 18:14:13 -05:00
parent e9c110c1fe
commit 151686f6a3
No known key found for this signature in database
2 changed files with 55 additions and 102 deletions

View File

@ -284,32 +284,67 @@ namespace ratgdo {
void RATGDOComponent::statusUpdateLoop()
{
if (this->doorState != this->previousDoorState)
sendDoorStatus();
if (this->doorState != this->previousDoorState) {
DoorState val = static_cast<DoorState>(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)
sendLightStatus();
}
if (this->lightState != this->previousLightState) {
LightState val = static_cast<LightState>(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)
sendLockStatus();
}
if (this->lockState != this->previousLockState) {
LockState val = static_cast<LockState>(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)
sendObstructionStatus();
}
if (this->obstructionState != this->previousObstructionState){
ObstructionState val = static_cast<ObstructionState>(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<MotorState>(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<MotionState>(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<ButtonState>(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<DoorState>(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<LightState>(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<LockState>(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<MotionState>(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<ButtonState>(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<MotorState>(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<ObstructionState>(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

View File

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