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

feat(buttons): Allow calling buttons.read() without args


Allow calling buttons.read() without an argument.  This is equivalent to
a mask with all bits set (that is, buttons.read(255)).  Additionally,
add a check that the mask is within the limits (< 256).

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent f8a8f0d7
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,24 @@
#include "epicardium.h"
static mp_obj_t mp_buttons_read(mp_obj_t mask_in)
static mp_obj_t mp_buttons_read(size_t n_args, const mp_obj_t *args)
{
uint8_t mask = mp_obj_get_int(mask_in);
uint8_t mask;
if (n_args == 1) {
mp_int_t mask_int = mp_obj_get_int(args[0]);
if (mask_int > 255) {
mp_raise_ValueError("mask must be less than 256");
}
mask = (uint8_t)mask_int;
} else {
mask = 0xff;
}
uint8_t button_states = epic_buttons_read(mask);
return MP_OBJ_NEW_SMALL_INT(button_states);
}
static MP_DEFINE_CONST_FUN_OBJ_1(buttons_read_obj, mp_buttons_read);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
buttons_read_obj, 0, 1, mp_buttons_read
);
static const mp_rom_map_elem_t buttons_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buttons) },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment