Skip to content

Commit 75db5a2

Browse files
authored
Merge pull request #5392 from dhalbert/report-id-0
allow usb_hid.Device(..., report_ids=(0,), ...)
2 parents df10543 + de8f7b1 commit 75db5a2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ msgstr ""
165165
msgid "%q should be an int"
166166
msgstr ""
167167

168+
#: shared-bindings/usb_hid/Device.c
169+
msgid "%q with a report ID of 0 must be of length 1"
170+
msgstr ""
171+
168172
#: py/bc.c py/objnamedtuple.c
169173
msgid "%q() takes %d positional arguments but %d were given"
170174
msgstr ""

shared-bindings/usb_hid/Device.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args
136136
// It's not the actual argument that's out of range, but its elements.
137137
// But the error message is close enough.
138138
MP_OBJ_SMALL_INT_VALUE(mp_obj_subscr(report_ids, i_obj, MP_OBJ_SENTINEL)),
139-
1, 255, MP_QSTR_report_ids);
139+
0, 255, MP_QSTR_report_ids);
140140

141141
in_report_lengths_array[i] = (uint8_t)mp_arg_validate_int_range(
142142
MP_OBJ_SMALL_INT_VALUE(mp_obj_subscr(in_report_lengths, i_obj, MP_OBJ_SENTINEL)),
@@ -147,6 +147,10 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args
147147
0, 255, MP_QSTR_out_report_lengths);
148148
}
149149

150+
if (report_ids_array[0] == 0 && report_ids_count > 1) {
151+
mp_raise_ValueError_varg(translate("%q with a report ID of 0 must be of length 1"), MP_QSTR_report_ids);
152+
}
153+
150154
common_hal_usb_hid_device_construct(
151155
self, descriptor, usage_page, usage, report_ids_count, report_ids_array, in_report_lengths_array, out_report_lengths_array);
152156
return (mp_obj_t)self;

0 commit comments

Comments
 (0)