diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 8ab4ee2..588bf61 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -324,13 +324,13 @@ namespace ratgdo { } this->previousMotorState = this->motorState; } - if (this->motionState == MotionState::MOTION_STATE_DETECTED) { + if (this->motionState == this->previousMotionState) { 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; + this->previousMotionState = this->motionState; } if (this->buttonState != this->previousButtonState) { ButtonState val = static_cast(this->buttonState); diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index bc8cf4a..22fc764 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -95,14 +95,15 @@ namespace ratgdo { uint8_t previousObstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN }; uint8_t previousMotorState { MotorState::MOTOR_STATE_UNKNOWN }; uint8_t previousButtonState { ButtonState::BUTTON_STATE_UNKNOWN }; + uint8_t previousMotionState { MotionState::MOTION_STATE_UNKNOWN }; - uint8_t obstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN }; - uint8_t motionState { MotionState::MOTION_STATE_CLEAR }; - uint8_t motorState { MotorState::MOTOR_STATE_UNKNOWN }; - uint8_t lockState { LockState::LOCK_STATE_UNKNOWN }; - uint8_t lightState { LightState::LIGHT_STATE_UNKNOWN }; uint8_t doorState { DoorState::DOOR_STATE_UNKNOWN }; + uint8_t lightState { LightState::LIGHT_STATE_UNKNOWN }; + uint8_t lockState { LockState::LOCK_STATE_UNKNOWN }; + uint8_t obstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN }; + uint8_t motorState { MotorState::MOTOR_STATE_UNKNOWN }; uint8_t buttonState { ButtonState::BUTTON_STATE_UNKNOWN }; + uint8_t motionState { MotionState::MOTION_STATE_UNKNOWN }; void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }; void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }; diff --git a/components/ratgdo/ratgdo_state.cpp b/components/ratgdo/ratgdo_state.cpp index 68f2c08..6011d2a 100644 --- a/components/ratgdo/ratgdo_state.cpp +++ b/components/ratgdo/ratgdo_state.cpp @@ -57,8 +57,10 @@ namespace ratgdo { case MOTION_STATE_DETECTED: return "DETECTED"; case MOTION_STATE_CLEAR: - default: return "CLEAR"; + case MOTION_STATE_UNKNOWN: + default: + return "UNKNOWN"; } } diff --git a/components/ratgdo/ratgdo_state.h b/components/ratgdo/ratgdo_state.h index 294f25d..c581f17 100644 --- a/components/ratgdo/ratgdo_state.h +++ b/components/ratgdo/ratgdo_state.h @@ -51,6 +51,7 @@ namespace ratgdo { enum MotionState : uint8_t { MOTION_STATE_CLEAR = 0, MOTION_STATE_DETECTED = 1, + MOTION_STATE_UNKNOWN = 2, }; const char* motion_state_to_string(MotionState state);