/* * SPDX-FileCopyrightText: 2025 Kozmotronik Tech * * SPDX-License-Identifier: MIT */ #include "test_common.h" #include "relay_chn_ctl.h" // For resetting the channels #if CONFIG_RELAY_CHN_ENABLE_TILTING #include "relay_chn_tilt.h" // For resetting tilt count #endif 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]); static void reset_channel(relay_chn_ctl_t *ctl) { ctl->pending_cmd = RELAY_CHN_CMD_NONE; ctl->state = RELAY_CHN_STATE_IDLE; ctl->output->direction = RELAY_CHN_DIRECTION_DEFAULT; ctl->run_info->last_run_cmd = RELAY_CHN_CMD_NONE; ctl->run_info->last_run_cmd_time_ms = 0; esp_timer_stop(ctl->inertia_timer); #if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT esp_timer_stop(ctl->run_limit_timer); ctl->run_limit_sec = CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC; #endif #if CONFIG_RELAY_CHN_ENABLE_TILTING relay_chn_tilt_reset_count(ctl->tilt_ctl); #endif #if CONFIG_RELAY_CHN_COUNT > 1 #else #endif } void reset_channels_to_defaults() { #if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_ctl_t *ctls = relay_chn_ctl_get_all(); TEST_ASSERT_NOT_NULL_MESSAGE(ctls, "reset_channels_to_defaults: relay_chn_ctl_get_all() returned NULL"); for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_ctl_t *ctl = &ctls[i]; TEST_ASSERT_NOT_NULL_MESSAGE(ctl, "ctl is NULL"); reset_channel(ctl); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i)); TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(i)); } #else relay_chn_ctl_t *ctl = relay_chn_ctl_get(); TEST_ASSERT_NOT_NULL_MESSAGE(ctl, "reset_channels_to_defaults: relay_chn_ctl_get() returned NULL"); reset_channel(ctl); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction()); #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); }