diff --git a/lv_conf_template.h b/lv_conf_template.h index 94c599b9e..39c7ea033 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -522,6 +522,10 @@ typedef void * lv_obj_user_data_t; /*LED (dependencies: -)*/ #define LV_USE_LED 1 +#if LV_USE_LED +# define LV_LED_BRIGHT_MIN 60 /*Minimal brightness*/ +# define LV_LED_BRIGHT_MAX 255 /*Maximal brightness*/ +#endif /*Line (dependencies: -*/ #define LV_USE_LINE 1 diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index abd306607..59307fa08 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -766,6 +766,14 @@ #ifndef LV_USE_LED #define LV_USE_LED 1 #endif +#if LV_USE_LED +#ifndef LV_LED_BRIGHT_MIN +# define LV_LED_BRIGHT_MIN 60 /*Minimal brightness*/ +#endif +#ifndef LV_LED_BRIGHT_MAX +# define LV_LED_BRIGHT_MAX 255 /*Maximal brightness*/ +#endif +#endif /*Line (dependencies: -*/ #ifndef LV_USE_LINE diff --git a/src/lv_widgets/lv_led.c b/src/lv_widgets/lv_led.c index c98ac8743..d14b4b9f7 100644 --- a/src/lv_widgets/lv_led.c +++ b/src/lv_widgets/lv_led.c @@ -20,8 +20,6 @@ #define LV_LED_WIDTH_DEF (LV_DPI / 3) #define LV_LED_HEIGHT_DEF (LV_DPI / 3) -#define LV_LED_BRIGHT_OFF 60 -#define LV_LED_BRIGHT_ON 255 /********************** * TYPEDEFS @@ -73,7 +71,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) return NULL; } - ext->bright = LV_LED_BRIGHT_ON; + ext->bright = LV_LED_BRIGHT_MAX; lv_obj_set_signal_cb(led, lv_led_signal); lv_obj_set_design_cb(led, lv_led_design); @@ -105,7 +103,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) /** * Set the brightness of a LED object * @param led pointer to a LED object - * @param bright 0 (max. dark) ... 255 (max. light) + * @param bright LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light) */ void lv_led_set_bright(lv_obj_t * led, uint8_t bright) { @@ -115,6 +113,9 @@ void lv_led_set_bright(lv_obj_t * led, uint8_t bright) lv_led_ext_t * ext = lv_obj_get_ext_attr(led); if(ext->bright == bright) return; + if(bright < LV_LED_BRIGHT_MIN) bright = LV_LED_BRIGHT_MIN; + if(bright > LV_LED_BRIGHT_MAX) bright = LV_LED_BRIGHT_MAX; + ext->bright = bright; /*Invalidate the object there fore it will be redrawn*/ @@ -129,7 +130,7 @@ void lv_led_on(lv_obj_t * led) { LV_ASSERT_OBJ(led, LV_OBJX_NAME); - lv_led_set_bright(led, LV_LED_BRIGHT_ON); + lv_led_set_bright(led, LV_LED_BRIGHT_MAX); } /** @@ -140,7 +141,7 @@ void lv_led_off(lv_obj_t * led) { LV_ASSERT_OBJ(led, LV_OBJX_NAME); - lv_led_set_bright(led, LV_LED_BRIGHT_OFF); + lv_led_set_bright(led, LV_LED_BRIGHT_MIN); } /** @@ -152,7 +153,7 @@ void lv_led_toggle(lv_obj_t * led) LV_ASSERT_OBJ(led, LV_OBJX_NAME); uint8_t bright = lv_led_get_bright(led); - if(bright > (LV_LED_BRIGHT_OFF + LV_LED_BRIGHT_ON) >> 1) + if(bright > (LV_LED_BRIGHT_MIN + LV_LED_BRIGHT_MAX) >> 1) lv_led_off(led); else lv_led_on(led); @@ -211,8 +212,8 @@ static lv_design_res_t lv_led_design(lv_obj_t * led, const lv_area_t * clip_area /*Set the current shadow width according to brightness proportionally between LV_LED_BRIGHT_OFF * and LV_LED_BRIGHT_ON*/ - rect_dsc.shadow_width = ((ext->bright - LV_LED_BRIGHT_OFF) * rect_dsc.shadow_width) / - (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF); + rect_dsc.shadow_width = ((ext->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_width) / + (LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN); lv_draw_rect(&led->coords, clip_area, &rect_dsc); } diff --git a/src/lv_widgets/lv_led.h b/src/lv_widgets/lv_led.h index 2ef640954..7ab33cef1 100644 --- a/src/lv_widgets/lv_led.h +++ b/src/lv_widgets/lv_led.h @@ -55,7 +55,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); /** * Set the brightness of a LED object * @param led pointer to a LED object - * @param bright 0 (max. dark) ... 255 (max. light) + * @param bright LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light) */ void lv_led_set_bright(lv_obj_t * led, uint8_t bright);