Skip to content

adding brightness consumer codes #70

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
May 29, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions adafruit_hid/consumer_control_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ class ConsumerControlCode:
"""Decrease volume"""
VOLUME_INCREMENT = 0xE9
"""Increase volume"""
BRIGHTNESS_DECREMENT = 0x70
"""Decrease Brightness"""
BRIGHTNESS_INCREMENT = 0x6F
"""Increase Brightness"""
30 changes: 27 additions & 3 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
32 changes: 32 additions & 0 deletions examples/hid_consumer_control_brightness.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions examples/hid_joywing_gamepad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down