button
This commit is contained in:
parent
e9c110c1fe
commit
151686f6a3
|
@ -284,32 +284,67 @@ namespace ratgdo {
|
||||||
|
|
||||||
void RATGDOComponent::statusUpdateLoop()
|
void RATGDOComponent::statusUpdateLoop()
|
||||||
{
|
{
|
||||||
if (this->doorState != this->previousDoorState)
|
if (this->doorState != this->previousDoorState) {
|
||||||
sendDoorStatus();
|
DoorState val = static_cast<DoorState>(this->doorState);
|
||||||
this->previousDoorState = this->doorState;
|
ESP_LOGD(TAG, "Door state: %s", door_state_to_string(val));
|
||||||
if (this->lightState != this->previousLightState)
|
for (auto* child : this->children_) {
|
||||||
sendLightStatus();
|
child->on_door_state(val);
|
||||||
this->previousLightState = this->lightState;
|
}
|
||||||
if (this->lockState != this->previousLockState)
|
this->previousDoorState = this->doorState;
|
||||||
sendLockStatus();
|
}
|
||||||
this->previousLockState = this->lockState;
|
if (this->lightState != this->previousLightState) {
|
||||||
if (this->obstructionState != this->previousObstructionState)
|
LightState val = static_cast<LightState>(this->lightState);
|
||||||
sendObstructionStatus();
|
ESP_LOGD(TAG, "Light state %s (%d)", light_state_to_string(val), this->lightState);
|
||||||
this->previousObstructionState = this->obstructionState;
|
for (auto* child : this->children_) {
|
||||||
|
child->on_light_state(val);
|
||||||
|
}
|
||||||
|
this->previousLightState = this->lightState;
|
||||||
|
}
|
||||||
|
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){
|
||||||
|
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) {
|
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;
|
this->previousMotorState = this->motorState;
|
||||||
}
|
}
|
||||||
if (this->motionState == MotionState::MOTION_STATE_DETECTED) {
|
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;
|
this->motionState = MotionState::MOTION_STATE_CLEAR;
|
||||||
}
|
}
|
||||||
if (this->buttonState != this->previousButtonState) {
|
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;
|
this->previousButtonState = this->buttonState;
|
||||||
}
|
}
|
||||||
if (this->openings != this->previousOpenings) {
|
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;
|
this->previousOpenings = this->openings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,77 +355,6 @@ namespace ratgdo {
|
||||||
sendCommandAndSaveCounter(Command.REBOOT2);
|
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 *************************/
|
/************************* DOOR COMMUNICATION *************************/
|
||||||
/*
|
/*
|
||||||
* Transmit a message to the door opener over uart1
|
* Transmit a message to the door opener over uart1
|
||||||
|
|
|
@ -113,36 +113,26 @@ namespace ratgdo {
|
||||||
void transmit(cmd command);
|
void transmit(cmd command);
|
||||||
void sync();
|
void sync();
|
||||||
|
|
||||||
|
void gdoStateLoop();
|
||||||
void obstructionLoop();
|
void obstructionLoop();
|
||||||
void sendObstructionStatus();
|
void statusUpdateLoop();
|
||||||
|
|
||||||
void sendOpenings();
|
|
||||||
|
|
||||||
|
void sendCommandAndSaveCounter(cmd command);
|
||||||
void toggleDoor();
|
void toggleDoor();
|
||||||
void openDoor();
|
void openDoor();
|
||||||
void closeDoor();
|
void closeDoor();
|
||||||
void stopDoor();
|
void stopDoor();
|
||||||
void sendDoorStatus();
|
|
||||||
|
|
||||||
void toggleLight();
|
void toggleLight();
|
||||||
void lightOn();
|
void lightOn();
|
||||||
void lightOff();
|
void lightOff();
|
||||||
bool isLightOn();
|
bool isLightOn();
|
||||||
void sendLightStatus();
|
|
||||||
|
|
||||||
void toggleLock();
|
void toggleLock();
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
void sendLockStatus();
|
|
||||||
void sendButtonStatus();
|
|
||||||
void sendMotionStatus();
|
|
||||||
void sendMotorStatus();
|
|
||||||
void query();
|
void query();
|
||||||
void doorStateLoop();
|
|
||||||
void printRollingCode();
|
void printRollingCode();
|
||||||
void getRollingCode(cmd command);
|
void getRollingCode(cmd command);
|
||||||
void gdoStateLoop();
|
|
||||||
void statusUpdateLoop();
|
|
||||||
void readRollingCode(
|
void readRollingCode(
|
||||||
bool& isStatus,
|
bool& isStatus,
|
||||||
uint8_t& door,
|
uint8_t& door,
|
||||||
|
@ -156,7 +146,6 @@ namespace ratgdo {
|
||||||
void incrementRollingCodeCounter();
|
void incrementRollingCodeCounter();
|
||||||
void sendRollingCodeChanged();
|
void sendRollingCodeChanged();
|
||||||
void setRollingCodeCounter(uint32_t counter);
|
void setRollingCodeCounter(uint32_t counter);
|
||||||
void sendCommandAndSaveCounter(cmd command);
|
|
||||||
LightState getLightState();
|
LightState getLightState();
|
||||||
/** Register a child component. */
|
/** Register a child component. */
|
||||||
void register_child(RATGDOClient* obj);
|
void register_child(RATGDOClient* obj);
|
||||||
|
|
Loading…
Reference in New Issue