Refactor and enhance reset_channels_to_idle_state
- Refactor reset_channels_to_idle_state to reset_channels_to_defaults and enhance functionality with direction reset logic. This is because some tilt test cases were failing due to modified run limit values in some of the previous core test cases. See #1089-3. - A relay channel listener has been added to diagnose channel states during tests. Refs #1089
This commit is contained in:
@@ -25,7 +25,7 @@ void setUp()
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
reset_channels_to_idle_state();
|
||||
reset_channels_to_defaults();
|
||||
}
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
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);
|
||||
Reference in New Issue
Block a user