Add default tilt sensitivity get function
Added `relay_chn_tilt_get_default_sensitivity` function and test cases. Refs #1085 and fixes #1101
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]")
|
||||
{
|
||||
|
||||
@@ -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]")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user