@@ -80,6 +80,7 @@ static gdo_status_t g_status = {
80
80
GDO_PAIRED_DEVICE_COUNT_UNKNOWN ,
81
81
GDO_PAIRED_DEVICE_COUNT_UNKNOWN },
82
82
.synced = false,
83
+ .ttc_enabled = false,
83
84
.openings = 0 ,
84
85
.ttc_seconds = 0 ,
85
86
.open_ms = 0 ,
@@ -101,7 +102,8 @@ static esp_timer_handle_t motion_detect_timer;
101
102
static esp_timer_handle_t door_position_sync_timer ;
102
103
static esp_timer_handle_t obst_timer ;
103
104
static void * g_user_cb_arg ;
104
- static uint32_t g_tx_delay_ms = 250 ; // Less than 250 is too frequent and brownouts many wall controllers
105
+ static uint32_t g_tx_delay_ms = 50 ;
106
+ static uint32_t g_ttc_delay_s = 0 ;
105
107
static portMUX_TYPE gdo_spinlock = portMUX_INITIALIZER_UNLOCKED ;
106
108
107
109
@@ -526,6 +528,26 @@ esp_err_t gdo_light_off(void) {
526
528
return err ;
527
529
}
528
530
531
+ /**
532
+ * @brief Sets the time to close.
533
+ * @return ESP_OK on success, ESP_ERR_NO_MEM if the queue is full, ESP_FAIL if the encoding fails.
534
+ */
535
+ esp_err_t gdo_set_ttc (uint16_t seconds ) {
536
+ esp_err_t err = ESP_OK ;
537
+
538
+ if (g_status .protocol & GDO_PROTOCOL_SEC_PLUS_V1 ) {
539
+ } else {
540
+ //queue_command(gdo_command_t command, uint8_t nibble, uint8_t byte1, uint8_t byte2)
541
+ err = queue_command (GDO_CMD_SET_TTC , seconds , 0 , 0 );
542
+ if (err == ESP_OK ) {
543
+ get_status ();
544
+ }
545
+ }
546
+
547
+ return err ;
548
+ }
549
+
550
+
529
551
/**
530
552
* @brief Toggles the light.
531
553
* @return ESP_OK on success, ESP_ERR_NOT_FOUND if current state is unknown,
@@ -1324,8 +1346,12 @@ static void decode_packet(uint8_t *packet) {
1324
1346
update_motion_state (GDO_MOTION_STATE_DETECTED );
1325
1347
} else if (cmd == GDO_CMD_OPENINGS ) {
1326
1348
update_openings (nibble , ((byte1 << 8 ) | byte2 ));
1349
+ } else if (cmd == GDO_CMD_UPDATE_TTC ) {
1350
+ update_ttc ((byte1 << 8 ) | byte2 );
1351
+ queue_event ((gdo_event_t ){GDO_EVENT_UPDATE_TTC });
1327
1352
} else if (cmd == GDO_CMD_SET_TTC ) {
1328
1353
update_ttc ((byte1 << 8 ) | byte2 );
1354
+ queue_event ((gdo_event_t ){GDO_EVENT_SET_TTC });
1329
1355
} else if (cmd == GDO_CMD_PAIRED_DEVICES ) {
1330
1356
update_paired_devices (nibble , byte2 );
1331
1357
} else if (cmd == GDO_CMD_BATTERY_STATUS ) {
@@ -1578,8 +1604,13 @@ static void gdo_main_task(void* arg) {
1578
1604
case GDO_EVENT_MOTION_UPDATE :
1579
1605
cb_event = GDO_CB_EVENT_MOTION ;
1580
1606
break ;
1581
- case GDO_EVENT_TTC_UPDATE :
1582
- cb_event = GDO_CB_EVENT_TTC ;
1607
+ case GDO_EVENT_UPDATE_TTC :
1608
+ cb_event = GDO_CB_EVENT_UPDATE_TTC ;
1609
+ ESP_LOGI (TAG , "GDO_CB_EVENT_UPDATE_TTC" );
1610
+ break ;
1611
+ case GDO_EVENT_SET_TTC :
1612
+ cb_event = GDO_CB_EVENT_SET_TTC ;
1613
+ ESP_LOGI (TAG , "GDO_CB_EVENT_SET_TTC" );
1583
1614
break ;
1584
1615
case GDO_EVENT_PAIRED_DEVICES_UPDATE :
1585
1616
cb_event = GDO_CB_EVENT_PAIRED_DEVICES ;
@@ -1896,13 +1927,29 @@ inline static void update_openings(uint8_t flag, uint16_t count) {
1896
1927
* @param ttc The new TTC to update to.
1897
1928
*/
1898
1929
inline static void update_ttc (uint16_t ttc ) {
1899
- ESP_LOGD (TAG , "TTC: %u" , ttc );
1930
+ ESP_LOGI (TAG , "TTC Seconds remaining : %u" , ttc );
1900
1931
if (g_status .ttc_seconds != ttc ) {
1901
1932
g_status .ttc_seconds = ttc ;
1902
- queue_event ((gdo_event_t ){GDO_EVENT_TTC_UPDATE });
1903
1933
}
1904
1934
}
1905
1935
1936
+ /**
1937
+ * @brief Set the time to close
1938
+ * @param time_to_close The new time to close set by the UI
1939
+ */
1940
+ esp_err_t gdo_set_time_to_close (uint16_t time_to_close ) {
1941
+ g_ttc_delay_s = time_to_close ;
1942
+ g_status .ttc_enabled = (time_to_close > 0 ) ? 1 : 0 ;
1943
+ esp_err_t err = ESP_OK ;
1944
+ uint8_t byte1 = (time_to_close >> 8 );
1945
+ uint8_t byte2 = (uint8_t )time_to_close ;
1946
+ uint8_t nibble = 1 ;
1947
+ update_ttc (time_to_close );
1948
+ queue_command (GDO_CMD_SET_TTC , nibble , byte1 , byte2 );
1949
+ queue_event ((gdo_event_t ){GDO_EVENT_SET_TTC });
1950
+ return err ;
1951
+ }
1952
+
1906
1953
/**
1907
1954
* @brief Updates the local paired devices count and queues an event if it has changed.
1908
1955
* @param type The type of paired devices to update.
0 commit comments