Skip to content

handle 16-bit Consumer Control codes #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)