1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Add slew rate limited angle delta based on threshold of degress/sec

This commit is contained in:
Adam Martini 2020-07-05 12:25:44 -07:00
parent 3aa35a77cb
commit e256a27b5a
2 changed files with 17 additions and 1 deletions

View File

@ -442,6 +442,20 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
if(angle < ext->arc.bg_angle_start) angle = ext->arc.bg_angle_start;
if(angle > bg_end) angle = bg_end;
/*Calculate the slew rate limited angle delta the threshold (degrees/sec)*/
int16_t delta_angle = angle - ext->last_angle;
uint16_t delta_ts_milli = lv_tick_get() - ext->last_timestamp;
int16_t delta_angle_threshold = (ext->threshold * 1000) / delta_ts_milli;
if (delta_angle > delta_angle_threshold) {
delta_angle = delta_angle_threshold;
} else if (delta_angle < -delta_angle_threshold) {
delta_angle = -delta_angle_threshold;
}
angle = ext->last_angle + delta_angle; /*Apply the limited angle change*/
ext->last_angle = angle; /*Cache angle for the next iteration*/
int16_t new_value = _lv_map(angle, ext->arc.bg_angle_start, bg_end, ext->min_value, ext->max_value);
/*Set the new value if it's larger than the threshold*/

View File

@ -71,8 +71,10 @@ typedef struct {
int16_t min_value; /*Minimum value of the rotary*/
int16_t max_value; /*Maximum value of the rotary*/
int16_t sensitivity; /*Control signal increment multiplier of the rotary*/
int16_t threshold; /*Drag increment threshold of the rotary*/
uint16_t dragging :1;
uint16_t threshold; /*Drag angle rate of change threshold of the rotary (degrees/sec)*/
int16_t last_timestamp; /*Last dragging event timestamp of the rotary*/
int16_t last_angle; /*Last dragging angle of the rotary*/
} lv_rotary_ext_t;
/** Built-in styles of rotary*/