From 3452e60ec1a86660f866608a577fa98c79ff8279 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 15 Nov 2019 08:03:11 -0500 Subject: [PATCH 1/2] Silence -Wconversion --- src/lv_misc/lv_color.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lv_misc/lv_color.h b/src/lv_misc/lv_color.h index 54b62aa2b..c94341de0 100644 --- a/src/lv_misc/lv_color.h +++ b/src/lv_misc/lv_color.h @@ -114,10 +114,10 @@ enum { # define LV_COLOR_GET_B8(c) (c).ch.blue # define LV_COLOR_GET_A8(c) 0xFF -# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint16_t)((v) & 0x1F); -# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint16_t)((v) & 0x3F); -# define LV_COLOR_SET_G16_SWAP(c, v) {(c).ch.green_h = (uint16_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint16_t)((v) & 0x7);} -# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint16_t)((v) & 0x1F); +# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)((v) & 0x1F); +# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3F); +# define LV_COLOR_SET_G16_SWAP(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);} +# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1F); # define LV_COLOR_SET_A16(c, v) do {} while(0) # define LV_COLOR_GET_R16(c) (c).ch.red From 59743f7f90d2b62c664d4d5bdd58a4fe272090b4 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 16 Nov 2019 11:27:35 +0100 Subject: [PATCH 2/2] linemeter: angle offset fixes rename lv_lmeter_set_angle to lv_lmeter_set_angle_offset add lv_lemeter_get_angle_offset initialze ext->angle_ofs in lv_lmeter_create --- src/lv_objx/lv_lmeter.c | 24 ++++++++++++++++++------ src/lv_objx/lv_lmeter.h | 15 +++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/lv_objx/lv_lmeter.c b/src/lv_objx/lv_lmeter.c index 76ae1cd66..5843a7d34 100644 --- a/src/lv_objx/lv_lmeter.c +++ b/src/lv_objx/lv_lmeter.c @@ -76,6 +76,7 @@ lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy) ext->cur_value = 0; ext->line_cnt = 21; /*Odd scale number looks better*/ ext->scale_angle = 240; /*(scale_num - 1) * N looks better */ + ext->angle_ofs = 0; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_lmeter, lv_lmeter_signal); @@ -178,16 +179,16 @@ void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt) } /** - * Set the angle settings of a line meter + * Set the set an offset for the line meter's angles to rotate it. * @param lmeter pointer to a line meter object * @param angle angle where the meter will be facing (with its center) */ -void lv_lmeter_set_angle(lv_obj_t * lmeter, uint16_t angle) +void lv_lmeter_set_angle_offset(lv_obj_t * lmeter, uint16_t angle) { lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); - if(ext->angle == angle) return; + if(ext->angle_ofs == angle) return; - ext->angle = angle; + ext->angle_ofs = angle; lv_obj_invalidate(lmeter); } @@ -251,7 +252,7 @@ uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter) /** * Get the scale angle of a line meter * @param lmeter pointer to a line meter object - * @return angle of the scale + * @return angle_ofs of the scale */ uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter) { @@ -261,6 +262,17 @@ uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter) return ext->scale_angle; } +/** + * get the set an offset for the line meter. + * @param lmeter pointer to a line meter object + * @return angle offset (0..360) + */ +uint16_t lv_lmeter_get_angle_offset(lv_obj_t * lmeter) +{ + lv_lmeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); + + return ext->angle_ofs; +} /********************** * STATIC FUNCTIONS **********************/ @@ -302,7 +314,7 @@ static bool lv_lmeter_design(lv_obj_t * lmeter, const lv_area_t * mask, lv_desig lv_coord_t x_ofs = lv_obj_get_width(lmeter) / 2 + lmeter->coords.x1; lv_coord_t y_ofs = lv_obj_get_height(lmeter) / 2 + lmeter->coords.y1; - int16_t angle_ofs = ext->angle + 90 + (360 - ext->scale_angle) / 2; + int16_t angle_ofs = ext->angle_ofs + 90 + (360 - ext->scale_angle) / 2; int16_t level = (int32_t)((int32_t)(ext->cur_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value); uint8_t i; diff --git a/src/lv_objx/lv_lmeter.h b/src/lv_objx/lv_lmeter.h index 49d662819..bc098e1b8 100644 --- a/src/lv_objx/lv_lmeter.h +++ b/src/lv_objx/lv_lmeter.h @@ -36,7 +36,7 @@ typedef struct /*No inherited ext.*/ /*Ext. of ancestor*/ /*New data for this type */ uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ - uint16_t angle; + uint16_t angle_ofs; uint8_t line_cnt; /*Count of lines */ int16_t cur_value; int16_t min_value; @@ -90,11 +90,11 @@ void lv_lmeter_set_range(lv_obj_t * lmeter, int16_t min, int16_t max); void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt); /** - * Set the rotation settings of a line meter + * Set the set an offset for the line meter's angles to rotate it. * @param lmeter pointer to a line meter object - * @param angle angle of rotation (relative to the northen axis) + * @param angle angle offset (0..360), rotates clockwise */ -void lv_lmeter_set_angle(lv_obj_t * lmeter, uint16_t angle); +void lv_lmeter_set_angle_offset(lv_obj_t * lmeter, uint16_t angle); /** * Set the styles of a line meter @@ -147,6 +147,13 @@ uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter); */ uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter); +/** + * get the set an offset for the line meter. + * @param lmeter pointer to a line meter object + * @return angle offset (0..360) + */ +uint16_t lv_lmeter_get_angle_offset(lv_obj_t * lmeter); + /** * Get the style of a line meter * @param lmeter pointer to a line meter object