diff --git a/include/relay_chn.h b/include/relay_chn.h index 424add7..43e15f3 100644 --- a/include/relay_chn.h +++ b/include/relay_chn.h @@ -63,6 +63,18 @@ esp_err_t relay_chn_register_listener(relay_chn_state_listener_t listener); */ void relay_chn_unregister_listener(relay_chn_state_listener_t listener); +#if CONFIG_RELAY_CHN_ENABLE_TILTING +/** + * @brief Get the default tilting sensitivity for the relay channel. + * + * This function retrieves the default sensitivity for the relay channel's automatic + * tilting mechanism. + * + * @return Sensitivity value in percentage: 0 - 100%. + */ +uint8_t relay_chn_tilt_get_default_sensitivity(void); +#endif + #if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the state of the specified relay channel. diff --git a/src/relay_chn_tilt.c b/src/relay_chn_tilt.c index 6a2da91..ac3d1ff 100644 --- a/src/relay_chn_tilt.c +++ b/src/relay_chn_tilt.c @@ -199,6 +199,11 @@ static void relay_chn_tilt_issue_auto(relay_chn_tilt_ctl_t *tilt_ctl) } } +uint8_t relay_chn_tilt_get_default_sensitivity() +{ + return RELAY_CHN_TILT_DEFAULT_SENSITIVITY; +} + #if CONFIG_RELAY_CHN_COUNT > 1 static void relay_chn_tilt_issue_cmd_on_all_channels(relay_chn_tilt_cmd_t cmd) diff --git a/test_apps/main/test_relay_chn_tilt_multi.c b/test_apps/main/test_relay_chn_tilt_multi.c index 87b8d79..b5d9913 100644 --- a/test_apps/main/test_relay_chn_tilt_multi.c +++ b/test_apps/main/test_relay_chn_tilt_multi.c @@ -322,6 +322,17 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi TEST_ASSERT_EQUAL_UINT8_ARRAY(expect, vals, CONFIG_RELAY_CHN_COUNT); } +TEST_CASE("relay_chn_tilt_get_default_sensitivity returns correct value", "[relay_chn][tilt][sensitivity]") +{ + // The default sensitivity is calculated from default timing values. + // Default run time: 15ms, Min run time: 50ms, Max run time: 10ms. + // Formula: ( (DEFAULT_RUN - MIN_RUN) * 100 ) / (MAX_RUN - MIN_RUN) + // ( (15 - 50) * 100 ) / (10 - 50) = (-35 * 100) / -40 = -3500 / -40 = 87.5 + // As integer arithmetic, this is 87. + uint8_t expected_sensitivity = 87; + TEST_ASSERT_EQUAL_UINT8(expected_sensitivity, relay_chn_tilt_get_default_sensitivity()); +} + // Test sensitivity upper boundary for all set functions TEST_CASE("relay_chn_tilt_set_sensitivity functions handle upper boundary", "[relay_chn][tilt][sensitivity]") { diff --git a/test_apps/main/test_relay_chn_tilt_single.c b/test_apps/main/test_relay_chn_tilt_single.c index a2d6deb..185e535 100644 --- a/test_apps/main/test_relay_chn_tilt_single.c +++ b/test_apps/main/test_relay_chn_tilt_single.c @@ -205,6 +205,17 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi TEST_ASSERT_EQUAL_UINT8(42, relay_chn_tilt_get_sensitivity()); } +TEST_CASE("relay_chn_tilt_get_default_sensitivity returns correct value", "[relay_chn][tilt][sensitivity]") +{ + // The default sensitivity is calculated from default timing values. + // Default run time: 15ms, Min run time: 50ms, Max run time: 10ms. + // Formula: ( (DEFAULT_RUN - MIN_RUN) * 100 ) / (MAX_RUN - MIN_RUN) + // ( (15 - 50) * 100 ) / (10 - 50) = (-35 * 100) / -40 = -3500 / -40 = 87.5 + // As integer arithmetic, this is 87. + uint8_t expected_sensitivity = 87; + TEST_ASSERT_EQUAL_UINT8(expected_sensitivity, relay_chn_tilt_get_default_sensitivity()); +} + // Test sensitivity upper boundary TEST_CASE("relay_chn_tilt_set_sensitivity handles upper boundary", "[relay_chn][tilt][sensitivity]") {