Implement specific *all functions
Specific `_*all` and `_*all_with` functions were implemented to make the API more concise and clean, and to replace the use of `RELAY_CHN_ID_ALL`, which caused confusion within the API. Refs #1085
This commit is contained in:
@@ -39,7 +39,7 @@ const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]);
|
||||
void reset_channels_to_idle_state()
|
||||
{
|
||||
#if CONFIG_RELAY_CHN_COUNT > 1
|
||||
relay_chn_stop(RELAY_CHN_ID_ALL);
|
||||
relay_chn_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(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));
|
||||
|
||||
@@ -70,11 +70,10 @@ TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]") {
|
||||
}
|
||||
|
||||
|
||||
// ### Broadcast Command (RELAY_CHN_ID_ALL) Tests
|
||||
|
||||
TEST_CASE("run_forward with ID_ALL sets all channels to FORWARD", "[relay_chn][core][id_all]")
|
||||
// ### Batch Control Tests
|
||||
TEST_CASE("run_forward_all sets all channels to FORWARD", "[relay_chn][core][batch]")
|
||||
{
|
||||
relay_chn_run_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
@@ -82,9 +81,9 @@ TEST_CASE("run_forward with ID_ALL sets all channels to FORWARD", "[relay_chn][c
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("run_reverse with ID_ALL sets all channels to REVERSE", "[relay_chn][core][id_all]")
|
||||
TEST_CASE("run_reverse_all sets all channels to REVERSE", "[relay_chn][core][batch]")
|
||||
{
|
||||
relay_chn_run_reverse(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
@@ -92,14 +91,14 @@ TEST_CASE("run_reverse with ID_ALL sets all channels to REVERSE", "[relay_chn][c
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("stop with ID_ALL stops all running channels", "[relay_chn][core][id_all]")
|
||||
TEST_CASE("stop_all stops all running channels", "[relay_chn][core][batch]")
|
||||
{
|
||||
// 1. Start all channels forward to ensure they are in a known running state
|
||||
relay_chn_run_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
|
||||
// 2. Stop all channels using the broadcast command
|
||||
relay_chn_stop(RELAY_CHN_ID_ALL);
|
||||
// 2. Stop all channels
|
||||
relay_chn_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
// 3. Verify all channels have transitioned to the FREE state
|
||||
@@ -138,7 +137,7 @@ TEST_CASE("Get state returns UNDEFINED when id is invalid", "[relay_chn][core]")
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_UNDEFINED, relay_chn_get_state(invalid_id));
|
||||
}
|
||||
// Test for running states also
|
||||
relay_chn_run_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
int invalid_id = relay_chn_count * 2 + i;
|
||||
@@ -153,7 +152,7 @@ TEST_CASE("Get state string returns UNKNOWN when id is invalid", "[relay_chn][co
|
||||
TEST_ASSERT_EQUAL_STRING("UNKNOWN", relay_chn_get_state_str(invalid_id));
|
||||
}
|
||||
// Test for running states also
|
||||
relay_chn_run_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
int invalid_id = relay_chn_count * 2 + i;
|
||||
@@ -295,10 +294,10 @@ TEST_CASE("Single channel direction can be flipped", "[relay_chn][core][directio
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(ch));
|
||||
}
|
||||
|
||||
TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][core][direction][id_all]")
|
||||
TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][core][direction][batch]")
|
||||
{
|
||||
// 1. Flip all channels
|
||||
relay_chn_flip_direction(RELAY_CHN_ID_ALL);
|
||||
relay_chn_flip_direction_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
// 2. Verify all channels are flipped
|
||||
@@ -307,7 +306,7 @@ TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][c
|
||||
}
|
||||
|
||||
// 3. Flip all back
|
||||
relay_chn_flip_direction(RELAY_CHN_ID_ALL);
|
||||
relay_chn_flip_direction_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
// 4. Verify all channels are back to default
|
||||
@@ -380,7 +379,7 @@ TEST_CASE("Test run limit stops channel after timeout", "[relay_chn][run_limit]"
|
||||
relay_chn_set_run_limit(i, TEST_SHORT_RUN_LIMIT_SEC);
|
||||
}
|
||||
|
||||
relay_chn_run_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_forward_all();
|
||||
|
||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
// Check running forward
|
||||
@@ -407,7 +406,7 @@ TEST_CASE("Test run limit reset on direction change and time out finally", "[rel
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait 1 second
|
||||
|
||||
// Change direction before timeout
|
||||
relay_chn_run_reverse(RELAY_CHN_ID_ALL);
|
||||
relay_chn_run_reverse_all();
|
||||
|
||||
// Wait for the inertia period (after which the reverse command will be dispatched)
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
@@ -162,7 +162,7 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
|
||||
}
|
||||
|
||||
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
|
||||
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
||||
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_tilt_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
||||
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
@@ -173,15 +173,15 @@ TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
||||
|
||||
// 2. Issue stop command
|
||||
relay_chn_stop(ch);
|
||||
relay_chn_tilt_stop(ch);
|
||||
// Stop command should apply immediately, setting state to FREE since last state was tilt.
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch));
|
||||
}
|
||||
|
||||
// ### Tilt Broadcast Command (RELAY_CHN_ID_ALL) Tests
|
||||
// ### Batch Tilt Control Tests
|
||||
|
||||
TEST_CASE("tilt_forward with ID_ALL sets all channels to TILT_FORWARD", "[relay_chn][tilt][id_all]")
|
||||
TEST_CASE("tilt_forward_all sets all channels to TILT_FORWARD", "[relay_chn][tilt][batch]")
|
||||
{
|
||||
// 1. Prepare all channels.
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
@@ -189,16 +189,17 @@ TEST_CASE("tilt_forward with ID_ALL sets all channels to TILT_FORWARD", "[relay_
|
||||
}
|
||||
|
||||
// 2. Issue tilt forward to all channels
|
||||
relay_chn_tilt_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms)); // Tilt from FREE doesn't have stop-inertia
|
||||
|
||||
// 3. Verify all channels are tilting forward
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
ESP_LOGI(TEST_TAG, "Checking channel %d", i);
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(i));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_chn][tilt][id_all]")
|
||||
TEST_CASE("tilt_reverse_all sets all channels to TILT_REVERSE", "[relay_chn][tilt][batch]")
|
||||
{
|
||||
// 1. Prepare all channels.
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
@@ -206,7 +207,7 @@ TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_
|
||||
}
|
||||
|
||||
// 2. Issue tilt reverse to all channels
|
||||
relay_chn_tilt_reverse(RELAY_CHN_ID_ALL);
|
||||
relay_chn_tilt_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
|
||||
// 3. Verify all channels are tilting reverse
|
||||
@@ -215,26 +216,27 @@ TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("tilt_stop with ID_ALL stops all tilting channels", "[relay_chn][tilt][id_all]")
|
||||
TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]")
|
||||
{
|
||||
// 1. Prepare and start all channels tilting forward
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_REVERSE);
|
||||
}
|
||||
relay_chn_tilt_forward(RELAY_CHN_ID_ALL);
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
|
||||
|
||||
// 2. Stop tilting on all channels
|
||||
relay_chn_tilt_stop(RELAY_CHN_ID_ALL);
|
||||
relay_chn_tilt_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
// 3. Verify all channels are free
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
ESP_LOGI(TEST_TAG, "Checking channel %d", i);
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("tilt_auto with ID_ALL tilts channels based on last run direction", "[relay_chn][tilt][id_all]")
|
||||
TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_chn][tilt][batch]")
|
||||
{
|
||||
// This test requires at least 2 channels to demonstrate different behaviors
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(2, relay_chn_count, "Test requires at least 2 channels");
|
||||
@@ -244,7 +246,7 @@ TEST_CASE("tilt_auto with ID_ALL tilts channels based on last run direction", "[
|
||||
prepare_channel_for_tilt(1, RELAY_CHN_CMD_REVERSE);
|
||||
|
||||
// 2. Issue auto tilt command to all channels
|
||||
relay_chn_tilt_auto(RELAY_CHN_ID_ALL);
|
||||
relay_chn_tilt_auto_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms)); // Tilt from FREE state is dispatched immediately
|
||||
|
||||
// 3. Verify channel 0 tilts forward (last run was forward) and channel 1 tilts reverse (last run was reverse)
|
||||
@@ -273,26 +275,23 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
|
||||
// Test sensitivity set/get
|
||||
TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]") {
|
||||
uint8_t ch = 0;
|
||||
uint8_t val = 0;
|
||||
relay_chn_tilt_set_sensitivity(ch, 0);
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity(ch, &val, 1));
|
||||
TEST_ASSERT_EQUAL_UINT8(0, val);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, relay_chn_tilt_get_sensitivity(ch));
|
||||
|
||||
relay_chn_tilt_set_sensitivity(ch, 50);
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity(ch, &val, 1));
|
||||
TEST_ASSERT_EQUAL_UINT8(50, val);
|
||||
TEST_ASSERT_EQUAL_UINT8(50, relay_chn_tilt_get_sensitivity(ch));
|
||||
|
||||
relay_chn_tilt_set_sensitivity(ch, 100);
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity(ch, &val, 1));
|
||||
TEST_ASSERT_EQUAL_UINT8(100, val);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(ch));
|
||||
// Set all channels
|
||||
relay_chn_tilt_set_sensitivity(RELAY_CHN_ID_ALL, 42);
|
||||
relay_chn_tilt_set_sensitivity_all_with(42);
|
||||
|
||||
uint8_t vals[CONFIG_RELAY_CHN_COUNT] = {0};
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity(RELAY_CHN_ID_ALL, vals, relay_chn_count));
|
||||
for (int i = 0; i < relay_chn_count; ++i) {
|
||||
TEST_ASSERT_EQUAL_UINT8(42, vals[i]);
|
||||
}
|
||||
uint8_t expect[CONFIG_RELAY_CHN_COUNT];
|
||||
memset(expect, 42, CONFIG_RELAY_CHN_COUNT);
|
||||
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity_all(vals));
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expect, vals, CONFIG_RELAY_CHN_COUNT);
|
||||
}
|
||||
|
||||
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails
|
||||
|
||||
Reference in New Issue
Block a user