Rotary types. Add symmetric value setter
This commit is contained in:
@@ -147,13 +147,38 @@ void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim
|
|||||||
|
|
||||||
ext->cur_value = new_value;
|
ext->cur_value = new_value;
|
||||||
|
|
||||||
if (ext->reverse) {
|
switch(ext->type) {
|
||||||
|
case LV_ROTARY_TYPE_SYMMETRIC:
|
||||||
|
unint16_t bg_midpoint;
|
||||||
|
if (ext->arc.bg_angle_end < ext->arc.bg_angle_start) {
|
||||||
|
bg_midpoint = (ext->arc.bg_angle_start + ext->arc.bg_angle_end + 360) / 2;
|
||||||
|
} else {
|
||||||
|
bg_midpoint = (ext->arc.bg_angle_start + ext->arc.bg_angle_end) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t range_midpoint = (ext->min_value + ext->max_value) / 2;
|
||||||
|
if (ext->cur_value < range_midpoint) {
|
||||||
|
lv_arc_set_start_angle(
|
||||||
|
rotary,
|
||||||
|
_lv_map(ext->cur_value, ext->max_value, ext->min_value,
|
||||||
|
ext->arc.bg_angle_start, bg_midpoint)
|
||||||
|
);
|
||||||
|
} else if (ext->cur_value > range_midpoint) {
|
||||||
|
lv_arc_set_start_angle(
|
||||||
|
rotary,
|
||||||
|
_lv_map(ext->cur_value, ext->max_value, ext->min_value,
|
||||||
|
ext->arc.bg_angle_start, bg_midpoint)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LV_ROTARY_TYPE_REVERSE:
|
||||||
lv_arc_set_start_angle(
|
lv_arc_set_start_angle(
|
||||||
rotary,
|
rotary,
|
||||||
_lv_map(ext->cur_value, ext->max_value, ext->min_value,
|
_lv_map(ext->cur_value, ext->max_value, ext->min_value,
|
||||||
360 + ext->arc.bg_angle_end, ext->arc.bg_angle_start)
|
360 + ext->arc.bg_angle_end, ext->arc.bg_angle_start)
|
||||||
);
|
);
|
||||||
} else {
|
break;
|
||||||
|
default: /** LV_ROTARY_TYPE_NORMAL*/
|
||||||
lv_arc_set_end_angle(
|
lv_arc_set_end_angle(
|
||||||
rotary,
|
rotary,
|
||||||
_lv_map(ext->cur_value, ext->min_value, ext->max_value,
|
_lv_map(ext->cur_value, ext->min_value, ext->max_value,
|
||||||
@@ -188,42 +213,6 @@ void lv_rotary_set_range(lv_obj_t * rotary, int16_t min, int16_t max)
|
|||||||
lv_rotary_set_value(rotary, ext->cur_value, false);
|
lv_rotary_set_value(rotary, ext->cur_value, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the rotary symmetric to zero. The indicator will grow from zero instead of the minimum
|
|
||||||
* position.
|
|
||||||
* @param rotary pointer to a rotary object
|
|
||||||
* @param en true: enable disable symmetric behavior; false: disable
|
|
||||||
*/
|
|
||||||
void lv_rotary_set_symmetric(lv_obj_t * rotary, bool en)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
|
|
||||||
|
|
||||||
lv_rotary_ext_t *ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
|
||||||
ext->sym = en;
|
|
||||||
|
|
||||||
lv_obj_invalidate(rotary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse rotary behavior. The indicator will grow from arc end instead of arc start.
|
|
||||||
* position.
|
|
||||||
* @param rotary pointer to a rotary object
|
|
||||||
* @param reverse true: enable disable reverse behavior; false: disable
|
|
||||||
*/
|
|
||||||
void lv_rotary_set_reverse(lv_obj_t * rotary, bool reverse)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
|
|
||||||
|
|
||||||
lv_rotary_ext_t *ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
|
||||||
int16_t val = ext->cur_value;
|
|
||||||
|
|
||||||
ext->cur_value = -1; /** Force set_value handling*/
|
|
||||||
ext->reverse = reverse;
|
|
||||||
|
|
||||||
lv_rotary_set_end_angle(rotary, ext->arc.bg_angle_end);
|
|
||||||
lv_rotary_set_value(rotary, val, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the sesitivity of rotary knob increments
|
* Set the sesitivity of rotary knob increments
|
||||||
* position.
|
* position.
|
||||||
@@ -252,6 +241,42 @@ void lv_rotary_set_threshold(lv_obj_t * rotary, uint16_t threshold)
|
|||||||
ext->threshold = threshold;
|
ext->threshold = threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the type of rotary.
|
||||||
|
* @param rotary pointer to rotary object
|
||||||
|
* @param type rotary type
|
||||||
|
*/
|
||||||
|
void lv_rotary_set_type(lv_obj_t * rotary, lv_rotary_type_t type)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
|
||||||
|
|
||||||
|
lv_rotary_ext_t *ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
||||||
|
int16_t val = ext->cur_value;
|
||||||
|
|
||||||
|
ext->type = type;
|
||||||
|
ext->cur_value = -1; /** Force set_value handling*/
|
||||||
|
|
||||||
|
switch(ext->type) {
|
||||||
|
case LV_ROTARY_TYPE_SYMMETRIC:
|
||||||
|
unint16_t bg_midpoint;
|
||||||
|
if (ext->arc.bg_angle_end < ext->arc.bg_angle_start) {
|
||||||
|
bg_midpoint = (ext->arc.bg_angle_start + ext->arc.bg_angle_end + 360) / 2;
|
||||||
|
} else {
|
||||||
|
bg_midpoint = (ext->arc.bg_angle_start + ext->arc.bg_angle_end) / 2;
|
||||||
|
}
|
||||||
|
lv_rotary_set_start_angle(rotary, bg_midpoint);
|
||||||
|
lv_rotary_set_start_angle(rotary, bg_midpoint);
|
||||||
|
break;
|
||||||
|
case LV_ROTARY_TYPE_REVERSE:
|
||||||
|
lv_rotary_set_end_angle(rotary, ext->arc.bg_angle_end);
|
||||||
|
break;
|
||||||
|
default: /** LV_ROTARY_TYPE_NORMAL*/
|
||||||
|
lv_rotary_set_start_angle(rotary, ext->arc.bg_angle_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_rotary_set_value(rotary, val, false);
|
||||||
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@@ -308,6 +333,19 @@ bool lv_rotary_is_dragged(const lv_obj_t * rotary)
|
|||||||
return ext->dragging;
|
return ext->dragging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether the rotary is type or not.
|
||||||
|
* @param rotary pointer to a rotary object
|
||||||
|
* @return rotary type
|
||||||
|
*/
|
||||||
|
lv_rotary_type_t lv_rotary_get_type(const lv_obj_t * rotary)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
|
||||||
|
|
||||||
|
lv_rotary_ext_t * ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
||||||
|
return ext->type;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ extern "C" {
|
|||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
LV_ROTARY_TYPE_NORMAL
|
LV_ROTARY_TYPE_NORMAL,
|
||||||
|
LV_ROTARY_TYPE_SYMMETRIC,
|
||||||
|
LV_ROTARY_TYPE_REVERSE
|
||||||
};
|
};
|
||||||
typedef uint8_t lv_rotary_type_t;
|
typedef uint8_t lv_rotary_type_t;
|
||||||
|
|
||||||
@@ -71,8 +73,7 @@ typedef struct {
|
|||||||
int16_t threshold; /*Increment threshold of the rotary*/
|
int16_t threshold; /*Increment threshold of the rotary*/
|
||||||
lv_coord_t last_drag_x; /*Last drag x coordintate of the rotary*/
|
lv_coord_t last_drag_x; /*Last drag x coordintate of the rotary*/
|
||||||
uint16_t dragging :1;
|
uint16_t dragging :1;
|
||||||
uint16_t sym :1;
|
uint16_t type :2;
|
||||||
uint16_t reverse :1;
|
|
||||||
|
|
||||||
} lv_rotary_ext_t;
|
} lv_rotary_ext_t;
|
||||||
|
|
||||||
@@ -117,14 +118,6 @@ void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim
|
|||||||
*/
|
*/
|
||||||
void lv_rotary_set_range(lv_obj_t * rotary, int16_t min, int16_t max);
|
void lv_rotary_set_range(lv_obj_t * rotary, int16_t min, int16_t max);
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the rotary symmetric to zero. The indicator will grow from zero instead of the minimum
|
|
||||||
* position.
|
|
||||||
* @param rotary pointer to a rotary object
|
|
||||||
* @param en true: enable disable symmetric behavior; false: disable
|
|
||||||
*/
|
|
||||||
void lv_rotary_set_symmetric(lv_obj_t * rotary, bool en);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse rotary behavior. The indicator will grow from arc end instead of arc start.
|
* Reverse rotary behavior. The indicator will grow from arc end instead of arc start.
|
||||||
* position.
|
* position.
|
||||||
@@ -149,6 +142,13 @@ void lv_rotary_set_sensitivity(lv_obj_t * rotary, uint16_t sensitivity);
|
|||||||
*/
|
*/
|
||||||
void lv_rotary_set_threshold(lv_obj_t * rotary, uint16_t threshold);
|
void lv_rotary_set_threshold(lv_obj_t * rotary, uint16_t threshold);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the type of rotary.
|
||||||
|
* @param rotary pointer to rotary object
|
||||||
|
* @param type rotary type
|
||||||
|
*/
|
||||||
|
void lv_rotary_set_type(lv_obj_t * rotary, lv_rotary_type_t type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the start angle of rotary indicator. 0 deg: right, 90 bottom, etc.
|
* Set the start angle of rotary indicator. 0 deg: right, 90 bottom, etc.
|
||||||
* @param arc pointer to an arc object
|
* @param arc pointer to an arc object
|
||||||
@@ -292,15 +292,11 @@ int16_t lv_rotary_get_max_value(const lv_obj_t * rotary);
|
|||||||
bool lv_rotary_is_dragged(const lv_obj_t * rotary);
|
bool lv_rotary_is_dragged(const lv_obj_t * rotary);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the rotary is symmetric or not.
|
* Get whether the rotary is type or not.
|
||||||
* @param rotary pointer to a rotary object
|
* @param rotary pointer to a rotary object
|
||||||
* @return true: symmetric is enabled; false: disable
|
* @return rotary type
|
||||||
*/
|
*/
|
||||||
static inline bool lv_rotary_get_symmetric(lv_obj_t * rotary)
|
lv_rotary_type_t lv_rotary_get_type(const lv_obj_t * rotary);
|
||||||
{
|
|
||||||
lv_rotary_ext_t * ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
|
||||||
return ext->sym;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current state of the rotary
|
* Get the current state of the rotary
|
||||||
@@ -308,7 +304,7 @@ static inline bool lv_rotary_get_symmetric(lv_obj_t * rotary)
|
|||||||
* @return the state of the rotary (from lv_rotary_state_t enum).
|
* @return the state of the rotary (from lv_rotary_state_t enum).
|
||||||
* If the rotary is in disabled state `LV_ROTARY_STATE_DISABLED` will be ORed to the other rotary states.
|
* If the rotary is in disabled state `LV_ROTARY_STATE_DISABLED` will be ORed to the other rotary states.
|
||||||
*/
|
*/
|
||||||
static inline lv_btn_state_t lv_rotary_get_state(const lv_obj_t * rotary) {
|
static inline lv_rotary_state_t lv_rotary_get_state(const lv_obj_t * rotary) {
|
||||||
return lv_btn_get_state(rotary);
|
return lv_btn_get_state(rotary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user