Add update_value private function to lv_arc to prevent set_value return checks in the event of… (#1748)

Add update_value to lv_arc to update the value on range change.
This commit is contained in:
Adam Martini 2020-08-27 00:51:11 -07:00 committed by GitHub
parent 832000ad34
commit cb5faa64ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 43 deletions

View File

@ -687,9 +687,6 @@ typedef void * lv_obj_user_data_t;
# define LV_ROLLER_INF_PAGES 7
#endif
/*Rotary (dependencies: lv_arc, lv_btn)*/
#define LV_USE_ROTARY 1
/*Slider (dependencies: lv_bar)*/
#define LV_USE_SLIDER 1

View File

@ -1047,10 +1047,6 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h" */
#endif
#endif
/*Rotary (dependencies: lv_arc, lv_btn)*/
#ifndef LV_USE_ROTARY
#define LV_USE_ROTARY 1
#endif
/*Slider (dependencies: lv_bar)*/
#ifndef LV_USE_SLIDER
#define LV_USE_SLIDER 1

View File

@ -109,9 +109,6 @@ typedef enum {
#if LV_USE_ROLLER
LV_THEME_ROLLER,
#endif
#if LV_USE_ROTARY
LV_THEME_ROTARY,
#endif
#if LV_USE_SLIDER
LV_THEME_SLIDER,
#endif

View File

@ -34,6 +34,7 @@ static lv_style_list_t * lv_arc_get_style(lv_obj_t * arc, uint8_t part);
static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle, lv_arc_part_t part);
static void get_center(lv_obj_t * arc, lv_point_t * center, lv_coord_t * arc_r);
static void get_knob_area(lv_obj_t * arc, const lv_point_t * center, lv_coord_t r, lv_area_t * knob_area);
static void value_update(lv_obj_t * arc);
/**********************
* STATIC VARIABLES
@ -397,34 +398,7 @@ void lv_arc_set_value(lv_obj_t * arc, int16_t value)
if(ext->cur_value == new_value) return;
ext->cur_value = new_value;
int16_t bg_midpoint, range_midpoint, bg_end = ext->bg_angle_end;
if (ext->bg_angle_end < ext->bg_angle_start) bg_end = ext->bg_angle_end + 360;
int16_t angle;
switch(ext->type) {
case LV_ARC_TYPE_SYMMETRIC:
bg_midpoint = (ext->bg_angle_start + bg_end) / 2;
range_midpoint = (int32_t)(ext->min_value + ext->max_value) / 2;
if (ext->cur_value < range_midpoint) {
angle = _lv_map(ext->cur_value, ext->min_value, range_midpoint, ext->bg_angle_start, bg_midpoint);
lv_arc_set_start_angle(arc, angle);
lv_arc_set_end_angle(arc, bg_midpoint);
} else {
angle = _lv_map(ext->cur_value, range_midpoint, ext->max_value, bg_midpoint, bg_end);
lv_arc_set_start_angle(arc, bg_midpoint);
lv_arc_set_end_angle(arc, angle);
}
break;
case LV_ARC_TYPE_REVERSE:
angle = _lv_map(ext->cur_value, ext->min_value, ext->max_value, ext->bg_angle_start, bg_end);
lv_arc_set_start_angle(arc, angle);
break;
default: /** LV_ARC_TYPE_NORMAL*/
angle = _lv_map(ext->cur_value, ext->min_value, ext->max_value, ext->bg_angle_start, bg_end);
lv_arc_set_end_angle(arc, angle);
}
ext->last_angle = angle; /*Cache angle for slew rate limiting*/
value_update(arc);
}
/**
@ -450,7 +424,7 @@ void lv_arc_set_range(lv_obj_t * arc, int16_t min, int16_t max)
ext->cur_value = max;
}
lv_arc_set_value(arc, ext->cur_value);
value_update(arc); /* value has changed relative to the new range */
}
/**
@ -1066,4 +1040,42 @@ static void get_knob_area(lv_obj_t * arc, const lv_point_t * center, lv_coord_t
knob_area->y2 = center->y + knob_y + bottom_knob + indic_width_half;
}
/**
* Used internally to update arc angles after a value change
* @param arc pointer to a arc object
*/
static void value_update(lv_obj_t * arc)
{
lv_arc_ext_t *ext = (lv_arc_ext_t *)lv_obj_get_ext_attr(arc);
int16_t bg_midpoint, range_midpoint, bg_end = ext->bg_angle_end;
if (ext->bg_angle_end < ext->bg_angle_start) bg_end = ext->bg_angle_end + 360;
int16_t angle;
switch(ext->type) {
case LV_ARC_TYPE_SYMMETRIC:
bg_midpoint = (ext->bg_angle_start + bg_end) / 2;
range_midpoint = (int32_t)(ext->min_value + ext->max_value) / 2;
if (ext->cur_value < range_midpoint) {
angle = _lv_map(ext->cur_value, ext->min_value, range_midpoint, ext->bg_angle_start, bg_midpoint);
lv_arc_set_start_angle(arc, angle);
lv_arc_set_end_angle(arc, bg_midpoint);
} else {
angle = _lv_map(ext->cur_value, range_midpoint, ext->max_value, bg_midpoint, bg_end);
lv_arc_set_start_angle(arc, bg_midpoint);
lv_arc_set_end_angle(arc, angle);
}
break;
case LV_ARC_TYPE_REVERSE:
angle = _lv_map(ext->cur_value, ext->min_value, ext->max_value, ext->bg_angle_start, bg_end);
lv_arc_set_start_angle(arc, angle);
break;
default: /** LV_ARC_TYPE_NORMAL*/
angle = _lv_map(ext->cur_value, ext->min_value, ext->max_value, ext->bg_angle_start, bg_end);
lv_arc_set_end_angle(arc, angle);
}
ext->last_angle = angle; /*Cache angle for slew rate limiting*/
}
#endif

View File

@ -120,7 +120,6 @@ minimal_monochrome = {
"LV_USE_PAGE":0,
"LV_USE_SPINNER":0,
"LV_USE_ROLLER":0,
"LV_USE_ROTARY":0,
"LV_USE_SLIDER":0,
"LV_USE_SPINBOX":0,
"LV_USE_SWITCH":0,
@ -197,7 +196,6 @@ all_obj_minimal_features = {
"LV_USE_PAGE":1,
"LV_USE_SPINNER":0, #Disabled beacsue needs anim
"LV_USE_ROLLER":1,
"LV_USE_ROTARY":1,
"LV_USE_SLIDER":1,
"LV_USE_SPINBOX":1,
"LV_USE_SWITCH":1,
@ -276,7 +274,6 @@ all_obj_all_features = {
"LV_USE_PAGE":1,
"LV_USE_SPINNER":1,
"LV_USE_ROLLER":1,
"LV_USE_ROTARY":1,
"LV_USE_SLIDER":1,
"LV_USE_SPINBOX":1,
"LV_USE_SWITCH":1,
@ -368,7 +365,6 @@ advanced_features = {
"LV_USE_PAGE":1,
"LV_USE_SPINNER":1,
"LV_USE_ROLLER":1,
"LV_USE_ROTARY":1,
"LV_USE_SLIDER":1,
"LV_USE_SPINBOX":1,
"LV_USE_SWITCH":1,