Skip to content

Commit

Permalink
SUKU ranage inversion implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
SukuWc committed Aug 24, 2024
1 parent 466449d commit 8d6c3c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/host_based_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
name: Fuzzing Binary
path: |
fuzzer_test
input.bin
input.bin
10 changes: 10 additions & 0 deletions grid_common/grid_ui_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ uint8_t grid_ui_encoder_update_trigger(struct grid_ui_element* ele, uint64_t* en
return 0; // did not trigger
}

// positive delta means we wish to move closer to max value, megative delta means we wish to move closer to min value

// update lastrealtime
*encoder_last_real_time = grid_platform_rtc_get_micros();
int32_t* template_parameter_list = ele->template_parameter_list;
Expand All @@ -148,6 +150,14 @@ uint8_t grid_ui_encoder_update_trigger(struct grid_ui_element* ele, uint64_t* en
int32_t min = template_parameter_list[GRID_LUA_FNC_E_ENCODER_MIN_index];
int32_t max = template_parameter_list[GRID_LUA_FNC_E_ENCODER_MAX_index];

// inver range if min is greater then max
if (min > max) {
delta = -delta;
int32_t tmp = min;
min = max;
max = tmp;
}

double elapsed_ms = encoder_elapsed_time / MS_TO_US;

if (elapsed_ms > 25) {
Expand Down
20 changes: 14 additions & 6 deletions grid_common/host_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,32 @@ void test_function_should_calculateRelativeMode(void) {
// in relative mode value should be 64 after event reset
TEST_ASSERT_EQUAL_UINT8(64, grid_ui_element_get_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_VALUE_index));

// in relative mode value should be 0 after event reset when min max is set to -100 ... 100
grid_ui_element_set_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_MIN_index, -100); // set min to -100
grid_ui_element_set_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_MAX_index, 100); // set max to 100
grid_ui_event_reset(eve);
if (eve->parent->event_clear_cb != NULL) {
eve->parent->event_clear_cb(eve);
}
TEST_ASSERT_EQUAL_UINT8(0, grid_ui_element_get_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_VALUE_index));

for (uint8_t i = 0; i < ele->template_parameter_list_length; i++) {
printf("template_parameter_list[%d] = %d\n", i, template_parameter_list[i]);
// in relative mode value should be 0 after event reset when min max is set to 200 ... 100
grid_ui_element_set_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_MIN_index, 200);
grid_ui_element_set_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_MAX_index, 100);
grid_ui_event_reset(eve);
if (eve->parent->event_clear_cb != NULL) {
eve->parent->event_clear_cb(eve);
}

// in relative mode value should be 0 after event reset when min max is set to -100 ... 100
TEST_ASSERT_EQUAL_UINT8(0, grid_ui_element_get_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_VALUE_index));
TEST_ASSERT_EQUAL_UINT8(150, grid_ui_element_get_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_VALUE_index));

uint64_t last_real_time = 0;
int16_t delta = 1;
uint8_t is_endless_pot = 0;

for (uint8_t i = 0; i < ele->template_parameter_list_length; i++) {
printf("template_parameter_list[%d] = %d\n", i, template_parameter_list[i]);
}

grid_ui_encoder_update_trigger(ele, &last_real_time, delta, is_endless_pot);

for (uint8_t i = 0; i < ele->template_parameter_list_length; i++) {
Expand All @@ -73,7 +81,7 @@ void test_function_should_calculateRelativeMode(void) {

printf("test_function_should_calculateRelativeMode: %d\n", grid_ui_event_istriggered(eve));

TEST_ASSERT_EQUAL_UINT8(1, grid_ui_event_istriggered(eve)); // event triggering should happen
TEST_ASSERT_NOT_EQUAL_INT32(200, grid_ui_element_get_template_parameter(ele, GRID_LUA_FNC_E_ENCODER_VALUE_index));

// ....
}
Expand Down

0 comments on commit 8d6c3c8

Please sign in to comment.