Skip to content

Commit 520fae2

Browse files
committed
improve doc; put example in a directory
1 parent de2ef73 commit 520fae2

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

adafruit_radial_controller/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
At the minimum, a radial controller is a rotary encoder plus a switch.
1919
2020
Documentation is available from Microsoft:
21+
https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/radial-implementation-guide
2122
2223
**Software and Dependencies:**
2324
@@ -77,8 +78,10 @@ def click(self):
7778

7879
def rotate(self, degree_tenths):
7980
"""Set relative rotation value, in tenths of a degree.
80-
A value of 1 or 10 can be too small and cause tool selection or scrolling to not work.
81-
100 is a good value for a single increment in most cases."""
81+
A value of +/- 1 or 10 can be too small and cause tool selection or scrolling to not work.
82+
+/- 100 is a good value for a single increment in many cases, though it causes value sliders
83+
to change by 10 instead of 1.
84+
"""
8285

8386
if not -3600 <= degree_tenths <= 3600:
8487
raise ValueError("rotation must be in range -3600 to 3600")

adafruit_radial_controller/device.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ def device(report_id):
6969
0xc0, # End Collection
7070
0xc0, # End Collection
7171

72-
# The presence of this (even empty) System Control Collection makes the device
73-
# appears in /dev/input in Linux. Don't know why this works yet.
72+
# The presence of this (empty) System Control Collection makes the device
73+
# appear in /dev/input in Linux, which will help if radial controller
74+
# functionality is added in userspace code.
7475
0x09, 0x80, # Usage (System Control)
7576
0xa1, 0x01, # Collection (Application)
7677
0xc0, # End Collection
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 Dan Halbert for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import usb_hid
6+
7+
import adafruit_radial_controller.device
8+
9+
REPORT_ID = 5
10+
11+
radial_controller_device = adafruit_radial_controller.device.device(REPORT_ID)
12+
usb_hid.enable((radial_controller_device,))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 Dan Halbert for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import board
6+
import digitalio
7+
import rotaryio
8+
import usb_hid
9+
10+
from adafruit_debouncer import Debouncer
11+
import adafruit_radial_controller
12+
13+
switch = digitalio.DigitalInOut(board.SWITCH)
14+
switch.pull = digitalio.Pull.DOWN
15+
debounced_switch = Debouncer(switch)
16+
17+
encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB)
18+
19+
radial_controller = adafruit_radial_controller.RadialController(usb_hid.devices)
20+
21+
last_position = 0
22+
DEGREE_TENTHS_MULTIPLIER = 100
23+
24+
while True:
25+
debounced_switch.update()
26+
if debounced_switch.rose:
27+
radial_controller.press()
28+
if debounced_switch.fell:
29+
radial_controller.release()
30+
31+
position = encoder.position
32+
delta = position - last_position
33+
if delta != 0:
34+
radial_controller.rotate(delta * DEGREE_TENTHS_MULTIPLIER)
35+
last_position = position

0 commit comments

Comments
 (0)