diff --git a/src/driver/drv_doorSensorWithDeepSleep.c b/src/driver/drv_doorSensorWithDeepSleep.c index 4c086bd9f..4356084a1 100644 --- a/src/driver/drv_doorSensorWithDeepSleep.c +++ b/src/driver/drv_doorSensorWithDeepSleep.c @@ -43,7 +43,8 @@ void DoorDeepSleep_OnEverySecond() { //if (g_noChangeTimePassed < 4) { for (i = 0; i < PLATFORM_GPIO_MAX; i++) { if (g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || - g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup) { + g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup || + g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_pd) { MQTT_ChannelPublish(g_cfg.pins.channels[i], 0); } } @@ -87,7 +88,8 @@ void DoorDeepSleep_AppendInformationToHTTPIndexPage(http_request_t* request) void DoorDeepSleep_OnChannelChanged(int ch, int value) { // detect door state change // (only sleep when there are no changes for certain time) - if (CHANNEL_HasChannelPinWithRoleOrRole(ch, IOR_DoorSensorWithDeepSleep, IOR_DoorSensorWithDeepSleep_NoPup)) { + if (CHANNEL_HasChannelPinWithRoleOrRole(ch, IOR_DoorSensorWithDeepSleep, IOR_DoorSensorWithDeepSleep_NoPup) + || CHANNEL_HasChannelPinWithRoleOrRole(ch, IOR_DoorSensorWithDeepSleep, IOR_DoorSensorWithDeepSleep_pd)) { // 0 seconds since last change g_noChangeTimePassed = 0; g_emergencyTimeWithNoConnection = 0; diff --git a/src/hal/bk7231/hal_pins_bk7231.c b/src/hal/bk7231/hal_pins_bk7231.c index e7475a5b5..0dcb23f73 100644 --- a/src/hal/bk7231/hal_pins_bk7231.c +++ b/src/hal/bk7231/hal_pins_bk7231.c @@ -77,6 +77,9 @@ int HAL_PIN_ReadDigitalInput(int index) { void HAL_PIN_Setup_Input_Pullup(int index) { bk_gpio_config_input_pup(index); } +void HAL_PIN_Setup_Input_Pulldown(int index) { + bk_gpio_config_input_pdwn(index); +} void HAL_PIN_Setup_Input(int index) { bk_gpio_config_input(index); } diff --git a/src/hal/bl602/hal_pins_bl602.c b/src/hal/bl602/hal_pins_bl602.c index 5b9c808b0..a34b03231 100644 --- a/src/hal/bl602/hal_pins_bl602.c +++ b/src/hal/bl602/hal_pins_bl602.c @@ -29,6 +29,8 @@ int HAL_PIN_ReadDigitalInput(int index) { bl_gpio_input_get(index, &iVal); return iVal; } +void HAL_PIN_Setup_Input_Pulldown(int index) { +} void HAL_PIN_Setup_Input_Pullup(int index) { // int bl_gpio_enable_input(uint8_t pin, uint8_t pullup, uint8_t pulldown); bl_gpio_enable_input(index, 1, 0); diff --git a/src/hal/hal_pins.h b/src/hal/hal_pins.h index 0caf8a9e8..c8c9f1e1f 100644 --- a/src/hal/hal_pins.h +++ b/src/hal/hal_pins.h @@ -1,6 +1,7 @@ void HAL_PIN_SetOutputValue(int index, int iVal); int HAL_PIN_ReadDigitalInput(int index); +void HAL_PIN_Setup_Input_Pulldown(int index); void HAL_PIN_Setup_Input_Pullup(int index); void HAL_PIN_Setup_Input(int index); void HAL_PIN_Setup_Output(int index); diff --git a/src/hal/w800/hal_pins_w800.c b/src/hal/w800/hal_pins_w800.c index 05f817cfa..de6ddb27f 100644 --- a/src/hal/w800/hal_pins_w800.c +++ b/src/hal/w800/hal_pins_w800.c @@ -136,6 +136,9 @@ int HAL_PIN_ReadDigitalInput(int index) { realCode = g_pins[index].code; return tls_gpio_read(realCode); +} +void HAL_PIN_Setup_Input_Pulldown(int index) { + } void HAL_PIN_Setup_Input_Pullup(int index) { int realCode; diff --git a/src/hal/win32/hal_pins_win32.c b/src/hal/win32/hal_pins_win32.c index 8e9d6c70c..3d0cf0475 100644 --- a/src/hal/win32/hal_pins_win32.c +++ b/src/hal/win32/hal_pins_win32.c @@ -191,6 +191,8 @@ int HAL_PIN_ReadDigitalInput(int index) { void HAL_PIN_Setup_Input_Pullup(int index) { g_pinModes[index] = SIM_PIN_INPUT_PULLUP; } +void HAL_PIN_Setup_Input_Pulldown(int index) { +} void HAL_PIN_Setup_Input(int index) { g_pinModes[index] = SIM_PIN_INPUT; } diff --git a/src/hal/xr809/hal_pins_xr809.c b/src/hal/xr809/hal_pins_xr809.c index 9cf8593a8..5a8555fab 100644 --- a/src/hal/xr809/hal_pins_xr809.c +++ b/src/hal/xr809/hal_pins_xr809.c @@ -71,6 +71,9 @@ int HAL_PIN_ReadDigitalInput(int index) { if (HAL_GPIO_ReadPin(xr_port, xr_pin) == GPIO_PIN_LOW) return 0; return 1; +} +void HAL_PIN_Setup_Input_Pulldown(int index) { + } void HAL_PIN_Setup_Input_Pullup(int index) { int xr_port; // eg GPIO_PORT_A diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 30e7c242b..b9a78305d 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -448,7 +448,7 @@ const char* htmlPinRoleNames[] = { "TM1637_DIO", "TM1637_CLK", "BL0937SEL_n", - "error", + "DoorSnsrWSleep_pd", "error", "error", "error", diff --git a/src/new_pins.c b/src/new_pins.c index 674ca76ad..fcf9925bf 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -130,6 +130,7 @@ void PINS_BeginDeepSleepWithPinWakeUp() { for (i = 0; i < PLATFORM_GPIO_MAX; i++) { if (g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup + || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_pd || g_cfg.pins.roles[i] == IOR_DigitalInput || g_cfg.pins.roles[i] == IOR_DigitalInput_n || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup @@ -743,6 +744,14 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { HAL_PIN_Setup_Input_Pullup(index); } break; + case IOR_DoorSensorWithDeepSleep_pd: + { + // add to active inputs + setGPIActive(index, 1, falling); + // digital input + HAL_PIN_Setup_Input_Pulldown(index); + } + break; case IOR_DigitalInput_NoPup_n: falling = 1; case IOR_DoorSensorWithDeepSleep_NoPup: @@ -894,7 +903,8 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) { } else if (g_cfg.pins.roles[i] == IOR_DigitalInput || g_cfg.pins.roles[i] == IOR_DigitalInput_n || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup_n - || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup) { + || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup + || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_pd) { bCallCb = 1; } else if (g_cfg.pins.roles[i] == IOR_ToggleChannelOnToggle) { @@ -1292,6 +1302,7 @@ bool CHANNEL_HasRoleThatShouldBePublished(int ch) { || role == IOR_CHT8305_DAT || role == IOR_SHT3X_DAT || role == IOR_DigitalInput || role == IOR_DigitalInput_n || role == IOR_DoorSensorWithDeepSleep || role == IOR_DoorSensorWithDeepSleep_NoPup + || role == IOR_DoorSensorWithDeepSleep_pd || IS_PIN_DHT_ROLE(role) || role == IOR_DigitalInput_NoPup || role == IOR_DigitalInput_NoPup_n) { return true; @@ -1605,7 +1616,8 @@ void PIN_ticks(void* param) else if (g_cfg.pins.roles[i] == IOR_DigitalInput || g_cfg.pins.roles[i] == IOR_DigitalInput_n || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup_n - || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup) { + || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup + || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_pd) { // read pin digital value (and already invert it if needed) value = PIN_ReadDigitalInputValue_WithInversionIncluded(i); @@ -1899,6 +1911,7 @@ void PIN_get_Relay_PWM_Count(int* relayCount, int* pwmCount, int* dInputCount) { case IOR_DigitalInput_NoPup_n: case IOR_DoorSensorWithDeepSleep: case IOR_DoorSensorWithDeepSleep_NoPup: + case IOR_DoorSensorWithDeepSleep_pd: if (dInputCount) { (*dInputCount)++; } @@ -1965,7 +1978,7 @@ int h_isChannelDigitalInput(int tg_ch) { if (role == IOR_DigitalInput || role == IOR_DigitalInput_n || role == IOR_DigitalInput_NoPup || role == IOR_DigitalInput_NoPup_n) { return true; } - if (role == IOR_DoorSensorWithDeepSleep || role == IOR_DoorSensorWithDeepSleep_NoPup) { + if (role == IOR_DoorSensorWithDeepSleep || role == IOR_DoorSensorWithDeepSleep_NoPup || role == IOR_DoorSensorWithDeepSleep_pd) { return true; } } diff --git a/src/new_pins.h b/src/new_pins.h index 04abb3823..32018a944 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -460,6 +460,13 @@ typedef enum ioRole_e { //iodetail:"file":"new_pins.h", //iodetail:"driver":""} IOR_BL0937_SEL_n, + //iodetail:{"name":"DoorSensorWithDeepSleep_pd", + //iodetail:"title":"TODO", + //iodetail:"descr":"As DoorSensorWithDeepSleep, but with pulldown resistor", + //iodetail:"enum":"IOR_DoorSensorWithDeepSleep_pd", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_DoorSensorWithDeepSleep_pd, //iodetail:{"name":"Total_Options", //iodetail:"title":"TODO", //iodetail:"descr":"Current total number of available IOR roles",