diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 96684ae332961f50bbee63fb6eef4231e6217599..406df58fcec5883faf010b74896d982a4b8a53a5 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -610,8 +610,7 @@ API(API_LEDS_UPDATE, void epic_leds_update(void)); * +-------+--------+----------+ * | ``2`` | Green | Right | * +-------+--------+----------+ - * :param uint8_t value: Brightness of LED (only two brightness levels are - * supported right now). + * :param uint8_t value: Brightness of LED (value between 0 and 31). */ API(API_LEDS_SET_ROCKET, void epic_leds_set_rocket(int led, uint8_t value)); diff --git a/epicardium/modules/leds.c b/epicardium/modules/leds.c index 0fa35c1616e5c40791a2e630847b62448c86b1dc..0faca35e33fc51b755c6b5e6a920ecfa23697dfc 100644 --- a/epicardium/modules/leds.c +++ b/epicardium/modules/leds.c @@ -63,6 +63,7 @@ void epic_leds_dim_bottom(uint8_t value) void epic_leds_set_rocket(int led, uint8_t value) { + value = value > 31 ? 31 : value; pmic_set_led(led, value); } diff --git a/pycardium/modules/py/leds.py b/pycardium/modules/py/leds.py index 2c9fd275d9d7b2f969018f2362451c4f1ba9a05a..0cbf2c3fe3351088e6c89d16fbf01730c5718d49 100644 --- a/pycardium/modules/py/leds.py +++ b/pycardium/modules/py/leds.py @@ -61,8 +61,7 @@ def set_rocket(led, value): +-------+--------+----------+ | ``2`` | Green | Right | +-------+--------+----------+ - :param int value: Brightness of LED (only two brightness levels are - supported right now). + :param int value: Brightness of LED (value between 0 and 31). """ sys_leds.set_rocket(led, value) @@ -71,7 +70,7 @@ def dim_top(value): """ Set global brightness for top RGB LEDs. - :param int value: Brightness. Default = 1, range = 1...8 + :param int value: Brightness. Default = 1, Range = 1..8 """ sys_leds.dim_top(value) @@ -80,7 +79,7 @@ def dim_bottom(value): """ Set global brightness for bottom RGB LEDs. - :param int value: Brightness. Default = 8, range = 1...8 + :param int value: Brightness. Default = 8, Range = 1..8 """ sys_leds.dim_bottom(value) diff --git a/pycardium/modules/sys_leds.c b/pycardium/modules/sys_leds.c index 55c99ba38d964463b62b33390834022db52c0c58..7c1c2d5a35156ae06c31c424546bf1623d69d311 100644 --- a/pycardium/modules/sys_leds.c +++ b/pycardium/modules/sys_leds.c @@ -1,9 +1,11 @@ +#include "epicardium.h" + #include "py/obj.h" #include "py/objlist.h" #include "py/runtime.h" + #include <stdio.h> -#include "epicardium.h" static mp_obj_t mp_leds_set(mp_obj_t led_in, mp_obj_t color_in) { @@ -162,6 +164,11 @@ static mp_obj_t mp_leds_set_rocket(mp_obj_t led_in, mp_obj_t value_in) { int led = mp_obj_get_int(led_in); int value = mp_obj_get_int(value_in); + + if (value > 31) { + mp_raise_ValueError("brightness must by < 32"); + } + epic_leds_set_rocket(led, value); return mp_const_none; } @@ -170,6 +177,11 @@ static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket); static mp_obj_t mp_leds_dim_top(mp_obj_t dim_in) { int dim = mp_obj_get_int(dim_in); + + if (dim > 8) { + mp_raise_ValueError("maximum allowed dim is 8"); + } + epic_leds_dim_top(dim); return mp_const_none; } @@ -178,6 +190,11 @@ static MP_DEFINE_CONST_FUN_OBJ_1(leds_dim_top_obj, mp_leds_dim_top); static mp_obj_t mp_leds_dim_bottom(mp_obj_t dim_in) { int dim = mp_obj_get_int(dim_in); + + if (dim > 8) { + mp_raise_ValueError("maximum allowed dim is 8"); + } + epic_leds_dim_bottom(dim); return mp_const_none; }