1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00

Move map function to proper func to avoid recalc of slope

This commit is contained in:
Adam Martini 2020-06-19 17:49:02 -07:00
parent f5d9e4bff4
commit e100565c67
3 changed files with 28 additions and 10 deletions

View File

@ -128,7 +128,6 @@ LV_ATTRIBUTE_FAST_MEM void _lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask
q->f = (uint32_t)(root & 0xf) << 4;
}
/**
* Calculate the atan2 of a vector.
* @param x
@ -232,6 +231,22 @@ int64_t _lv_pow(int64_t base, int8_t exp)
return result;
}
/**
* Get the mapped of a number given an imput and output range
* @param x integer which mapped value should be calculated
* @param min_in min input range
* @param max_in max input range
* @param in min output range
* @param out max output range
*/
LV_ATTRIBUTE_FAST_MEM int16_t _lv_map(int16_t x, int16_t min_in, int16_t max_in, int16_t min, int16_t max)
{
int16_t slope = (max - min) / (max_in - min_in);
int16_t bias = min - slope * min_in;
return bias + slope * x;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -31,8 +31,6 @@ extern "C" {
#define LV_MATH_UDIV255(x) ((uint32_t)((uint32_t) (x) * 0x8081) >> 0x17)
#define LV_MATH_MAP(a, min_in, max_in, min, max) (min - (((max - min) / (max_in - min_in)) * min_in) + (((max - min) / (max_in - min_in)) * a))
#define LV_IS_SIGNED(t) (((t)(-1)) < ((t) 0))
#define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL)))
#define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL)))
@ -114,6 +112,16 @@ LV_ATTRIBUTE_FAST_MEM void _lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask
*/
int64_t _lv_pow(int64_t base, int8_t exp);
/**
* Get the mapped of a number given an imput and output range
* @param x integer which mapped value should be calculated
* @param min_in min input range
* @param max_in max input range
* @param in min output range
* @param out max output range
*/
LV_ATTRIBUTE_FAST_MEM int16_t _lv_map(int16_t x, int16_t min_in, int16_t max_in, int16_t min, int16_t max);
/**********************
* MACROS
**********************/

View File

@ -145,13 +145,8 @@ void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim
lv_arc_set_end_angle(
rotary,
LV_MATH_MAP(
ext->cur_value,
ext->min_value,
ext->max_value,
ext->arc.arc_angle_start,
360 + ext->arc.bg_angle_end
)
_lv_map(ext->cur_value, ext->min_value, ext->max_value,
ext->arc.arc_angle_start, 360 + ext->arc.bg_angle_end)
);
}