diff --git a/porting/lv_port_indev_template.c b/porting/lv_port_indev_template.c index 54b8c9fda..bf4a6436f 100644 --- a/porting/lv_port_indev_template.c +++ b/porting/lv_port_indev_template.c @@ -140,14 +140,14 @@ void lv_port_indev_init(void) /*Register a encoder input device*/ lv_indev_drv_init(&indev_drv); - indev_drv.type = LV_INDEV_TYPE_KEYPAD; + indev_drv.type = LV_INDEV_TYPE_ENCODER; indev_drv.read_cb = encoder_read; indev_encoder = lv_indev_drv_register(&indev_drv); /* Later you should create group(s) with `lv_group_t * group = lv_group_create()`, * add objects to the group with `lv_group_add_obj(group, obj)` * and assign this input device to group to navigate in it: - * `lv_indev_set_group(indev_keypad, group);` */ + * `lv_indev_set_group(indev_encoder, group);` */ /*------------------ * Button diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 2f5db6ad4..035100aaf 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -735,6 +735,12 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) */ static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data) { + /* Die gracefully if i->btn_points is NULL */ + if (i->btn_points == NULL) { + LV_LOG_WARN("indev_button_proc: btn_points was NULL"); + return; + } + i->proc.types.pointer.act_point.x = i->btn_points[data->btn_id].x; i->proc.types.pointer.act_point.y = i->btn_points[data->btn_id].y; diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 2992525f8..1474fe4a9 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -385,7 +385,7 @@ static void lv_refr_area(const lv_area_t * area_p) lv_coord_t w = lv_area_get_width(area_p); lv_coord_t h = lv_area_get_height(area_p); lv_coord_t y2 = - area_p->y2 >= lv_disp_get_ver_res(disp_refr) ? y2 = lv_disp_get_ver_res(disp_refr) - 1 : area_p->y2; + area_p->y2 >= lv_disp_get_ver_res(disp_refr) ? lv_disp_get_ver_res(disp_refr) - 1 : area_p->y2; int32_t max_row = (uint32_t)vdb->size / w; diff --git a/src/lv_misc/lv_math.c b/src/lv_misc/lv_math.c index ca0459a82..ecc75e29b 100644 --- a/src/lv_misc/lv_math.c +++ b/src/lv_misc/lv_math.c @@ -213,6 +213,26 @@ uint16_t lv_atan2(int x, int y) return degree; } +/** + * Calculate the integer exponents. + * @param base + * @param power + * @return base raised to the power exponent + */ +int64_t lv_pow(int64_t base, int8_t exp) +{ + int64_t result = 1; + while (exp) + { + if (exp & 1) + result *= base; + exp >>= 1; + base *= base; + } + + return result; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/lv_misc/lv_math.h b/src/lv_misc/lv_math.h index 0bc5a74e1..2acfba64c 100644 --- a/src/lv_misc/lv_math.h +++ b/src/lv_misc/lv_math.h @@ -96,6 +96,14 @@ uint16_t lv_atan2(int x, int y); */ LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask); +/** + * Calculate the integer exponents. + * @param base + * @param power + * @return base raised to the power exponent + */ +int64_t lv_pow(int64_t base, int8_t exp); + /********************** * MACROS **********************/ diff --git a/src/lv_widgets/lv_spinbox.c b/src/lv_widgets/lv_spinbox.c index 303fe52c9..a08151ebb 100644 --- a/src/lv_widgets/lv_spinbox.c +++ b/src/lv_widgets/lv_spinbox.c @@ -173,6 +173,13 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_ if(separator_position >= digit_count) separator_position = 0; if(separator_position > LV_SPINBOX_MAX_DIGIT_COUNT) separator_position = LV_SPINBOX_MAX_DIGIT_COUNT; + if(digit_count < LV_SPINBOX_MAX_DIGIT_COUNT) + { + uint64_t max_val = lv_pow(10, digit_count); + if(ext->range_max > max_val - 1) ext->range_max = max_val - 1; + if(ext->range_min < - max_val + 1) ext->range_min = - max_val + 1; + } + ext->digit_count = digit_count; ext->dec_point_pos = separator_position; diff --git a/src/lv_widgets/lv_spinbox.h b/src/lv_widgets/lv_spinbox.h index 1f0293294..83c057f58 100644 --- a/src/lv_widgets/lv_spinbox.h +++ b/src/lv_widgets/lv_spinbox.h @@ -28,7 +28,7 @@ extern "C" { /********************* * DEFINES *********************/ -#define LV_SPINBOX_MAX_DIGIT_COUNT 16 +#define LV_SPINBOX_MAX_DIGIT_COUNT 10 /********************** * TYPEDEFS