Verified Commit b545c16d authored by Rahix's avatar Rahix
Browse files

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



Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent b5a3f1b2
......@@ -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));
......
......@@ -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);
}
......
......@@ -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)
......
#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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment