1
+ import os
2
+ import board
3
+ from digitalio import DigitalInOut , Direction
4
+ import time
5
+ import touchio
6
+
7
+ # Set this to True to turn the touchpads into a keyboard
8
+ ENABLE_KEYBOARD = True
9
+
10
+ # Used if we do HID output, see below
11
+ if ENABLE_KEYBOARD :
12
+ from adafruit_hid .keyboard import Keyboard
13
+ from adafruit_hid .keycode import Keycode
14
+ from adafruit_hid .keyboard_layout_us import KeyboardLayoutUS
15
+ kbd = Keyboard ()
16
+ layout = KeyboardLayoutUS (kbd )
17
+
18
+ #print(dir(board), os.uname()) # Print a little about ourselves
19
+
20
+ led = DigitalInOut (board .D13 )
21
+ led .direction = Direction .OUTPUT
22
+
23
+ touches = [DigitalInOut (board .CAP0 )]
24
+ for p in (board .CAP1 , board .CAP2 , board .CAP3 ):
25
+ touches .append (touchio .TouchIn (p ))
26
+
27
+ leds = []
28
+ for p in (board .LED4 , board .LED5 , board .LED6 , board .LED7 ):
29
+ led = DigitalInOut (p )
30
+ led .direction = Direction .OUTPUT
31
+ led .value = True
32
+ time .sleep (0.25 )
33
+ leds .append (led )
34
+ for led in leds :
35
+ led .value = False
36
+
37
+
38
+ cap_touches = [False , False , False , False ]
39
+
40
+ def read_caps ():
41
+ t0_count = 0
42
+ t0 = touches [0 ]
43
+ t0 .direction = Direction .OUTPUT
44
+ t0 .value = True
45
+ t0 .direction = Direction .INPUT
46
+ # funky idea but we can 'diy' the one non-hardware captouch device by hand
47
+ # by reading the drooping voltage on a tri-state pin.
48
+ t0_count = t0 .value + t0 .value + t0 .value + t0 .value + t0 .value + \
49
+ t0 .value + t0 .value + t0 .value + t0 .value + t0 .value + \
50
+ t0 .value + t0 .value + t0 .value + t0 .value + t0 .value
51
+ cap_touches [0 ] = t0_count > 2
52
+ cap_touches [1 ] = touches [1 ].raw_value > 3000
53
+ cap_touches [2 ] = touches [2 ].raw_value > 3000
54
+ cap_touches [3 ] = touches [3 ].raw_value > 3000
55
+ return cap_touches
56
+
57
+ while True :
58
+ caps = read_caps ()
59
+ print (caps )
60
+ # light up the matching LED
61
+ for i ,c in enumerate (caps ):
62
+ leds [i ].value = c
63
+ if caps [0 ]:
64
+ if ENABLE_KEYBOARD :
65
+ # Zoom
66
+ kbd .press (Keycode .ALT , Keycode .V )
67
+ kbd .release (Keycode .V )
68
+ time .sleep (0.25 )
69
+ kbd .press (Keycode .A )
70
+ kbd .release_all ()
71
+ if caps [1 ]:
72
+ if ENABLE_KEYBOARD :
73
+ # Teams
74
+ # Note that video toggle doesn't work in the web app
75
+ kbd .press (Keycode .CONTROL , Keycode .SHIFT , Keycode .M )
76
+ kbd .release (Keycode .M )
77
+ time .sleep (0.5 )
78
+ kbd .press (Keycode .O )
79
+ kbd .release_all ()
80
+ if caps [2 ]:
81
+ if ENABLE_KEYBOARD :
82
+ # Skype
83
+ kbd .press (Keycode .CONTROL , Keycode .M )
84
+ kbd .release (Keycode .M )
85
+ time .sleep (0.5 )
86
+ kbd .press (Keycode .SHIFT , Keycode .K )
87
+ kbd .release_all ()
88
+ if caps [3 ]:
89
+ if ENABLE_KEYBOARD :
90
+ # Jitsi
91
+ kbd .press (Keycode .M )
92
+ kbd .release (Keycode .M )
93
+ time .sleep (0.5 )
94
+ kbd .press (Keycode .V )
95
+ kbd .release_all ()
96
+ time .sleep (.2 )
0 commit comments