Files
relay_chn/test_apps/main/test_common.c
ismail 0cd6b4e263 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
2025-08-28 09:30:43 +03:00

71 lines
2.0 KiB
C

#include "test_common.h"
const char *TEST_TAG = "RELAY_CHN_TEST";
// Test-wide GPIO map
#if CONFIG_RELAY_CHN_COUNT > 1
const uint8_t gpio_map[] = {
0, 1,
2, 3
#if CONFIG_RELAY_CHN_COUNT > 2
, 4, 5
#if CONFIG_RELAY_CHN_COUNT > 3
, 6, 7
#if CONFIG_RELAY_CHN_COUNT > 4
, 8, 9
#if CONFIG_RELAY_CHN_COUNT > 5
, 10, 11
#if CONFIG_RELAY_CHN_COUNT > 6
, 12, 13
#if CONFIG_RELAY_CHN_COUNT > 7
, 14, 15
#endif
#endif
#endif
#endif
#endif
#endif
};
#else
const uint8_t gpio_map[] = {4, 5};
#endif
const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]);
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);
}