pybricks/common/LightGrid: add char method
#include <pbdrv/pwm.h>
-#include "py/obj.h"
#include "py/mphal.h"
+#include "py/obj.h"
+#include "py/objstr.h"
#include <pybricks/common.h>
@@ -41,6 +42,21 @@ typedef struct _common_LightGrid_obj_t {
uint8_t size;
} common_LightGrid_obj_t;
+// pybricks._common.LightGrid.char
+STATIC mp_obj_t common_LightGrid_char(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ PB_PARSE_ARGS_METHOD(n_args, pos_args, kw_args,
+ common_LightGrid_obj_t, self,
+ PB_ARG_REQUIRED(character));
+
+ GET_STR_DATA_LEN(character, str, len);
+ if (len != 1 || str[0] < 32 || str[0] > 126) {
+ pb_assert(PBIO_ERROR_INVALID_ARG);
+ }
+ set_light_grid_full(self->pwm, pb_font_5x5[str[0] - 32]);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(common_LightGrid_char_obj, 1, common_LightGrid_char);
+
// pybricks._common.LightGrid.on
STATIC mp_obj_t common_LightGrid_on(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
common_LightGrid_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@@ -109,6 +125,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(common_LightGrid_number_obj, 1, common_LightGr
// dir(pybricks.builtins.LightGrid)
STATIC const mp_rom_map_elem_t common_LightGrid_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_char), MP_ROM_PTR(&common_LightGrid_char_obj) },
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&common_LightGrid_on_obj) },
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&common_LightGrid_off_obj) },
{ MP_ROM_QSTR(MP_QSTR_number), MP_ROM_PTR(&common_LightGrid_number_obj) },
