remove pressed() and get_states_into()

This commit is contained in:
Dan Halbert 2021-06-23 15:10:38 -04:00
parent 7774b18895
commit 4f538b6c09
9 changed files with 8 additions and 185 deletions

View File

@ -225,50 +225,6 @@ STATIC mp_obj_t keypad_keymatrix_row_column_to_key_number(mp_obj_t self_in, mp_o
}
MP_DEFINE_CONST_FUN_OBJ_3(keypad_keymatrix_row_column_to_key_number_obj, keypad_keymatrix_row_column_to_key_number);
//| def pressed(self, key_number: int) -> None:
//| """Return ``True`` if the given key is pressed. This is a debounced read
//| of the key state which bypasses the `events` `EventQueue`.
//| """
//| ...
//|
STATIC mp_obj_t keypad_keymatrix_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_uint_t key_number = mp_arg_validate_int_range(
mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_keymatrix_get_key_count(self), MP_QSTR_key_number);
return mp_obj_new_bool(common_hal_keypad_keymatrix_pressed(self, (mp_uint_t)key_number));
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_pressed_obj, keypad_keymatrix_pressed);
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
//| """Write the state of all the keys into ``states``.
//| Write a ``1`` if pressed, and ``0`` if released.
//| The ``length`` of ``states`` must be `key_count`.
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
//| The read is done atomically.
//| """
//| ...
//|
STATIC mp_obj_t keypad_keymatrix_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_states);
}
(void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_keymatrix_get_key_count(self),
MP_QSTR_states, MP_QSTR_key_count);
common_hal_keypad_keymatrix_get_states_into(self, (uint8_t *)bufinfo.buf);
return MP_ROM_NONE;
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_get_states_into_obj, keypad_keymatrix_get_states_into);
//| events: EventQueue
//| """The `EventQueue` associated with this `Keys` object. (read-only)
//| """
@ -292,12 +248,10 @@ STATIC const mp_rom_map_elem_t keypad_keymatrix_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keymatrix___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keymatrix_events_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keymatrix_get_states_into_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keymatrix_key_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keymatrix_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_number_to_row_column), MP_ROM_PTR(&keypad_keymatrix_key_number_to_row_column_obj) },
{ MP_ROM_QSTR(MP_QSTR_row_column_to_key_number), MP_ROM_PTR(&keypad_keymatrix_row_column_to_key_number_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keymatrix_key_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keymatrix_pressed_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keymatrix_reset_obj) },
};
STATIC MP_DEFINE_CONST_DICT(keypad_keymatrix_locals_dict, keypad_keymatrix_locals_dict_table);

View File

@ -40,13 +40,11 @@ bool common_hal_keypad_keymatrix_deinited(keypad_keymatrix_obj_t *self);
void common_hal_keypad_keymatrix_key_number_to_row_column(keypad_keymatrix_obj_t *self, mp_uint_t key_number, mp_uint_t *row, mp_uint_t *column);
mp_uint_t common_hal_keypad_keymatrix_row_column_to_key_number(keypad_keymatrix_obj_t *self, mp_uint_t row, mp_uint_t column);
mp_uint_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self);
mp_uint_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self);
mp_uint_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self);
size_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self);
size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self);
size_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self);
mp_obj_t common_hal_keypad_keymatrix_get_events(keypad_keymatrix_obj_t *self);
bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number);
void common_hal_keypad_keymatrix_reset(keypad_keymatrix_obj_t *self);
void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYMATRIX_H

View File

@ -167,49 +167,6 @@ const mp_obj_property_t keypad_keys_key_count_obj = {
MP_ROM_NONE},
};
//| def pressed(self, key_number: int) -> None:
//| """Return ``True`` if the given key is pressed.
// This is a debounced read of the key state which bypasses the `events` `EventQueue`.
//| """
//| ...
//|
STATIC mp_obj_t keypad_keys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
const mp_int_t key_number = mp_obj_get_int(key_number_in);
(void)mp_arg_validate_int_range(key_number, 0, common_hal_keypad_keys_get_key_count(self), MP_QSTR_key_number);
return mp_obj_new_bool(common_hal_keypad_keys_pressed(self, (mp_uint_t)key_number));
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_pressed_obj, keypad_keys_pressed);
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
//| """Write the states of all the keys into ``states``.
//| Write a ``1`` if pressed, and ``0`` if released.
//| The ``length`` of ``states`` must be `key_count`.
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
//| The read is done atomically.
//| """
//| ...
//|
STATIC mp_obj_t keypad_keys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed);
}
(void)mp_arg_validate_length_with_name(bufinfo.len,common_hal_keypad_keys_get_key_count(self),
MP_QSTR_pressed, MP_QSTR_key_count);
common_hal_keypad_keys_get_states_into(self, (uint8_t *)bufinfo.buf);
return MP_ROM_NONE;
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_get_states_into_obj, keypad_keys_get_states_into);
//| events: EventQueue
//| """The `EventQueue` associated with this `Keys` object. (read-only)
//| """
@ -233,9 +190,7 @@ STATIC const mp_rom_map_elem_t keypad_keys_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keys___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keys_events_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keys_get_states_into_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keys_pressed_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keys_reset_obj) },
};

View File

@ -38,9 +38,7 @@ void common_hal_keypad_keys_deinit(keypad_keys_obj_t *self);
bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self);
mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self);
mp_uint_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self);
bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number);
size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self);
void common_hal_keypad_keys_reset(keypad_keys_obj_t *self);
void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYS_H

View File

@ -171,50 +171,6 @@ const mp_obj_property_t keypad_shiftregisterkeys_key_count_obj = {
MP_ROM_NONE},
};
//| def pressed(self, key_number: int) -> None:
//| """Return ``True`` if the given key is pressed.
// This is a debounced read of the key state which bypasses the `events` `EventQueue`.
//| """
//| ...
//|
STATIC mp_obj_t keypad_shiftregisterkeys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_uint_t key_number = mp_arg_validate_int_range(
mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_shiftregisterkeys_get_key_count(self),
MP_QSTR_key_number);
return mp_obj_new_bool(common_hal_keypad_shiftregisterkeys_pressed(self, key_number));
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_pressed_obj, keypad_shiftregisterkeys_pressed);
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
//| """Write the states of all the keys into ``states``.
//| Write a ``1`` if pressed, and ``0`` if released.
//| The ``length`` of ``states`` must be `key_count`.
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
//| The read is done atomically.
//| """
//| ...
//|
STATIC mp_obj_t keypad_shiftregisterkeys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed);
}
(void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_shiftregisterkeys_get_key_count(self),
MP_QSTR_states, MP_QSTR_key_count);
common_hal_keypad_shiftregisterkeys_get_states_into(self, (uint8_t *)bufinfo.buf);
return MP_ROM_NONE;
}
MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_get_states_into_obj, keypad_shiftregisterkeys_get_states_into);
//| events: EventQueue
//| """The `EventQueue` associated with this `Keys` object. (read-only)
//| """
@ -238,9 +194,7 @@ STATIC const mp_rom_map_elem_t keypad_shiftregisterkeys_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_shiftregisterkeys___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_shiftregisterkeys_events_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_shiftregisterkeys_get_states_into_obj) },
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_shiftregisterkeys_key_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_shiftregisterkeys_pressed_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_shiftregisterkeys_reset_obj) },
};

View File

@ -38,9 +38,7 @@ void common_hal_keypad_shiftregisterkeys_deinit(keypad_shiftregisterkeys_obj_t *
bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t *self);
mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self);
mp_uint_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self);
bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number);
size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self);
void common_hal_keypad_shiftregisterkeys_reset(keypad_shiftregisterkeys_obj_t *self);
void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_SHIFTREGISTERKEYS_H

View File

@ -116,18 +116,6 @@ size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self
return self->column_digitalinouts->len;
}
bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number) {
return self->currently_pressed[key_number];
}
// The length of states has already been validated.
void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states) {
// Read the state atomically.
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
memcpy(states, self->currently_pressed, common_hal_keypad_keymatrix_get_key_count(self));
supervisor_release_lock(&keypad_scanners_linked_list_lock);
}
mp_uint_t common_hal_keypad_keymatrix_row_column_to_key_number(keypad_keymatrix_obj_t *self, mp_uint_t row, mp_uint_t column) {
return row_column_to_key_number(self, row, column);
}

View File

@ -89,17 +89,6 @@ bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self) {
size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self) {
return self->digitalinouts->len;
}
bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number) {
return self->currently_pressed[key_number];
}
// The length of states has already been validated.
void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states) {
// Read the state atomically.
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
memcpy(states, self->currently_pressed, common_hal_keypad_keys_get_key_count(self));
supervisor_release_lock(&keypad_scanners_linked_list_lock);
}
mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self) {
return MP_OBJ_FROM_PTR(self->events);

View File

@ -101,17 +101,6 @@ bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t
size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self) {
return self->key_count;
}
bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number) {
return self->currently_pressed[key_number];
}
// The length of states has already been validated.
void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states) {
// Read the state atomically.
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
memcpy(states, self->currently_pressed, common_hal_keypad_shiftregisterkeys_get_key_count(self));
supervisor_release_lock(&keypad_scanners_linked_list_lock);
}
mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self) {
return MP_OBJ_FROM_PTR(self->events);