Skip to content

Commit 1da880c

Browse files
authored
Merge pull request #23 from dhalbert/16_bit_consumer_control
handle 16-bit Consumer Control codes
2 parents 058c945 + 12b35f6 commit 1da880c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

adafruit_hid/consumer_control.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
raise ImportError('{0} is not supported in CircuitPython 2.x or lower'.format(__name__))
3434

3535
# pylint: disable=wrong-import-position
36+
import struct
3637
import time
3738
import usb_hid
3839

@@ -53,10 +54,7 @@ def __init__(self):
5354
raise IOError("Could not find an HID Consumer device.")
5455

5556
# Reuse this bytearray to send consumer reports.
56-
self.report = bytearray(2)
57-
58-
# View bytes as a single 16-bit number.
59-
self.usage_id = memoryview(self.report)[0:2]
57+
self._report = bytearray(2)
6058

6159
# Do a no-op to test if HID device is ready.
6260
# If not, wait a bit and try once more.
@@ -82,7 +80,7 @@ def send(self, consumer_code):
8280
# Advance to next track (song).
8381
consumer_control.send(ConsumerControlCode.SCAN_NEXT_TRACK)
8482
"""
85-
self.usage_id[0] = consumer_code
86-
self.hid_consumer.send_report(self.report)
87-
self.usage_id[0] = 0x0
88-
self.hid_consumer.send_report(self.report)
83+
struct.pack_into("<H", self._report, 0, consumer_code)
84+
self.hid_consumer.send_report(self._report)
85+
self._report[0] = self._report[1] = 0x0
86+
self.hid_consumer.send_report(self._report)

0 commit comments

Comments
 (0)