diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-09-10 17:35:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-10 17:35:04 -0700 |
| commit | 9256e6b376c5a8a6c185e6a4ab25e01987e04445 (patch) | |
| tree | 498cdf5d73baa4316b90e4199cbfb7bebbfd0a03 /shared-bindings | |
| parent | 9e722c8c99d1c31d8ac1c009aef8e2da31f401b9 (diff) | |
| parent | f0bb9635bf311013e7b1ff69d1a0542575cf9d0a (diff) | |
Merge pull request #3302 from xiongyihui/main
support to get HID OUT report
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/usb_hid/Device.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 83c0df4ae..c7c05a974 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -58,6 +58,25 @@ STATIC mp_obj_t usb_hid_device_send_report(mp_obj_t self_in, mp_obj_t buffer) { } MP_DEFINE_CONST_FUN_OBJ_2(usb_hid_device_send_report_obj, usb_hid_device_send_report); +//| last_received_report: bytes +//| """The HID OUT report as a `bytes`. (read-only). `None` if nothing received.""" +//| +STATIC mp_obj_t usb_hid_device_obj_get_last_received_report(mp_obj_t self_in) { + usb_hid_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + if (self->out_report_buffer == 0) { + return mp_const_none; + } + return mp_obj_new_bytes(self->out_report_buffer, self->out_report_length); +} +MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_device_get_last_received_report_obj, usb_hid_device_obj_get_last_received_report); + +const mp_obj_property_t usb_hid_device_last_received_report_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&usb_hid_device_get_last_received_report_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + //| usage_page: int //| """The usage page of the device as an `int`. Can be thought of a category. (read-only)""" //| @@ -95,9 +114,10 @@ const mp_obj_property_t usb_hid_device_usage_obj = { }; STATIC const mp_rom_map_elem_t usb_hid_device_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_send_report), MP_ROM_PTR(&usb_hid_device_send_report_obj) }, - { MP_ROM_QSTR(MP_QSTR_usage_page), MP_ROM_PTR(&usb_hid_device_usage_page_obj)}, - { MP_ROM_QSTR(MP_QSTR_usage), MP_ROM_PTR(&usb_hid_device_usage_obj)}, + { MP_ROM_QSTR(MP_QSTR_send_report), MP_ROM_PTR(&usb_hid_device_send_report_obj) }, + { MP_ROM_QSTR(MP_QSTR_last_received_report), MP_ROM_PTR(&usb_hid_device_last_received_report_obj) }, + { MP_ROM_QSTR(MP_QSTR_usage_page), MP_ROM_PTR(&usb_hid_device_usage_page_obj)}, + { MP_ROM_QSTR(MP_QSTR_usage), MP_ROM_PTR(&usb_hid_device_usage_obj)}, }; STATIC MP_DEFINE_CONST_DICT(usb_hid_device_locals_dict, usb_hid_device_locals_dict_table); |
