Skip to content

Commit

Permalink
Merge pull request #23 from dhalbert/16_bit_consumer_control
Browse files Browse the repository at this point in the history
handle 16-bit Consumer Control codes
  • Loading branch information
dhalbert authored Jun 1, 2018
2 parents 058c945 + 12b35f6 commit 1da880c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions adafruit_hid/consumer_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
raise ImportError('{0} is not supported in CircuitPython 2.x or lower'.format(__name__))

# pylint: disable=wrong-import-position
import struct
import time
import usb_hid

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

# Reuse this bytearray to send consumer reports.
self.report = bytearray(2)

# View bytes as a single 16-bit number.
self.usage_id = memoryview(self.report)[0:2]
self._report = bytearray(2)

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

0 comments on commit 1da880c

Please sign in to comment.