This commit is contained in:
J. Nick Koston 2023-06-07 19:20:32 -05:00
parent 9d7f521b6b
commit 1db1934b98
No known key found for this signature in database
2 changed files with 34 additions and 34 deletions

View File

@ -412,31 +412,31 @@ namespace ratgdo {
msgStart = 0; msgStart = 0;
byteCount = 0; byteCount = 0;
readRollingCode(this->store_.doorState, this->store_.lightState, this->store_.lockState, this->store_.motionState, this->store_.obstructionState); readRollingCode(this->doorState, this->lightState, this->lockState, this->motionState, this->obstructionState);
} }
} }
} }
void RATGDOComponent::statusUpdateLoop() void RATGDOComponent::statusUpdateLoop()
{ {
if (this->store_.doorState != this->previousDoorState) if (this->doorState != this->previousDoorState)
sendDoorStatus(); sendDoorStatus();
if (this->store_.lightState != this->previousLightState) if (this->lightState != this->previousLightState)
sendLightStatus(); sendLightStatus();
if (this->store_.lockState != this->previousLockState) if (this->lockState != this->previousLockState)
sendLockStatus(); sendLockStatus();
if (this->store_.obstructionState != this->previousObstructionState) if (this->obstructionState != this->previousObstructionState)
sendObstructionStatus(); sendObstructionStatus();
if (this->store_.motionState == MotionState::MOTION_STATE_DETECTED) { if (this->motionState == MotionState::MOTION_STATE_DETECTED) {
sendMotionStatus(); sendMotionStatus();
this->store_.motionState = MotionState::MOTION_STATE_CLEAR; this->motionState = MotionState::MOTION_STATE_CLEAR;
} }
this->previousDoorState = this->store_.doorState; this->previousDoorState = this->doorState;
this->previousLightState = this->store_.lightState; this->previousLightState = this->lightState;
this->previousLockState = this->store_.lockState; this->previousLockState = this->lockState;
this->previousObstructionState = this->store_.obstructionState; this->previousObstructionState = this->obstructionState;
} }
void RATGDOComponent::query() void RATGDOComponent::query()
@ -449,18 +449,18 @@ namespace ratgdo {
void RATGDOComponent::sendDoorStatus() void RATGDOComponent::sendDoorStatus()
{ {
DoorState val = static_cast<DoorState>(this->store_.doorState); DoorState val = static_cast<DoorState>(this->doorState);
ESP_LOGD(TAG, "Door state: %s", door_state_to_string(val)); ESP_LOGD(TAG, "Door state: %s", door_state_to_string(val));
for (auto* child : this->children_) { for (auto* child : this->children_) {
child->on_door_state(val); child->on_door_state(val);
} }
this->status_door_pin_->digital_write(this->store_.doorState == 1); this->status_door_pin_->digital_write(this->doorState == 1);
} }
void RATGDOComponent::sendLightStatus() void RATGDOComponent::sendLightStatus()
{ {
LightState val = static_cast<LightState>(this->store_.lightState); LightState val = static_cast<LightState>(this->lightState);
ESP_LOGD(TAG, "Light state %s (%d)", light_state_to_string(val), this->store_.lightState); ESP_LOGD(TAG, "Light state %s (%d)", light_state_to_string(val), this->lightState);
for (auto* child : this->children_) { for (auto* child : this->children_) {
child->on_light_state(val); child->on_light_state(val);
} }
@ -468,7 +468,7 @@ namespace ratgdo {
void RATGDOComponent::sendLockStatus() void RATGDOComponent::sendLockStatus()
{ {
LockState val = static_cast<LockState>(this->store_.lockState); LockState val = static_cast<LockState>(this->lockState);
ESP_LOGD(TAG, "Lock state %s", lock_state_to_string(val)); ESP_LOGD(TAG, "Lock state %s", lock_state_to_string(val));
for (auto* child : this->children_) { for (auto* child : this->children_) {
child->on_lock_state(val); child->on_lock_state(val);
@ -477,7 +477,7 @@ namespace ratgdo {
void RATGDOComponent::sendMotionStatus() void RATGDOComponent::sendMotionStatus()
{ {
MotionState val = static_cast<MotionState>(this->store_.motionState); MotionState val = static_cast<MotionState>(this->motionState);
ESP_LOGD(TAG, "Motion state %s", motion_state_to_string(val)); ESP_LOGD(TAG, "Motion state %s", motion_state_to_string(val));
for (auto* child : this->children_) { for (auto* child : this->children_) {
child->on_motion_state(val); child->on_motion_state(val);
@ -486,12 +486,12 @@ namespace ratgdo {
void RATGDOComponent::sendObstructionStatus() void RATGDOComponent::sendObstructionStatus()
{ {
ObstructionState val = static_cast<ObstructionState>(this->store_.obstructionState); ObstructionState val = static_cast<ObstructionState>(this->obstructionState);
ESP_LOGD(TAG, "Obstruction state %s", obstruction_state_to_string(val)); ESP_LOGD(TAG, "Obstruction state %s", obstruction_state_to_string(val));
for (auto* child : this->children_) { for (auto* child : this->children_) {
child->on_obstruction_state(val); child->on_obstruction_state(val);
} }
this->status_obst_pin_->digital_write(this->store_.obstructionState == 0); this->status_obst_pin_->digital_write(this->obstructionState == 0);
} }
/************************* DOOR COMMUNICATION *************************/ /************************* DOOR COMMUNICATION *************************/
@ -538,8 +538,8 @@ namespace ratgdo {
void RATGDOComponent::openDoor() void RATGDOComponent::openDoor()
{ {
if (this->store_.doorState == DoorState::DOOR_STATE_OPEN || this->store_.doorState == DoorState::DOOR_STATE_OPENING) { if (this->doorState == DoorState::DOOR_STATE_OPEN || this->doorState == DoorState::DOOR_STATE_OPENING) {
ESP_LOGD(TAG, "The door is already %s", door_state_to_string(static_cast<DoorState>(this->store_.doorState))); ESP_LOGD(TAG, "The door is already %s", door_state_to_string(static_cast<DoorState>(this->doorState)));
return; return;
} }
toggleDoor(); toggleDoor();
@ -547,8 +547,8 @@ namespace ratgdo {
void RATGDOComponent::closeDoor() void RATGDOComponent::closeDoor()
{ {
if (this->store_.doorState == DoorState::DOOR_STATE_CLOSED || this->store_.doorState == DoorState::DOOR_STATE_CLOSING) { if (this->doorState == DoorState::DOOR_STATE_CLOSED || this->doorState == DoorState::DOOR_STATE_CLOSING) {
ESP_LOGD(TAG, "The door is already %s", door_state_to_string(static_cast<DoorState>(this->store_.doorState))); ESP_LOGD(TAG, "The door is already %s", door_state_to_string(static_cast<DoorState>(this->doorState)));
return; return;
} }
toggleDoor(); toggleDoor();
@ -556,7 +556,7 @@ namespace ratgdo {
void RATGDOComponent::stopDoor() void RATGDOComponent::stopDoor()
{ {
if (this->store_.doorState == DoorState::DOOR_STATE_OPENING || this->store_.doorState == DoorState::DOOR_STATE_CLOSING) { if (this->doorState == DoorState::DOOR_STATE_OPENING || this->doorState == DoorState::DOOR_STATE_CLOSING) {
toggleDoor(); toggleDoor();
} else { } else {
ESP_LOGD(TAG, "The door is not moving."); ESP_LOGD(TAG, "The door is not moving.");
@ -572,7 +572,7 @@ namespace ratgdo {
void RATGDOComponent::lightOn() void RATGDOComponent::lightOn()
{ {
if (this->store_.lightState == LightState::LIGHT_STATE_ON) { if (this->lightState == LightState::LIGHT_STATE_ON) {
ESP_LOGD(TAG, "The light is already on"); ESP_LOGD(TAG, "The light is already on");
} else { } else {
toggleLight(); toggleLight();
@ -581,7 +581,7 @@ namespace ratgdo {
void RATGDOComponent::lightOff() void RATGDOComponent::lightOff()
{ {
if (this->store_.lightState == LightState::LIGHT_STATE_OFF) { if (this->lightState == LightState::LIGHT_STATE_OFF) {
ESP_LOGD(TAG, "The light is already off"); ESP_LOGD(TAG, "The light is already off");
} else { } else {
toggleLight(); toggleLight();
@ -596,7 +596,7 @@ namespace ratgdo {
// Lock functions // Lock functions
void RATGDOComponent::lock() void RATGDOComponent::lock()
{ {
if (this->store_.lockState == LockState::LOCK_STATE_LOCKED) { if (this->lockState == LockState::LOCK_STATE_LOCKED) {
ESP_LOGD(TAG, "already locked"); ESP_LOGD(TAG, "already locked");
} else { } else {
toggleLock(); toggleLock();
@ -605,7 +605,7 @@ namespace ratgdo {
void RATGDOComponent::unlock() void RATGDOComponent::unlock()
{ {
if (this->store_.lockState == LockState::LOCK_STATE_UNLOCKED) { if (this->lockState == LockState::LOCK_STATE_UNLOCKED) {
ESP_LOGD(TAG, "already unlocked"); ESP_LOGD(TAG, "already unlocked");
} else { } else {
toggleLock(); toggleLock();

View File

@ -59,12 +59,6 @@ namespace ratgdo {
int obstructionLowCount = 0; // count obstruction low pulses int obstructionLowCount = 0; // count obstruction low pulses
long lastObstructionHigh = 0; // count time between high pulses from the obst ISR long lastObstructionHigh = 0; // count time between high pulses from the obst ISR
uint8_t obstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN };
uint8_t motionState { MotionState::MOTION_STATE_CLEAR };
uint8_t lockState { LockState::LOCK_STATE_UNKNOWN };
uint8_t lightState { LightState::LIGHT_STATE_UNKNOWN };
uint8_t doorState { DoorState::DOOR_STATE_UNKNOWN };
static void IRAM_ATTR isrDoorOpen(RATGDOStore* arg); static void IRAM_ATTR isrDoorOpen(RATGDOStore* arg);
static void IRAM_ATTR isrDoorClose(RATGDOStore* arg); static void IRAM_ATTR isrDoorClose(RATGDOStore* arg);
static void IRAM_ATTR isrLight(RATGDOStore* arg); static void IRAM_ATTR isrLight(RATGDOStore* arg);
@ -87,6 +81,12 @@ namespace ratgdo {
uint8_t previousLockState { LockState::LOCK_STATE_UNKNOWN }; uint8_t previousLockState { LockState::LOCK_STATE_UNKNOWN };
uint8_t previousObstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN }; uint8_t previousObstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN };
uint8_t obstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN };
uint8_t motionState { MotionState::MOTION_STATE_CLEAR };
uint8_t lockState { LockState::LOCK_STATE_UNKNOWN };
uint8_t lightState { LightState::LIGHT_STATE_UNKNOWN };
uint8_t doorState { DoorState::DOOR_STATE_UNKNOWN };
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }; void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; };
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }; void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }; void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; };