-
Notifications
You must be signed in to change notification settings - Fork 163
TTC Controls #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
TTC Controls #43
Changes from 11 commits
8815184
27b7bbf
4849712
775cde7
7cb100e
1240b00
ead72e9
7b078c9
d60ed0a
caf73c8
ae2e6ba
8c8a996
bb5ddeb
a8cb645
ecc12a3
8929b32
5518518
d110d61
5d72946
e285003
9dda7b8
1a3ff77
7281273
8a7eec3
d2ae60e
dee9f3d
e4ecce0
7d0422a
9bc41c2
fe593a9
575471b
f7a6fe8
180534f
6d8f3e0
f323e02
7da1282
89e2910
a7b0230
a6a225d
e248c70
2091be8
472ec6c
bdae84b
bbfded5
db22a36
b662957
75f95f1
e97204f
ded41d7
b0504bd
0f84d14
c677ded
7306135
61dd234
c09136d
e2f4b6e
8317f18
66ba19e
718237a
7be33e1
5bd2464
cdc7780
c4a9b6e
bb29b9b
36c4e55
0b7b851
a1dbdbe
ff2acab
e36225c
5a0294f
4f2e599
44ecf15
72977f2
c4e2776
ffbef79
4714508
2ea7ca6
892c4e2
53752d5
bb4c995
f942292
65c52d0
e7efd2c
587ff4c
82c62ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,17 @@ namespace ratgdo { | |
| this->door_position = 1.0; | ||
| } else if (door_state == DoorState::CLOSED) { | ||
| this->door_position = 0.0; | ||
| if(this->restore_TTC_) { | ||
| //GET_OPENINGS is sent when door closes, delay this tx | ||
| set_timeout(100, [=] { | ||
| if (*this->ttc_time_seconds == 0) { | ||
| this->turn_ttc_off(); | ||
| } else { | ||
| this->set_ttc_sec(*ttc_time_seconds); | ||
| } | ||
| } ); | ||
| this->restore_TTC_ = false; | ||
| } | ||
| } else { | ||
| if (*this->closing_duration == 0 || *this->opening_duration == 0 || *this->door_position == DOOR_POSITION_UNKNOWN) { | ||
| this->door_position = 0.5; // best guess | ||
|
|
@@ -157,7 +168,7 @@ namespace ratgdo { | |
| this->position_sync_while_opening(1.0 - *this->door_position); | ||
| this->moving_to_position = true; | ||
| } | ||
| if (door_state == DoorState::CLOSING && !this->moving_to_position) { | ||
| if (door_state == DoorState::CLOSING && !this->moving_to_position) { | ||
| this->position_sync_while_closing(*this->door_position); | ||
| this->moving_to_position = true; | ||
| } | ||
|
|
@@ -222,10 +233,47 @@ namespace ratgdo { | |
| this->send_command(Command::GET_STATUS); | ||
| } | ||
| ESP_LOGD(TAG, "Motion: %s", MotionState_to_string(*this->motion_state)); | ||
| } else if (cmd == Command::SET_TTC) { | ||
| } else if (cmd == Command::TTC_SET_DURATION) { | ||
| auto seconds = (byte1 << 8) | byte2; | ||
| ESP_LOGD(TAG, "Time to close (TTC): %ds", seconds); | ||
| } | ||
| ESP_LOGD(TAG, "Time to close (TTC) update request: %ds", seconds); | ||
| } else if (cmd == Command::TTC_DURATION) { | ||
| auto seconds = (byte1 << 8) | byte2; | ||
| ESP_LOGD(TAG, "Time to close (TTC) set to: %ds", seconds); | ||
| if (seconds == 60) { | ||
| this->ttc_time_seconds=seconds; | ||
| } else if (seconds == 300) { | ||
| this->ttc_time_seconds=seconds; | ||
| } else if (seconds == 600) { | ||
| this->ttc_time_seconds=seconds; | ||
| } else if (seconds == 0) { | ||
| this->ttc_time_seconds=seconds; | ||
| } else { | ||
| this->ttc_time_seconds=0; | ||
| ESP_LOGW(TAG, "Unsupported TTC time: %ds", seconds); | ||
| } | ||
| } else if (cmd == Command::TTC_COUNTDOWN) { | ||
| auto seconds = (byte1 << 8) | byte2; | ||
| ESP_LOGD(TAG, "(TTC) door will close in: %ds", seconds); | ||
| } else if (cmd == Command::TTC_CANCEL) { | ||
| if (byte1 == 0x04) { | ||
| ESP_LOGD(TAG, "TTC: Auto Hold Toggled"); | ||
| } else if (byte1 == 0x05) { | ||
| ESP_LOGD(TAG, "TTC: Disabled"); | ||
| } else { | ||
| ESP_LOGD(TAG, "TTC_CANCEL: Unknown Data"); | ||
| } | ||
| } else if (cmd == Command::EXT_STATUS) { | ||
| if ( (byte1 & 0b00000111) == 0b00000001) { | ||
| ESP_LOGD(TAG, "TTC is disabled."); | ||
| this->hold_state = HoldState::HOLD_DISABLED; | ||
| } else if ( (byte1 & 0b00000111) == 0b00000010) { | ||
| ESP_LOGD(TAG, "TTC is enabled but in Hold Open."); | ||
| this->hold_state = HoldState::HOLD_ENABLED; | ||
| } else if ( (byte1 & 0b00000111) == 0b00000100) { | ||
| ESP_LOGD(TAG, "TTC is enabled."); | ||
| this->hold_state = HoldState::HOLD_DISABLED; | ||
| } | ||
| } | ||
|
|
||
| return cmd; | ||
| } | ||
|
|
@@ -383,13 +431,46 @@ namespace ratgdo { | |
| void RATGDOComponent::query_status() | ||
| { | ||
| send_command(Command::GET_STATUS); | ||
| set_timeout(100, [=] {this->send_command(Command::GET_EXT_STATUS, data::GET_EXT_STATUS);} ); | ||
| set_timeout(200, [=] {this->send_command(Command::TTC_GET_DURATION, data::TTC_GET_DURATION);} ); | ||
| set_timeout(300, [=] {this->send_command(Command::GET_OPENINGS);} ); | ||
| } | ||
|
|
||
| void RATGDOComponent::query_openings() | ||
| { | ||
| send_command(Command::GET_OPENINGS); | ||
| this->query_status(); | ||
| } | ||
|
|
||
| //TODO does gdo send status that door is closing??? | ||
| void RATGDOComponent::close_with_alert() | ||
| { | ||
| //Check if door is closed and ignore, only works if fully open | ||
| if(*this->door_state != DoorState::OPEN) { | ||
| ESP_LOGW(TAG, "Door must be fully open to Close with alert!"); | ||
| return; | ||
| } | ||
| //SET_TTC closes door in 1 second with light and beeper | ||
| set_ttc_sec(1); | ||
| this->restore_TTC_ = true; | ||
| } | ||
|
|
||
| void RATGDOComponent::turn_ttc_off() | ||
| { | ||
| send_command(Command::TTC_CANCEL, data::TTC_CANCEL_OFF); | ||
| this->ttc_time_seconds=0; | ||
| } | ||
|
|
||
| void RATGDOComponent::ttc_toggle_hold() | ||
| { | ||
| send_command(Command::TTC_CANCEL, data::TTC_CANCEL_TOGGLE_HOLD); | ||
| } | ||
|
|
||
| void RATGDOComponent::set_ttc_sec(uint16_t duration) | ||
| { | ||
| send_command(Command::TTC_SET_DURATION, (duration & 0xff) << 16 | (duration & 0xff00) | 0x01); | ||
| } | ||
|
|
||
|
|
||
| /************************* DOOR COMMUNICATION *************************/ | ||
| /* | ||
| * Transmit a message to the door opener over uart1 | ||
|
|
@@ -441,17 +522,9 @@ namespace ratgdo { | |
|
|
||
| set_retry( | ||
| 500, 10, [=](uint8_t r) { | ||
| if (*this->door_state != DoorState::UNKNOWN) { // have status | ||
| if (*this->openings != 0) { // have openings | ||
| return RetryResult::DONE; | ||
| } else { | ||
| if (r == 0) { // failed to sync probably rolling counter is wrong, notify | ||
| ESP_LOGD(TAG, "Triggering sync failed actions."); | ||
| this->sync_failed = true; | ||
| }; | ||
| this->send_command(Command::GET_OPENINGS); | ||
| return RetryResult::RETRY; | ||
| } | ||
| if (*this->door_state != DoorState::UNKNOWN) { // GET_STATUS succeeded | ||
| this->query_status(); //Get openings and TTC settings to initalize | ||
|
||
| return RetryResult::DONE; | ||
| } else { | ||
| if (r == 0) { // failed to sync probably rolling counter is wrong, notify | ||
| ESP_LOGD(TAG, "Triggering sync failed actions."); | ||
|
|
@@ -648,6 +721,27 @@ namespace ratgdo { | |
| this->send_command(Command::LOCK, data::LOCK_TOGGLE); | ||
| } | ||
|
|
||
| // Hold functions | ||
| void RATGDOComponent::hold_enable() | ||
| { | ||
| if(*(this->hold_state) == HoldState::HOLD_DISABLED) { | ||
| this->toggle_hold(); | ||
| } | ||
| } | ||
|
|
||
| void RATGDOComponent::hold_disable() | ||
| { | ||
| if(*(this->hold_state) == HoldState::HOLD_ENABLED) { | ||
| this->toggle_hold(); | ||
| } | ||
| } | ||
|
|
||
| void RATGDOComponent::toggle_hold() | ||
| { | ||
| this->hold_state = hold_state_toggle(*this->hold_state); | ||
| this->send_command(Command::TTC_CANCEL, data::TTC_CANCEL_TOGGLE_HOLD); | ||
| } | ||
|
|
||
| LightState RATGDOComponent::get_light_state() const | ||
| { | ||
| return *this->light_state; | ||
|
|
@@ -688,6 +782,14 @@ namespace ratgdo { | |
| { | ||
| this->lock_state.subscribe([=](LockState state) { defer("lock_state", [=] { f(state); }); }); | ||
| } | ||
| void RATGDOComponent::subscribe_hold_state(std::function<void(HoldState)>&& f) | ||
| { | ||
| this->hold_state.subscribe([=](HoldState state) { defer("hold_state", [=] { f(state); }); }); | ||
| } | ||
| void RATGDOComponent::subscribe_ttc_seconds(std::function<void(uint16_t)>&& f) | ||
| { | ||
| this->ttc_time_seconds.subscribe([=](uint16_t state) { defer("ttc_time", [=] { f(state); }); }); | ||
| } | ||
| void RATGDOComponent::subscribe_obstruction_state(std::function<void(ObstructionState)>&& f) | ||
| { | ||
| this->obstruction_state.subscribe([=](ObstructionState state) { defer("obstruction_state", [=] { f(state); }); }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.