Skip to content
Snippets Groups Projects
Verified Commit b545c16d authored by rahix's avatar rahix
Browse files

fix(leds): Catch out-of-bounds errors


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent b5a3f1b2
Branches
Tags
No related merge requests found
...@@ -610,8 +610,7 @@ API(API_LEDS_UPDATE, void epic_leds_update(void)); ...@@ -610,8 +610,7 @@ API(API_LEDS_UPDATE, void epic_leds_update(void));
* +-------+--------+----------+ * +-------+--------+----------+
* | ``2`` | Green | Right | * | ``2`` | Green | Right |
* +-------+--------+----------+ * +-------+--------+----------+
* :param uint8_t value: Brightness of LED (only two brightness levels are * :param uint8_t value: Brightness of LED (value between 0 and 31).
* supported right now).
*/ */
API(API_LEDS_SET_ROCKET, void epic_leds_set_rocket(int led, uint8_t value)); API(API_LEDS_SET_ROCKET, void epic_leds_set_rocket(int led, uint8_t value));
......
...@@ -63,6 +63,7 @@ void epic_leds_dim_bottom(uint8_t value) ...@@ -63,6 +63,7 @@ void epic_leds_dim_bottom(uint8_t value)
void epic_leds_set_rocket(int led, uint8_t value) void epic_leds_set_rocket(int led, uint8_t value)
{ {
value = value > 31 ? 31 : value;
pmic_set_led(led, value); pmic_set_led(led, value);
} }
......
...@@ -61,8 +61,7 @@ def set_rocket(led, value): ...@@ -61,8 +61,7 @@ def set_rocket(led, value):
+-------+--------+----------+ +-------+--------+----------+
| ``2`` | Green | Right | | ``2`` | Green | Right |
+-------+--------+----------+ +-------+--------+----------+
:param int value: Brightness of LED (only two brightness levels are :param int value: Brightness of LED (value between 0 and 31).
supported right now).
""" """
sys_leds.set_rocket(led, value) sys_leds.set_rocket(led, value)
...@@ -71,7 +70,7 @@ def dim_top(value): ...@@ -71,7 +70,7 @@ def dim_top(value):
""" """
Set global brightness for top RGB LEDs. 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) sys_leds.dim_top(value)
...@@ -80,7 +79,7 @@ def dim_bottom(value): ...@@ -80,7 +79,7 @@ def dim_bottom(value):
""" """
Set global brightness for bottom RGB LEDs. 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) sys_leds.dim_bottom(value)
......
#include "epicardium.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/objlist.h" #include "py/objlist.h"
#include "py/runtime.h" #include "py/runtime.h"
#include <stdio.h> #include <stdio.h>
#include "epicardium.h"
static mp_obj_t mp_leds_set(mp_obj_t led_in, mp_obj_t color_in) 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) ...@@ -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 led = mp_obj_get_int(led_in);
int value = mp_obj_get_int(value_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); epic_leds_set_rocket(led, value);
return mp_const_none; return mp_const_none;
} }
...@@ -170,6 +177,11 @@ static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket); ...@@ -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) static mp_obj_t mp_leds_dim_top(mp_obj_t dim_in)
{ {
int dim = mp_obj_get_int(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); epic_leds_dim_top(dim);
return mp_const_none; return mp_const_none;
} }
...@@ -178,6 +190,11 @@ static MP_DEFINE_CONST_FUN_OBJ_1(leds_dim_top_obj, mp_leds_dim_top); ...@@ -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) static mp_obj_t mp_leds_dim_bottom(mp_obj_t dim_in)
{ {
int dim = mp_obj_get_int(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); epic_leds_dim_bottom(dim);
return mp_const_none; return mp_const_none;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment