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:
@@ -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