From 03de2df20ae992a3f619d81d5062b652237588a6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 29 May 2021 10:55:57 -0500 Subject: [PATCH] adding brightness consumer codes --- adafruit_hid/consumer_control_code.py | 4 +++ docs/examples.rst | 30 +++++++++++++++++-- examples/hid_consumer_control_brightness.py | 32 +++++++++++++++++++++ examples/hid_joywing_gamepad.py | 2 ++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 examples/hid_consumer_control_brightness.py diff --git a/adafruit_hid/consumer_control_code.py b/adafruit_hid/consumer_control_code.py index 12f668b..e49137e 100644 --- a/adafruit_hid/consumer_control_code.py +++ b/adafruit_hid/consumer_control_code.py @@ -41,3 +41,7 @@ class ConsumerControlCode: """Decrease volume""" VOLUME_INCREMENT = 0xE9 """Increase volume""" + BRIGHTNESS_DECREMENT = 0x70 + """Decrease Brightness""" + BRIGHTNESS_INCREMENT = 0x6F + """Increase Brightness""" diff --git a/docs/examples.rst b/docs/examples.rst index 2a6c333..549b4bb 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,18 +3,42 @@ Simple test Ensure your device works with this simple test. +.. literalinclude:: ../examples/hid_simpletest.py + :caption: examples/hid_simpletest.py + :linenos: + +Keyboard Shortcuts +------------------- + +Send ALT+Tab for swapping windows, and CTRL+K for searching in a browser. + .. literalinclude:: ../examples/hid_keyboard_shortcuts.py :caption: examples/hid_keyboard_shortcuts.py :linenos: -.. literalinclude:: ../examples/hid_simpletest.py - :caption: examples/hid_simpletest.py - :linenos: +Simple Gamepad +--------------- + +Send gamepad buttons and joystick to the host. .. literalinclude:: ../examples/hid_simple_gamepad.py :caption: examples/hid_simple_gamepad.py :linenos: +HID Joywing +------------ + +Use Joy FeatherWing to drive Gamepad. + .. literalinclude:: ../examples/hid_joywing_gamepad.py :caption: examples/hid_joywing_gamepad.py :linenos: + +Consumer Control Brightness +---------------------------- + +Send brightness up and down consumer codes to the host. + +.. literalinclude:: ../examples/hid_consumer_control_brightness.py + :caption: examples/hid_consumer_control_brightness.py + :linenos: diff --git a/examples/hid_consumer_control_brightness.py b/examples/hid_consumer_control_brightness.py new file mode 100644 index 0000000..1cf922c --- /dev/null +++ b/examples/hid_consumer_control_brightness.py @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries +# SPDX-License-Identifier: MIT + +import time +import board +import digitalio +import usb_hid +from adafruit_hid.consumer_control import ConsumerControl +from adafruit_hid.consumer_control_code import ConsumerControlCode + +cc = ConsumerControl(usb_hid.devices) + +# define buttons. these can be any physical switches/buttons, but the values +# here work out-of-the-box with a FunHouse UP and DOWN buttons. +button_up = digitalio.DigitalInOut(board.BUTTON_UP) +button_up.switch_to_input(pull=digitalio.Pull.DOWN) + +button_down = digitalio.DigitalInOut(board.BUTTON_DOWN) +button_down.switch_to_input(pull=digitalio.Pull.DOWN) + +while True: + if button_up.value: + print("Button up pressed!") + # send brightness up button press + cc.send(ConsumerControlCode.BRIGHTNESS_INCREMENT) + + if button_down.value: + print("Button down pressed!") + # send brightness down button press + cc.send(ConsumerControlCode.BRIGHTNESS_DECREMENT) + + time.sleep(0.1) diff --git a/examples/hid_joywing_gamepad.py b/examples/hid_joywing_gamepad.py index 850279b..2d23db4 100644 --- a/examples/hid_joywing_gamepad.py +++ b/examples/hid_joywing_gamepad.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: MIT # Use Joy FeatherWing to drive Gamepad. +# https://www.adafruit.com/product/3632 +# https://learn.adafruit.com/joy-featherwing import time