Skip to content

Commit c05463f

Browse files
authored
Merge pull request #1511 from adafruit/neotrinkey_zoom_shortcuts
Adding code for NeoTrinkey Zoom shortcuts
2 parents b9ed630 + 95b7b3d commit c05463f

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

NeoTrinkey_Zoom_Shortcuts/code.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import time
2+
import board
3+
import neopixel
4+
import touchio
5+
import usb_hid
6+
from adafruit_hid.keyboard import Keyboard
7+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
8+
from adafruit_hid.keycode import Keycode
9+
10+
# setup for onboard neopixels
11+
pixel_pin = board.NEOPIXEL
12+
num_pixels = 4
13+
14+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.05, auto_write=False)
15+
16+
# setup for cap touch pads
17+
top_touch = touchio.TouchIn(board.TOUCH1)
18+
bot_touch = touchio.TouchIn(board.TOUCH2)
19+
20+
# HID keyboard input setup
21+
keyboard = Keyboard(usb_hid.devices)
22+
keyboard_layout = KeyboardLayoutUS(keyboard)
23+
# variable for the ALT key
24+
alt_key = Keycode.ALT
25+
26+
# rainbow cycle animation
27+
def wheel(pos):
28+
# Input a value 0 to 255 to get a color value.
29+
# The colours are a transition r - g - b - back to r.
30+
if pos < 0 or pos > 255:
31+
return (0, 0, 0)
32+
if pos < 85:
33+
return (255 - pos * 3, pos * 3, 0)
34+
if pos < 170:
35+
pos -= 85
36+
return (0, 255 - pos * 3, pos * 3)
37+
pos -= 170
38+
return (pos * 3, 0, 255 - pos * 3)
39+
40+
41+
def rainbow_cycle(wait):
42+
for j in range(255):
43+
for i in range(num_pixels):
44+
rc_index = (i * 256 // num_pixels) + j
45+
pixels[i] = wheel(rc_index & 255)
46+
pixels.show()
47+
time.sleep(wait)
48+
49+
# variables for colors
50+
RED = (255, 0, 0)
51+
GREEN = (0, 255, 0)
52+
53+
# state machines
54+
# cap touch debouncing
55+
bot_pressed = False
56+
top_pressed = False
57+
# default mute states
58+
mic_mute = True
59+
vid_mute = True
60+
# time.monotonic() tracker
61+
clock = time.monotonic()
62+
# tracking for initiating an exit from the meeting
63+
escape = False
64+
escape_1 = False
65+
escape_2 = False
66+
67+
while True:
68+
# cap touch debouncing
69+
if not top_touch.value and top_pressed:
70+
top_pressed = False
71+
if not bot_touch.value and bot_pressed:
72+
bot_pressed = False
73+
# if your mic is muted...
74+
if mic_mute:
75+
# neopixels are red
76+
pixels[0] = RED
77+
pixels[1] = RED
78+
pixels.show()
79+
# if your camera is muted...
80+
if vid_mute:
81+
# neopixels are red
82+
pixels[2] = RED
83+
pixels[3] = RED
84+
pixels.show()
85+
# if your mic is NOT muted...
86+
if not mic_mute:
87+
# neopixels are green
88+
pixels[0] = GREEN
89+
pixels[1] = GREEN
90+
pixels.show()
91+
# if your camera is NOT muted...
92+
if not vid_mute:
93+
# neopixels are green
94+
pixels[2] = GREEN
95+
pixels[3] = GREEN
96+
pixels.show()
97+
# if you are leaving the meeting...
98+
if escape:
99+
# neopixels are rainbow
100+
rainbow_cycle(0)
101+
# resets exit states
102+
escape = False
103+
escape_1 = False
104+
escape_2 = False
105+
mic_mute = True
106+
vid_mute = True
107+
# if you press the top touch cap touch pad...
108+
if (top_touch.value and not top_pressed):
109+
top_pressed = True
110+
# start time count for exit
111+
clock = time.monotonic()
112+
# slight delay so that you don't automatically mute/unmute
113+
# if your intent is to exit
114+
time.sleep(0.12)
115+
# if after the delay you're still pressing the cap touch pad...
116+
if top_touch.value and top_pressed:
117+
print("escape top")
118+
# initial escape state is set to true
119+
escape_1 = True
120+
# if you aren't still pressing the cap touch pad...
121+
else:
122+
# if your camera was muted...
123+
if vid_mute:
124+
print("top")
125+
# your camera is NOT muted
126+
vid_mute = False
127+
# resets escape state just in case
128+
escape_1 = False
129+
# if your camera was NOT muted...
130+
elif not vid_mute:
131+
print("top")
132+
# your camera is muted
133+
vid_mute = True
134+
# resets escape state just in case
135+
escape_1 = False
136+
# sends camera mute/unmute shortcut
137+
keyboard.send(alt_key, Keycode.V)
138+
# if you press the top touch cap touch pad...
139+
if (bot_touch.value and not bot_pressed):
140+
bot_pressed = True
141+
# start time count for exit
142+
clock = time.monotonic()
143+
# slight delay so that you don't automatically mute/unmute
144+
# if your intent is to exit
145+
time.sleep(0.12)
146+
# if after the delay you're still pressing the cap touch pad...
147+
if bot_touch.value and bot_pressed:
148+
print("escape bot")
149+
# initial escape state is set to true
150+
escape_2 = True
151+
# if you aren't still pressing the cap touch pad...
152+
else:
153+
# if your mic was muted...
154+
if mic_mute:
155+
print("bot")
156+
# your mic is NOT muted
157+
mic_mute = False
158+
# resets escape state just in case
159+
escape_2 = False
160+
# if your mic was NOT muted...
161+
elif not mic_mute:
162+
print("bot")
163+
# your mic is muted
164+
mic_mute = True
165+
# resets escape state just in case
166+
escape_2 = False
167+
# sends mic mute/unmute shortcut
168+
keyboard.send(alt_key, Keycode.A)
169+
# if you held down both cap touch pads and 2 seconds has passed...
170+
if ((clock + 2) < time.monotonic()) and (escape_1 and escape_2):
171+
print("escape")
172+
# full escape state is set
173+
escape = True
174+
# sends exit meeting shortcut
175+
keyboard.send(alt_key, Keycode.Q)
176+
# brief delay for confirmation window to open
177+
time.sleep(0.1)
178+
# sends enter to confirm meeting exit
179+
keyboard.send(Keycode.ENTER)

0 commit comments

Comments
 (0)