feat(arc): add float support
This commit is contained in:
@@ -147,7 +147,7 @@ static void arc_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * arc = lv_event_get_target(e);
|
||||
|
||||
int32_t v = lv_arc_get_angle_end(arc);
|
||||
int32_t v = (int32_t)lv_arc_get_angle_end(arc);
|
||||
lv_obj_set_style_transform_rotation(card_to_transform, v * 10, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
#define LV_SPRINTF_INCLUDE LV_RTTHREAD_INCLUDE
|
||||
#define LV_SNPRINTF rt_snprintf
|
||||
#define LV_VSNPRINTF rt_vsnprintf
|
||||
#define LV_SPRINTF_USE_FLOAT 0
|
||||
|
||||
/*=====================
|
||||
* COMPILER SETTINGS
|
||||
|
||||
@@ -57,11 +57,6 @@
|
||||
#endif
|
||||
#endif /*LV_USE_MALLOC == LV_STDLIB_BUILTIN*/
|
||||
|
||||
|
||||
#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN
|
||||
#define LV_SPRINTF_USE_FLOAT 0
|
||||
#endif /*LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN*/
|
||||
|
||||
/*====================
|
||||
HAL SETTINGS
|
||||
*====================*/
|
||||
@@ -267,20 +262,20 @@
|
||||
|
||||
/*Number of stops allowed per gradient. Increase this to allow more stops.
|
||||
*This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/
|
||||
#define LV_GRADIENT_MAX_STOPS 2
|
||||
#define LV_GRADIENT_MAX_STOPS 2
|
||||
|
||||
/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently.
|
||||
* 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
|
||||
/* Add 2 x 32 bit variables to each lv_obj_t to speed up getting style properties */
|
||||
#define LV_OBJ_STYLE_CACHE 0
|
||||
#define LV_OBJ_STYLE_CACHE 0
|
||||
|
||||
/* Add `id` field to `lv_obj_t` */
|
||||
#define LV_USE_OBJ_ID 0
|
||||
#define LV_USE_OBJ_ID 0
|
||||
|
||||
/* Use lvgl builtin method for obj ID */
|
||||
#define LV_USE_OBJ_ID_BUILTIN 0
|
||||
#define LV_USE_OBJ_ID_BUILTIN 0
|
||||
|
||||
/*=====================
|
||||
* COMPILER SETTINGS
|
||||
@@ -321,6 +316,9 @@
|
||||
/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/
|
||||
#define LV_USE_LARGE_COORD 0
|
||||
|
||||
/* Use `float` as `lv_value_precise_t` */
|
||||
#define LV_USE_FLOAT 0
|
||||
|
||||
/*==================
|
||||
* FONT USAGE
|
||||
*===================*/
|
||||
|
||||
@@ -154,6 +154,11 @@ LV_EXPORT_CONST_INT(LV_DPI_DEF);
|
||||
|
||||
#undef _LV_KCONFIG_PRESENT
|
||||
|
||||
#if LV_USE_FLOAT
|
||||
typedef float lv_value_precise_t;
|
||||
#else
|
||||
typedef int32_t lv_value_precise_t;
|
||||
#endif
|
||||
|
||||
/*Set some defines if a dependency is disabled*/
|
||||
#if LV_USE_LOG == 0
|
||||
|
||||
@@ -66,13 +66,16 @@ void lv_draw_arc(lv_layer_t * layer, const lv_draw_arc_dsc_t * dsc)
|
||||
LV_PROFILER_END;
|
||||
}
|
||||
|
||||
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
|
||||
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, lv_value_precise_t start_angle,
|
||||
lv_value_precise_t end_angle,
|
||||
lv_coord_t w, bool rounded, lv_area_t * area)
|
||||
{
|
||||
lv_coord_t rout = radius;
|
||||
int32_t start_angle_int = (int32_t) start_angle;
|
||||
int32_t end_angle_int = (int32_t) end_angle;
|
||||
|
||||
/*Special case: full arc invalidation */
|
||||
if(end_angle == start_angle + 360) {
|
||||
if(end_angle_int == start_angle_int + 360) {
|
||||
area->x1 = x - rout;
|
||||
area->y1 = y - rout;
|
||||
area->x2 = x + rout;
|
||||
@@ -80,75 +83,75 @@ void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t
|
||||
return;
|
||||
}
|
||||
|
||||
if(start_angle > 360) start_angle -= 360;
|
||||
if(end_angle > 360) end_angle -= 360;
|
||||
if(start_angle_int > 360) start_angle_int -= 360;
|
||||
if(end_angle_int > 360) end_angle_int -= 360;
|
||||
|
||||
lv_coord_t rin = radius - w;
|
||||
lv_coord_t extra_area = rounded ? w / 2 + 1 : 0;
|
||||
uint8_t start_quarter = start_angle / 90;
|
||||
uint8_t end_quarter = end_angle / 90;
|
||||
uint8_t start_quarter = start_angle_int / 90;
|
||||
uint8_t end_quarter = end_angle_int / 90;
|
||||
|
||||
/*360 deg still counts as quarter 3 (360 / 90 would be 4)*/
|
||||
if(start_quarter == 4) start_quarter = 3;
|
||||
if(end_quarter == 4) end_quarter = 3;
|
||||
|
||||
if(start_quarter == end_quarter && start_angle <= end_angle) {
|
||||
if(start_quarter == end_quarter && start_angle_int <= end_angle_int) {
|
||||
if(start_quarter == 0) {
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
}
|
||||
else if(start_quarter == 1) {
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
}
|
||||
else if(start_quarter == 2) {
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
}
|
||||
else if(start_quarter == 3) {
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
}
|
||||
}
|
||||
else if(start_quarter == 0 && end_quarter == 1) {
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle),
|
||||
lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle_int),
|
||||
lv_trigo_sin(start_angle_int)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + rout + extra_area;
|
||||
}
|
||||
else if(start_quarter == 1 && end_quarter == 2) {
|
||||
area->x1 = x - rout - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle + 90),
|
||||
lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle_int + 90),
|
||||
lv_trigo_sin(end_angle_int + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
}
|
||||
else if(start_quarter == 2 && end_quarter == 3) {
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y - rout - extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle) * rin,
|
||||
lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle_int) * rin,
|
||||
lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
}
|
||||
else if(start_quarter == 3 && end_quarter == 0) {
|
||||
area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle + 90),
|
||||
lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle_int + 90),
|
||||
lv_trigo_sin(start_angle_int + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
|
||||
area->x2 = x + rout + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -30,8 +30,8 @@ typedef struct {
|
||||
|
||||
lv_color_t color;
|
||||
lv_coord_t width;
|
||||
uint16_t start_angle;
|
||||
uint16_t end_angle;
|
||||
lv_value_precise_t start_angle;
|
||||
lv_value_precise_t end_angle;
|
||||
lv_point_t center;
|
||||
uint16_t radius;
|
||||
const void * img_src;
|
||||
@@ -60,7 +60,8 @@ void lv_draw_arc(struct _lv_layer_t * layer, const lv_draw_arc_dsc_t * dsc);
|
||||
* @param rounded true: the arc is rounded
|
||||
* @param area store the area to invalidate here
|
||||
*/
|
||||
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
|
||||
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, lv_value_precise_t start_angle,
|
||||
lv_value_precise_t end_angle,
|
||||
lv_coord_t w, bool rounded, lv_area_t * area);
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -82,8 +82,8 @@ void lv_draw_sw_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc, c
|
||||
area_in.x2 -= dsc->width;
|
||||
area_in.y2 -= dsc->width;
|
||||
|
||||
int32_t start_angle = dsc->start_angle;
|
||||
int32_t end_angle = dsc->end_angle;
|
||||
int32_t start_angle = (int32_t)dsc->start_angle;
|
||||
int32_t end_angle = (int32_t)dsc->end_angle;
|
||||
while(start_angle >= 360) start_angle -= 360;
|
||||
while(end_angle >= 360) end_angle -= 360;
|
||||
|
||||
|
||||
@@ -149,17 +149,6 @@
|
||||
#endif
|
||||
#endif /*LV_USE_MALLOC == LV_STDLIB_BUILTIN*/
|
||||
|
||||
|
||||
#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN
|
||||
#ifndef LV_SPRINTF_USE_FLOAT
|
||||
#ifdef CONFIG_LV_SPRINTF_USE_FLOAT
|
||||
#define LV_SPRINTF_USE_FLOAT CONFIG_LV_SPRINTF_USE_FLOAT
|
||||
#else
|
||||
#define LV_SPRINTF_USE_FLOAT 0
|
||||
#endif
|
||||
#endif
|
||||
#endif /*LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN*/
|
||||
|
||||
/*====================
|
||||
HAL SETTINGS
|
||||
*====================*/
|
||||
@@ -737,7 +726,7 @@
|
||||
#ifdef CONFIG_LV_GRADIENT_MAX_STOPS
|
||||
#define LV_GRADIENT_MAX_STOPS CONFIG_LV_GRADIENT_MAX_STOPS
|
||||
#else
|
||||
#define LV_GRADIENT_MAX_STOPS 2
|
||||
#define LV_GRADIENT_MAX_STOPS 2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -747,7 +736,7 @@
|
||||
#ifdef CONFIG_LV_COLOR_MIX_ROUND_OFS
|
||||
#define LV_COLOR_MIX_ROUND_OFS CONFIG_LV_COLOR_MIX_ROUND_OFS
|
||||
#else
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -756,7 +745,7 @@
|
||||
#ifdef CONFIG_LV_OBJ_STYLE_CACHE
|
||||
#define LV_OBJ_STYLE_CACHE CONFIG_LV_OBJ_STYLE_CACHE
|
||||
#else
|
||||
#define LV_OBJ_STYLE_CACHE 0
|
||||
#define LV_OBJ_STYLE_CACHE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -765,7 +754,7 @@
|
||||
#ifdef CONFIG_LV_USE_OBJ_ID
|
||||
#define LV_USE_OBJ_ID CONFIG_LV_USE_OBJ_ID
|
||||
#else
|
||||
#define LV_USE_OBJ_ID 0
|
||||
#define LV_USE_OBJ_ID 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -774,7 +763,7 @@
|
||||
#ifdef CONFIG_LV_USE_OBJ_ID_BUILTIN
|
||||
#define LV_USE_OBJ_ID_BUILTIN CONFIG_LV_USE_OBJ_ID_BUILTIN
|
||||
#else
|
||||
#define LV_USE_OBJ_ID_BUILTIN 0
|
||||
#define LV_USE_OBJ_ID_BUILTIN 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -887,6 +876,15 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Use `float` as `lv_value_precise_t` */
|
||||
#ifndef LV_USE_FLOAT
|
||||
#ifdef CONFIG_LV_USE_FLOAT
|
||||
#define LV_USE_FLOAT CONFIG_LV_USE_FLOAT
|
||||
#else
|
||||
#define LV_USE_FLOAT 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*==================
|
||||
* FONT USAGE
|
||||
*===================*/
|
||||
@@ -2747,6 +2745,11 @@ LV_EXPORT_CONST_INT(LV_DPI_DEF);
|
||||
|
||||
#undef _LV_KCONFIG_PRESENT
|
||||
|
||||
#if LV_USE_FLOAT
|
||||
typedef float lv_value_precise_t;
|
||||
#else
|
||||
typedef int32_t lv_value_precise_t;
|
||||
#endif
|
||||
|
||||
/*Set some defines if a dependency is disabled*/
|
||||
#if LV_USE_LOG == 0
|
||||
|
||||
@@ -38,7 +38,6 @@ extern "C" {
|
||||
#define LV_OS_CMSIS_RTOS2 3
|
||||
#define LV_OS_CUSTOM 255
|
||||
|
||||
|
||||
#define LV_STDLIB_BUILTIN 0
|
||||
#define LV_STDLIB_CLIB 1
|
||||
#define LV_STDLIB_MICROPYTHON 2
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "../lv_sprintf.h"
|
||||
#include "../../misc/lv_types.h"
|
||||
|
||||
#define PRINTF_DISABLE_SUPPORT_FLOAT (!LV_SPRINTF_USE_FLOAT)
|
||||
#define PRINTF_DISABLE_SUPPORT_FLOAT (!LV_USE_FLOAT)
|
||||
|
||||
// 'ntoa' conversion buffer size, this must be big enough to hold one converted
|
||||
// numeric number including padded zeros (dynamically created on stack)
|
||||
|
||||
@@ -37,14 +37,15 @@
|
||||
static void lv_arc_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
static void lv_arc_draw(lv_event_t * e);
|
||||
static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
||||
static void inv_arc_area(lv_obj_t * arc, uint32_t start_angle, uint32_t end_angle, lv_part_t part);
|
||||
static void inv_arc_area(lv_obj_t * arc, lv_value_precise_t start_angle, lv_value_precise_t end_angle, lv_part_t part);
|
||||
static void inv_knob_area(lv_obj_t * obj);
|
||||
static void get_center(const lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r);
|
||||
static lv_coord_t get_angle(const lv_obj_t * obj);
|
||||
static lv_value_precise_t get_angle(const lv_obj_t * obj);
|
||||
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 lv_coord_t knob_get_extra_size(lv_obj_t * obj);
|
||||
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle, const uint32_t tolerance_deg);
|
||||
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const lv_value_precise_t angle,
|
||||
const lv_value_precise_t tolerance_deg);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -86,15 +87,15 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
void lv_arc_set_start_angle(lv_obj_t * obj, uint32_t start)
|
||||
void lv_arc_set_start_angle(lv_obj_t * obj, lv_value_precise_t start)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
if(start > 360) start -= 360;
|
||||
|
||||
int16_t old_delta = arc->indic_angle_end - arc->indic_angle_start;
|
||||
int16_t new_delta = arc->indic_angle_end - start;
|
||||
lv_value_precise_t old_delta = arc->indic_angle_end - arc->indic_angle_start;
|
||||
lv_value_precise_t new_delta = arc->indic_angle_end - start;
|
||||
|
||||
if(old_delta < 0) old_delta = 360 + old_delta;
|
||||
if(new_delta < 0) new_delta = 360 + new_delta;
|
||||
@@ -110,14 +111,14 @@ void lv_arc_set_start_angle(lv_obj_t * obj, uint32_t start)
|
||||
inv_knob_area(obj);
|
||||
}
|
||||
|
||||
void lv_arc_set_end_angle(lv_obj_t * obj, uint32_t end)
|
||||
void lv_arc_set_end_angle(lv_obj_t * obj, lv_value_precise_t end)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
if(end > 360) end -= 360;
|
||||
|
||||
int32_t old_delta = arc->indic_angle_end - arc->indic_angle_start;
|
||||
int32_t new_delta = end - arc->indic_angle_start;
|
||||
lv_value_precise_t old_delta = arc->indic_angle_end - arc->indic_angle_start;
|
||||
lv_value_precise_t new_delta = end - arc->indic_angle_start;
|
||||
|
||||
if(old_delta < 0) old_delta = 360 + old_delta;
|
||||
if(new_delta < 0) new_delta = 360 + new_delta;
|
||||
@@ -133,21 +134,21 @@ void lv_arc_set_end_angle(lv_obj_t * obj, uint32_t end)
|
||||
inv_knob_area(obj);
|
||||
}
|
||||
|
||||
void lv_arc_set_angles(lv_obj_t * obj, uint32_t start, uint32_t end)
|
||||
void lv_arc_set_angles(lv_obj_t * obj, lv_value_precise_t start, lv_value_precise_t end)
|
||||
{
|
||||
lv_arc_set_end_angle(obj, end);
|
||||
lv_arc_set_start_angle(obj, start);
|
||||
}
|
||||
|
||||
void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint32_t start)
|
||||
void lv_arc_set_bg_start_angle(lv_obj_t * obj, lv_value_precise_t start)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
if(start > 360) start -= 360;
|
||||
|
||||
int32_t old_delta = arc->bg_angle_end - arc->bg_angle_start;
|
||||
int32_t new_delta = arc->bg_angle_end - start;
|
||||
lv_value_precise_t old_delta = arc->bg_angle_end - arc->bg_angle_start;
|
||||
lv_value_precise_t new_delta = arc->bg_angle_end - start;
|
||||
|
||||
if(old_delta < 0) old_delta = 360 + old_delta;
|
||||
if(new_delta < 0) new_delta = 360 + new_delta;
|
||||
@@ -161,15 +162,15 @@ void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint32_t start)
|
||||
value_update(obj);
|
||||
}
|
||||
|
||||
void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint32_t end)
|
||||
void lv_arc_set_bg_end_angle(lv_obj_t * obj, lv_value_precise_t end)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
if(end > 360) end -= 360;
|
||||
|
||||
int32_t old_delta = arc->bg_angle_end - arc->bg_angle_start;
|
||||
int32_t new_delta = end - arc->bg_angle_start;
|
||||
lv_value_precise_t old_delta = arc->bg_angle_end - arc->bg_angle_start;
|
||||
lv_value_precise_t new_delta = end - arc->bg_angle_start;
|
||||
|
||||
if(old_delta < 0) old_delta = 360 + old_delta;
|
||||
if(new_delta < 0) new_delta = 360 + new_delta;
|
||||
@@ -183,7 +184,7 @@ void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint32_t end)
|
||||
value_update(obj);
|
||||
}
|
||||
|
||||
void lv_arc_set_bg_angles(lv_obj_t * obj, uint32_t start, uint32_t end)
|
||||
void lv_arc_set_bg_angles(lv_obj_t * obj, lv_value_precise_t start, lv_value_precise_t end)
|
||||
{
|
||||
lv_arc_set_bg_end_angle(obj, end);
|
||||
lv_arc_set_bg_start_angle(obj, start);
|
||||
@@ -209,7 +210,7 @@ void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type)
|
||||
arc->type = type;
|
||||
arc->value = -1; /** Force set_value handling*/
|
||||
|
||||
int16_t bg_midpoint, bg_end = arc->bg_angle_end;
|
||||
lv_value_precise_t bg_midpoint, bg_end = arc->bg_angle_end;
|
||||
if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360;
|
||||
|
||||
switch(arc->type) {
|
||||
@@ -285,25 +286,25 @@ void lv_arc_set_knob_offset(lv_obj_t * obj, int32_t offset)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
uint32_t lv_arc_get_angle_start(lv_obj_t * obj)
|
||||
lv_value_precise_t lv_arc_get_angle_start(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
return ((lv_arc_t *) obj)->indic_angle_start;
|
||||
}
|
||||
|
||||
uint32_t lv_arc_get_angle_end(lv_obj_t * obj)
|
||||
lv_value_precise_t lv_arc_get_angle_end(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
return ((lv_arc_t *) obj)->indic_angle_end;
|
||||
}
|
||||
|
||||
uint32_t lv_arc_get_bg_angle_start(lv_obj_t * obj)
|
||||
lv_value_precise_t lv_arc_get_bg_angle_start(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
return ((lv_arc_t *) obj)->bg_angle_start;
|
||||
}
|
||||
|
||||
uint32_t lv_arc_get_bg_angle_end(lv_obj_t * obj)
|
||||
lv_value_precise_t lv_arc_get_bg_angle_end(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
return ((lv_arc_t *) obj)->bg_angle_end;
|
||||
@@ -365,7 +366,7 @@ void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv
|
||||
arc_r -= indic_width_half;
|
||||
arc_r += r_offset;
|
||||
|
||||
uint32_t angle = get_angle(obj);
|
||||
int32_t angle = (int32_t)get_angle(obj);
|
||||
lv_coord_t knob_x = (arc_r * lv_trigo_sin(angle + 90)) >> LV_TRIGO_SHIFT;
|
||||
lv_coord_t knob_y = (arc_r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT;
|
||||
lv_obj_align_to(obj_to_align, obj, LV_ALIGN_CENTER, knob_x, knob_y);
|
||||
@@ -390,7 +391,7 @@ void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate,
|
||||
|
||||
lv_obj_update_layout(obj);
|
||||
|
||||
uint32_t angle = get_angle(obj);
|
||||
int32_t angle = (int32_t)get_angle(obj);
|
||||
lv_coord_t pivot_x = obj_to_rotate->coords.x1 - center.x;
|
||||
lv_coord_t pivot_y = obj_to_rotate->coords.y1 - center.y;
|
||||
lv_obj_set_style_transform_pivot_x(obj_to_rotate, -pivot_x, 0);
|
||||
@@ -495,8 +496,8 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
if(p.x == 0 && p.y == 0) return;
|
||||
|
||||
/*Calculate the angle of the pressed point*/
|
||||
int16_t angle;
|
||||
int16_t bg_end = arc->bg_angle_end;
|
||||
lv_value_precise_t angle;
|
||||
lv_value_precise_t bg_end = arc->bg_angle_end;
|
||||
if(arc->bg_angle_end < arc->bg_angle_start) {
|
||||
bg_end = arc->bg_angle_end + 360;
|
||||
}
|
||||
@@ -509,17 +510,17 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
if(angle < 0) angle += 360;
|
||||
|
||||
const uint32_t circumference = (uint32_t)((2U * r * 314U) / 100U); /* Equivalent to: 2r * 3.14, avoiding floats */
|
||||
const uint32_t tolerance_deg = (360U * lv_dpx(50U)) / circumference;
|
||||
const lv_value_precise_t tolerance_deg = (360 * lv_dpx(50U)) / circumference;
|
||||
const uint32_t min_close_prev = (uint32_t) arc->min_close;
|
||||
|
||||
const bool is_angle_within_bg_bounds = lv_arc_angle_within_bg_bounds(obj, (uint32_t) angle, tolerance_deg);
|
||||
const bool is_angle_within_bg_bounds = lv_arc_angle_within_bg_bounds(obj, angle, tolerance_deg);
|
||||
if(!is_angle_within_bg_bounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
int16_t deg_range = bg_end - arc->bg_angle_start;
|
||||
int16_t last_angle_rel = arc->last_angle - arc->bg_angle_start;
|
||||
int16_t delta_angle = angle - last_angle_rel;
|
||||
lv_value_precise_t deg_range = bg_end - arc->bg_angle_start;
|
||||
lv_value_precise_t last_angle_rel = arc->last_angle - arc->bg_angle_start;
|
||||
lv_value_precise_t delta_angle = angle - last_angle_rel;
|
||||
|
||||
/*Do not allow big jumps (jumps bigger than 280°).
|
||||
*It's mainly to avoid jumping to the opposite end if the "dead" range between min. and max. is crossed.
|
||||
@@ -552,7 +553,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
|
||||
uint32_t delta_tick = lv_tick_elaps(arc->last_tick);
|
||||
/* delta_angle_max can never be signed. delta_tick is always signed, same for ch_rate */
|
||||
const uint16_t delta_angle_max = (arc->chg_rate * delta_tick) / 1000;
|
||||
const lv_value_precise_t delta_angle_max = (arc->chg_rate * delta_tick) / 1000;
|
||||
|
||||
if(delta_angle > delta_angle_max) {
|
||||
delta_angle = delta_angle_max;
|
||||
@@ -565,15 +566,16 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
angle = last_angle_rel + delta_angle; /*Apply the limited angle change*/
|
||||
|
||||
/*Rounding for symmetry*/
|
||||
int32_t round = ((bg_end - arc->bg_angle_start) * 8) / (arc->max_value - arc->min_value);
|
||||
round = (round + 4) >> 4;
|
||||
lv_value_precise_t round = ((bg_end - arc->bg_angle_start) * 8) / (arc->max_value - arc->min_value);
|
||||
round = (round + 4) / 16;
|
||||
angle += round;
|
||||
|
||||
angle += arc->bg_angle_start; /*Make the angle absolute again*/
|
||||
|
||||
/*Set the new value*/
|
||||
int16_t old_value = arc->value;
|
||||
int16_t new_value = lv_map(angle, arc->bg_angle_start, bg_end, arc->min_value, arc->max_value);
|
||||
int32_t old_value = arc->value;
|
||||
int32_t new_value = lv_map((int32_t)angle, (int32_t)arc->bg_angle_start, (int32_t)bg_end, arc->min_value,
|
||||
arc->max_value);
|
||||
if(arc->type == LV_ARC_MODE_REVERSE) {
|
||||
new_value = arc->max_value - new_value + arc->min_value;
|
||||
}
|
||||
@@ -720,7 +722,7 @@ static void lv_arc_draw(lv_event_t * e)
|
||||
lv_draw_rect(layer, &knob_rect_dsc, &knob_area);
|
||||
}
|
||||
|
||||
static void inv_arc_area(lv_obj_t * obj, uint32_t start_angle, uint32_t end_angle, lv_part_t part)
|
||||
static void inv_arc_area(lv_obj_t * obj, lv_value_precise_t start_angle, lv_value_precise_t end_angle, lv_part_t part)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
@@ -787,10 +789,10 @@ static void get_center(const lv_obj_t * obj, lv_point_t * center, lv_coord_t * a
|
||||
if(arc_r) *arc_r = r;
|
||||
}
|
||||
|
||||
static lv_coord_t get_angle(const lv_obj_t * obj)
|
||||
static lv_value_precise_t get_angle(const lv_obj_t * obj)
|
||||
{
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
uint32_t angle = arc->rotation;
|
||||
lv_value_precise_t angle = arc->rotation;
|
||||
if(arc->type == LV_ARC_MODE_NORMAL) {
|
||||
angle += arc->indic_angle_end;
|
||||
}
|
||||
@@ -798,13 +800,13 @@ static lv_coord_t get_angle(const lv_obj_t * obj)
|
||||
angle += arc->indic_angle_start;
|
||||
}
|
||||
else if(arc->type == LV_ARC_MODE_SYMMETRICAL) {
|
||||
int16_t bg_end = arc->bg_angle_end;
|
||||
lv_value_precise_t bg_end = arc->bg_angle_end;
|
||||
if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360;
|
||||
int16_t indic_end = arc->indic_angle_end;
|
||||
lv_value_precise_t indic_end = arc->indic_angle_end;
|
||||
if(arc->indic_angle_end < arc->indic_angle_start) indic_end = arc->indic_angle_end + 360;
|
||||
|
||||
int32_t angle_midpoint = (int32_t)(arc->bg_angle_start + bg_end) / 2;
|
||||
if((int32_t)arc->indic_angle_start < angle_midpoint) angle += arc->indic_angle_start;
|
||||
lv_value_precise_t angle_midpoint = (int32_t)(arc->bg_angle_start + bg_end) / 2;
|
||||
if(arc->indic_angle_start < angle_midpoint) angle += arc->indic_angle_start;
|
||||
else if(indic_end > angle_midpoint) angle += arc->indic_angle_end;
|
||||
else angle += angle_midpoint;
|
||||
}
|
||||
@@ -819,7 +821,7 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t
|
||||
lv_coord_t indic_width_half = indic_width / 2;
|
||||
r -= indic_width_half;
|
||||
|
||||
lv_coord_t angle = get_angle(obj);
|
||||
int32_t angle = (int32_t)get_angle(obj);
|
||||
lv_coord_t knob_offset = lv_arc_get_knob_offset(obj);
|
||||
lv_coord_t knob_x = (r * lv_trigo_sin(knob_offset + angle + 90)) >> LV_TRIGO_SHIFT;
|
||||
lv_coord_t knob_y = (r * lv_trigo_sin(knob_offset + angle)) >> LV_TRIGO_SHIFT;
|
||||
@@ -847,32 +849,33 @@ static void value_update(lv_obj_t * obj)
|
||||
/*If the value is still not set to any value do not update*/
|
||||
if(arc->value == VALUE_UNSET) return;
|
||||
|
||||
int16_t bg_midpoint, range_midpoint, bg_end = arc->bg_angle_end;
|
||||
lv_value_precise_t bg_midpoint, bg_end = arc->bg_angle_end;
|
||||
int32_t range_midpoint;
|
||||
if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360;
|
||||
|
||||
int16_t angle;
|
||||
int32_t angle;
|
||||
switch(arc->type) {
|
||||
case LV_ARC_MODE_SYMMETRICAL:
|
||||
bg_midpoint = (arc->bg_angle_start + bg_end) / 2;
|
||||
range_midpoint = (int32_t)(arc->min_value + arc->max_value) / 2;
|
||||
|
||||
if(arc->value < range_midpoint) {
|
||||
angle = lv_map(arc->value, arc->min_value, range_midpoint, arc->bg_angle_start, bg_midpoint);
|
||||
angle = lv_map(arc->value, arc->min_value, range_midpoint, (int32_t)arc->bg_angle_start, (int32_t)bg_midpoint);
|
||||
lv_arc_set_start_angle(obj, angle);
|
||||
lv_arc_set_end_angle(obj, bg_midpoint);
|
||||
}
|
||||
else {
|
||||
angle = lv_map(arc->value, range_midpoint, arc->max_value, bg_midpoint, bg_end);
|
||||
angle = lv_map(arc->value, range_midpoint, arc->max_value, (int32_t)bg_midpoint, (int32_t)bg_end);
|
||||
lv_arc_set_start_angle(obj, bg_midpoint);
|
||||
lv_arc_set_end_angle(obj, angle);
|
||||
}
|
||||
break;
|
||||
case LV_ARC_MODE_REVERSE:
|
||||
angle = lv_map(arc->value, arc->min_value, arc->max_value, bg_end, arc->bg_angle_start);
|
||||
angle = lv_map(arc->value, arc->min_value, arc->max_value, (int32_t)bg_end, (int32_t)arc->bg_angle_start);
|
||||
lv_arc_set_angles(obj, angle, arc->bg_angle_end);
|
||||
break;
|
||||
case LV_ARC_MODE_NORMAL:
|
||||
angle = lv_map(arc->value, arc->min_value, arc->max_value, arc->bg_angle_start, bg_end);
|
||||
angle = lv_map(arc->value, arc->min_value, arc->max_value, (int32_t)arc->bg_angle_start, (int32_t)bg_end);
|
||||
lv_arc_set_angles(obj, arc->bg_angle_start, angle);
|
||||
|
||||
break;
|
||||
@@ -920,13 +923,14 @@ static lv_coord_t knob_get_extra_size(lv_obj_t * obj)
|
||||
*
|
||||
* @return true if angle is within arc background bounds, false otherwise
|
||||
*/
|
||||
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle, const uint32_t tolerance_deg)
|
||||
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const lv_value_precise_t angle,
|
||||
const lv_value_precise_t tolerance_deg)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
uint32_t smaller_angle = 0;
|
||||
uint32_t bigger_angle = 0;
|
||||
lv_value_precise_t smaller_angle = 0;
|
||||
lv_value_precise_t bigger_angle = 0;
|
||||
|
||||
/* Determine which background angle is smaller and bigger */
|
||||
if(arc->bg_angle_start < arc->bg_angle_end) {
|
||||
@@ -934,14 +938,14 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle,
|
||||
smaller_angle = arc->bg_angle_start;
|
||||
}
|
||||
else {
|
||||
bigger_angle = 360U - arc->bg_angle_end;
|
||||
smaller_angle = arc->bg_angle_start;
|
||||
bigger_angle = (360 - arc->bg_angle_start) + arc->bg_angle_end;
|
||||
smaller_angle = 0;
|
||||
}
|
||||
|
||||
/* Angle is between both background angles */
|
||||
if((smaller_angle <= angle) && (angle <= bigger_angle)) {
|
||||
|
||||
if(((bigger_angle - smaller_angle) / 2U) >= angle) {
|
||||
if(((bigger_angle - smaller_angle) / 2) >= angle) {
|
||||
arc->min_close = 1;
|
||||
}
|
||||
else {
|
||||
@@ -954,8 +958,8 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle,
|
||||
}
|
||||
/* Distance between background start and end angles is less than tolerance,
|
||||
* consider the click inside the arc */
|
||||
else if(((smaller_angle - tolerance_deg) <= 0U) &&
|
||||
(360U - (bigger_angle + (smaller_angle - tolerance_deg)))) {
|
||||
else if(((smaller_angle - tolerance_deg) <= 0) &&
|
||||
(360 - (bigger_angle + (smaller_angle - tolerance_deg)))) {
|
||||
|
||||
arc->min_close = 1;
|
||||
arc->in_out = CLICK_INSIDE_BG_ANGLES;
|
||||
@@ -974,7 +978,7 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle,
|
||||
* Start angle is bigger or equal to tolerance */
|
||||
if((smaller_angle >= tolerance_deg)
|
||||
/* (360° - T) --- A --- 360° */
|
||||
&& ((angle >= (360U - tolerance_deg)) && (angle <= 360U))) {
|
||||
&& ((angle >= (360 - tolerance_deg)) && (angle <= 360))) {
|
||||
|
||||
arc->min_close = 1;
|
||||
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
|
||||
@@ -983,14 +987,14 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle,
|
||||
/* Tolerance is bigger than bg start angle */
|
||||
else if((smaller_angle < tolerance_deg)
|
||||
/* (360° - (T - S)) --- A --- 360° */
|
||||
&& (((360U - (tolerance_deg - smaller_angle)) <= angle)) && (angle <= 360U)) {
|
||||
&& (((360 - (tolerance_deg - smaller_angle)) <= angle)) && (angle <= 360)) {
|
||||
|
||||
arc->min_close = 1;
|
||||
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
|
||||
return true;
|
||||
}
|
||||
/* 360° is bigger than background end angle + tolerance */
|
||||
else if((360U >= (bigger_angle + tolerance_deg))
|
||||
else if((360 >= (bigger_angle + tolerance_deg))
|
||||
/* E --- A --- (E + T) */
|
||||
&& ((bigger_angle <= (angle + smaller_angle)) &&
|
||||
((angle + smaller_angle) <= (bigger_angle + tolerance_deg)))) {
|
||||
@@ -1001,8 +1005,8 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle,
|
||||
}
|
||||
/* Background end angle + tolerance is bigger than 360° and bg_start_angle + tolerance is not near 0° + ((bg_end_angle + tolerance) - 360°)
|
||||
* Here we can assume background is not near 0° because of the first two initial checks */
|
||||
else if((360U < (bigger_angle + tolerance_deg))
|
||||
&& (angle <= 0U + ((bigger_angle + tolerance_deg) - 360U)) && (angle > bigger_angle)) {
|
||||
else if((360 < (bigger_angle + tolerance_deg))
|
||||
&& (angle <= 0 + ((bigger_angle + tolerance_deg) - 360)) && (angle > bigger_angle)) {
|
||||
|
||||
arc->min_close = 0;
|
||||
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
|
||||
|
||||
@@ -42,20 +42,20 @@ typedef uint8_t lv_arc_mode_t;
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
uint32_t rotation;
|
||||
uint32_t indic_angle_start;
|
||||
uint32_t indic_angle_end;
|
||||
uint32_t bg_angle_start;
|
||||
uint32_t bg_angle_end;
|
||||
int16_t value; /*Current value of the arc*/
|
||||
int16_t min_value; /*Minimum value of the arc*/
|
||||
int16_t max_value; /*Maximum value of the arc*/
|
||||
lv_value_precise_t indic_angle_start;
|
||||
lv_value_precise_t indic_angle_end;
|
||||
lv_value_precise_t bg_angle_start;
|
||||
lv_value_precise_t bg_angle_end;
|
||||
int32_t value; /*Current value of the arc*/
|
||||
int32_t min_value; /*Minimum value of the arc*/
|
||||
int32_t max_value; /*Maximum value of the arc*/
|
||||
uint32_t dragging : 1;
|
||||
uint32_t type : 2;
|
||||
uint32_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
|
||||
uint32_t in_out : 1; /* 1: The click was within the background arc angles. 0: Click outside */
|
||||
uint32_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
||||
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
||||
int16_t last_angle; /*Last dragging angle of the arc*/
|
||||
lv_value_precise_t last_angle; /*Last dragging angle of the arc*/
|
||||
int16_t knob_offset; /*knob offset from the main arc*/
|
||||
} lv_arc_t;
|
||||
|
||||
@@ -85,14 +85,14 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent);
|
||||
* @param obj pointer to an arc object
|
||||
* @param start the start angle
|
||||
*/
|
||||
void lv_arc_set_start_angle(lv_obj_t * obj, uint32_t start);
|
||||
void lv_arc_set_start_angle(lv_obj_t * obj, lv_value_precise_t start);
|
||||
|
||||
/**
|
||||
* Set the end angle of an arc. 0 deg: right, 90 bottom, etc.
|
||||
* @param obj pointer to an arc object
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_end_angle(lv_obj_t * obj, uint32_t end);
|
||||
void lv_arc_set_end_angle(lv_obj_t * obj, lv_value_precise_t end);
|
||||
|
||||
/**
|
||||
* Set the start and end angles
|
||||
@@ -100,21 +100,21 @@ void lv_arc_set_end_angle(lv_obj_t * obj, uint32_t end);
|
||||
* @param start the start angle
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_angles(lv_obj_t * obj, uint32_t start, uint32_t end);
|
||||
void lv_arc_set_angles(lv_obj_t * obj, lv_value_precise_t start, lv_value_precise_t end);
|
||||
|
||||
/**
|
||||
* Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
|
||||
* @param obj pointer to an arc object
|
||||
* @param start the start angle
|
||||
*/
|
||||
void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint32_t start);
|
||||
void lv_arc_set_bg_start_angle(lv_obj_t * obj, lv_value_precise_t start);
|
||||
|
||||
/**
|
||||
* Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
|
||||
* @param obj pointer to an arc object
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint32_t end);
|
||||
void lv_arc_set_bg_end_angle(lv_obj_t * obj, lv_value_precise_t end);
|
||||
|
||||
/**
|
||||
* Set the start and end angles of the arc background
|
||||
@@ -122,7 +122,7 @@ void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint32_t end);
|
||||
* @param start the start angle
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_bg_angles(lv_obj_t * obj, uint32_t start, uint32_t end);
|
||||
void lv_arc_set_bg_angles(lv_obj_t * obj, lv_value_precise_t start, lv_value_precise_t end);
|
||||
|
||||
/**
|
||||
* Set the rotation for the whole arc
|
||||
@@ -176,28 +176,28 @@ void lv_arc_set_knob_offset(lv_obj_t * arc, int32_t offset);
|
||||
* @param obj pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint32_t lv_arc_get_angle_start(lv_obj_t * obj);
|
||||
lv_value_precise_t lv_arc_get_angle_start(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc.
|
||||
* @param obj pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint32_t lv_arc_get_angle_end(lv_obj_t * obj);
|
||||
lv_value_precise_t lv_arc_get_angle_end(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the start angle of an arc background.
|
||||
* @param obj pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint32_t lv_arc_get_bg_angle_start(lv_obj_t * obj);
|
||||
lv_value_precise_t lv_arc_get_bg_angle_start(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc background.
|
||||
* @param obj pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint32_t lv_arc_get_bg_angle_end(lv_obj_t * obj);
|
||||
lv_value_precise_t lv_arc_get_bg_angle_end(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the value of an arc
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -98,6 +98,10 @@ typedef void * lv_user_data_t;
|
||||
#define LV_DPI_DEF 130
|
||||
#endif
|
||||
|
||||
#if defined(LVGL_CI_USING_SYS_HEAP)
|
||||
#undef LV_USE_FLOAT
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define LV_USE_ASSERT_OBJ 1
|
||||
#define LV_USE_ASSERT_STYLE 1
|
||||
#define LV_USE_LARGE_COORD 1
|
||||
#define LV_USE_FLOAT 1
|
||||
|
||||
#define LV_FONT_MONTSERRAT_8 1
|
||||
#define LV_FONT_MONTSERRAT_10 1
|
||||
|
||||
@@ -178,26 +178,26 @@ void test_arc_click_sustained_from_start_to_end_does_not_set_value_to_max(void)
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_move_to(376, 285);
|
||||
lv_test_mouse_press();
|
||||
lv_test_indev_wait(50);
|
||||
lv_test_indev_wait(500);
|
||||
lv_test_mouse_release();
|
||||
lv_test_indev_wait(50);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(1, event_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(lv_arc_get_value(arc), lv_arc_get_min_value(arc));
|
||||
TEST_ASSERT_EQUAL_INT32(lv_arc_get_min_value(arc), lv_arc_get_value(arc));
|
||||
|
||||
/* Click close to end angle */
|
||||
event_cnt = 0;
|
||||
|
||||
lv_test_mouse_move_to(376, 285);
|
||||
lv_test_mouse_press();
|
||||
lv_test_indev_wait(50);
|
||||
lv_test_indev_wait(500);
|
||||
lv_test_mouse_move_to(415, 281);
|
||||
lv_test_indev_wait(50);
|
||||
lv_test_indev_wait(500);
|
||||
lv_test_mouse_release();
|
||||
lv_test_indev_wait(50);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(1, event_cnt);
|
||||
TEST_ASSERT_NOT_EQUAL_UINT32(lv_arc_get_value(arc), lv_arc_get_max_value(arc));
|
||||
TEST_ASSERT_EQUAL_INT32(lv_arc_get_min_value(arc), lv_arc_get_value(arc));
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("arc_2.png");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user