diff --git a/test_apps/main/test_app_main.c b/test_apps/main/test_app_main.c index 8400843..1f8d4f9 100644 --- a/test_apps/main/test_app_main.c +++ b/test_apps/main/test_app_main.c @@ -25,7 +25,7 @@ void setUp() void tearDown() { - reset_channels_to_idle_state(); + reset_channels_to_defaults(); } #if CONFIG_RELAY_CHN_ENABLE_NVS diff --git a/test_apps/main/test_common.c b/test_apps/main/test_common.c index 1dcdfad..d8fdb4d 100644 --- a/test_apps/main/test_common.c +++ b/test_apps/main/test_common.c @@ -32,17 +32,40 @@ const uint8_t gpio_map[] = {4, 5}; const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]); -void reset_channels_to_idle_state() +void reset_channels_to_defaults() { #if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_stop_all(); +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT + relay_chn_set_run_limit_all_with(CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC); +#endif vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i)); + + // Reset directions + if (relay_chn_get_direction(i) != RELAY_CHN_DIRECTION_DEFAULT) { + relay_chn_flip_direction(i); + TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(i)); + } } #else relay_chn_stop(); +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT + relay_chn_set_run_limit(CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC); +#endif + + // Reset direction + if (relay_chn_get_direction() != RELAY_CHN_DIRECTION_DEFAULT) { + relay_chn_flip_direction(); + TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction()); + } vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); #endif +} + +void test_state_listener(uint8_t id, relay_chn_state_t old_state, relay_chn_state_t new_state) +{ + ESP_LOGI(TEST_TAG, "test_state_listener: id: %d, old_state: %d, new_state: %d", id, old_state, new_state); } \ No newline at end of file diff --git a/test_apps/main/test_common.h b/test_apps/main/test_common.h index 1b9c94a..b2c1c55 100644 --- a/test_apps/main/test_common.h +++ b/test_apps/main/test_common.h @@ -18,4 +18,7 @@ extern const uint8_t gpio_count; #define TEST_DELAY_MARGIN_MS 50 // Reset channels to Idle state -void reset_channels_to_idle_state(void); \ No newline at end of file +void reset_channels_to_defaults(void); + +// Relay channel state listener for tests +void test_state_listener(uint8_t id, relay_chn_state_t old_state, relay_chn_state_t new_state); \ No newline at end of file