Skip to content

Commit

Permalink
buttons for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mulcmu committed Aug 31, 2023
1 parent 1240b00 commit ead72e9
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 21 deletions.
95 changes: 94 additions & 1 deletion base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,97 @@ button:
on_press:
then:
lambda: !lambda |-
id($id_prefix).sync();
id($id_prefix).sync();
- platform: template
id: ${id_prefix}_GET_TTC_DURATION
name: "Request TTC current duration"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).get_ttc_duration();
- platform: template
id: ${id_prefix}_CANCEL_TTC_OFF
name: "Turn TTC Off"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).turn_ttc_off();
- platform: template
id: ${id_prefix}_CANCEL_TTC_TOGGLE_HOLD
name: "Toggle TTC Hold Open"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).ttc_toggle_hold();
- platform: template
id: ${id_prefix}_ttc_1_min
name: "TTC Set 1 min"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_1_min();
- platform: template
id: ${id_prefix}_ttc_5_min
name: "TTC Set 5 min"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_5_min();
- platform: template
id: ${id_prefix}_ttc_10_min
name: "TTC Set 10 min"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_10_min();
- platform: template
id: ${id_prefix}_beef
name: "Set TTC 0xBEEF"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_beef();
- platform: template
id: ${id_prefix}_set_ttc_0_sec
name: "Set TTC 0 Sec"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_0_sec();
- platform: template
id: ${id_prefix}_set_ttc_1_sec
name: "Set TTC 1 Sec"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_1_sec();
- platform: template
id: ${id_prefix}_set_ttc_255
name: "Set TTC 255 Sec"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).set_ttc_255_sec();
76 changes: 62 additions & 14 deletions components/ratgdo/ratgdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace ratgdo {
this->door_position = 0.0;
if(this->clear_TTC_) {
//TODO this send_command gets sent same time as GET_OPENINGS on line 189
this->send_command(Command::CANCEL_TTC, data::CANCEL_TTC_OFF);
this->send_command(Command::TTC_CANCEL, data::TTC_CANCEL_OFF);
this->clear_TTC_ = false;
}
} else {
Expand Down Expand Up @@ -227,7 +227,7 @@ 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_DURATION) {
} else if (cmd == Command::TTC_SET_DURATION) {
auto seconds = (byte1 << 8) | byte2;
ESP_LOGD(TAG, "Time to close (TTC) update request: %ds", seconds);
} else if (cmd == Command::TTC_DURATION) {
Expand All @@ -236,13 +236,13 @@ namespace ratgdo {
} 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::CANCEL_TTC) {
} else if (cmd == Command::TTC_CANCEL) {
if (byte1 == 0x04) {
ESP_LOGD(TAG, "CANCEL_TTC: Auto Hold Toggled");
ESP_LOGD(TAG, "TTC: Auto Hold Toggled");
} else if (byte1 == 0x05) {
ESP_LOGD(TAG, "CANCEL_TTC: Disabled");
ESP_LOGD(TAG, "TTC: Disabled");
} else {
ESP_LOGD(TAG, "CANCEL_TTC: Unknown Data");
ESP_LOGD(TAG, "TTC_CANCEL: Unknown Data");
}
}

Expand Down Expand Up @@ -401,10 +401,7 @@ namespace ratgdo {

void RATGDOComponent::query_status()
{
//send_command(Command::GET_STATUS);

//TODO revert testing
send_command(Command::GET_TTC_DURATION, data::GET_TTC_DURATION);
send_command(Command::GET_STATUS);
}

void RATGDOComponent::query_openings()
Expand All @@ -415,14 +412,65 @@ namespace ratgdo {
void RATGDOComponent::close_with_alert()
{
//TODO check if door is closed and ignore
//TODO check if this will work with door partially open
//Only works if fully open

//SET_TTC closes door in 1 second with light and beeper
send_command(Command::SET_TTC_DURATION, data::TTC_BEEF);

//this->clear_TTC_ = true;
send_command(Command::TTC_SET_DURATION, data::TTC_1_SEC);
this->clear_TTC_ = true;
}

void RATGDOComponent::get_ttc_duration()
{
send_command(Command::TTC_GET_DURATION, data::TTC_GET_DURATION);
}

void RATGDOComponent::turn_ttc_off()
{
send_command(Command::TTC_CANCEL, data::TTC_CANCEL_OFF);
}

void RATGDOComponent::ttc_toggle_hold()
{
send_command(Command::TTC_CANCEL, data::TTC_CANCEL_TOGGLE_HOLD);
}

void RATGDOComponent::set_ttc_1_min()
{
send_command(Command::TTC_SET_DURATION, data::TTC_1_MIN);
}

void RATGDOComponent::set_ttc_5_min()
{
send_command(Command::TTC_SET_DURATION, data::TTC_5_MIN);
}

void RATGDOComponent::set_ttc_10_min()
{
send_command(Command::TTC_SET_DURATION, data::TTC_10_MIN);
}

void RATGDOComponent::set_ttc_beef()
{
send_command(Command::TTC_SET_DURATION, data::TTC_BEEF);
}

void RATGDOComponent::set_ttc_0_sec()
{
send_command(Command::TTC_SET_DURATION, data::TTC_0_SEC);
}

void RATGDOComponent::set_ttc_1_sec()
{
send_command(Command::TTC_SET_DURATION, data::TTC_1_SEC);
}

void RATGDOComponent::set_ttc_255_sec()
{
send_command(Command::TTC_SET_DURATION, data::TTC_255_SEC);
}



/************************* DOOR COMMUNICATION *************************/
/*
* Transmit a message to the door opener over uart1
Expand Down
24 changes: 18 additions & 6 deletions components/ratgdo/ratgdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace ratgdo {
const uint32_t DOOR_TOGGLE = 2;
const uint32_t DOOR_STOP = 3;

const uint32_t GET_TTC_DURATION= 1 ;
const uint32_t TTC_GET_DURATION= 1 ;

const uint32_t TTC_0_SEC = 0x000001;
const uint32_t TTC_1_SEC = 0x010001;
Expand All @@ -64,8 +64,8 @@ namespace ratgdo {
const uint32_t TTC_291_SEC = 0x230101; ////TODO remove test values
const uint32_t TTC_BEEF = 0xBEEF01; ////TODO remove test values

const uint32_t CANCEL_TTC_OFF = 0x000501; //Unknown meaning for these bytes, mimic button pad
const uint32_t CANCEL_TTC_TOGGLE_HOLD = 0x000401; //Unknown meaning for these bytes, mimic button pad
const uint32_t TTC_CANCEL_OFF = 0x000501; //Unknown meaning for these bytes, mimic button pad
const uint32_t TTC_CANCEL_TOGGLE_HOLD = 0x000401; //Unknown meaning for these bytes, mimic button pad
}

ENUM(Command, uint16_t,
Expand All @@ -88,10 +88,10 @@ namespace ratgdo {
(PING, 0x392),
(PING_RESP, 0x393),

(GET_TTC_DURATION, 0x400),
(TTC_GET_DURATION, 0x400),
(TTC_DURATION, 0x401), //data appears to contain the current TTC setting in gdo
(SET_TTC_DURATION, 0x402), // Set time to close in seconds = (byte1<<8)+byte2
(CANCEL_TTC, 0x408), //OFF or TOGGLE_HOLD are options
(TTC_SET_DURATION, 0x402), // Set time to close in seconds = (byte1<<8)+byte2
(TTC_CANCEL, 0x408), //OFF or TOGGLE_HOLD are options
(TTC_COUNTDOWN, 0x40a), // Time to close countdown in seconds

(GET_OPENINGS, 0x48b),
Expand Down Expand Up @@ -186,6 +186,18 @@ namespace ratgdo {
void sync();
void close_with_alert();

//TODO remove these buttons for testing
void get_ttc_duration();
void turn_ttc_off();
void ttc_toggle_hold();
void set_ttc_1_min();
void set_ttc_5_min();
void set_ttc_10_min();
void set_ttc_beef();
void set_ttc_0_sec();
void set_ttc_1_sec();
void set_ttc_255_sec();

// children subscriptions
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f);
void subscribe_opening_duration(std::function<void(float)>&& f);
Expand Down

0 comments on commit ead72e9

Please sign in to comment.