6
6
import board
7
7
import rp2pio
8
8
import usb_hid
9
+ from keypad import Keys
9
10
from adafruit_hid .consumer_control import ConsumerControl
10
11
from adafruit_hid .keyboard import Keyboard
12
+ from adafruit_hid .keyboard import Keycode
11
13
from adafruit_pioasm import Program
12
14
from adafruit_ticks import ticks_add , ticks_less , ticks_ms
13
15
16
+ # Customize the power key's keycode. You can change it to `Keycode.POWER` if
17
+ # you really want to accidentally power off your computer!
18
+ POWER_KEY_SENDS = Keycode .F1
19
+
14
20
from next_keycode import (
15
21
cc_value ,
16
22
is_cc ,
20
26
shift_modifiers ,
21
27
)
22
28
23
- NEXT_SERIAL_BUS_FREQUENCY = (
24
- 18958 # 455kHz/24 https://journal.spencerwnelson.com/entries/nextkb.html
25
- )
29
+ # according to https://journal.spencerwnelson.com/entries/nextkb.html the
30
+ # keyboard's timing source is a 455MHz crystal, and the serial data rate is
31
+ # 1/24 the crystal frequency. This differs by a few percent from the "50us" bit
32
+ # time reported in other sources.
33
+ NEXT_SERIAL_BUS_FREQUENCY = round (455_000 / 24 )
26
34
27
35
pio_program = Program (
28
36
"""
@@ -162,6 +170,7 @@ def handle_report(self, report_value):
162
170
else :
163
171
self .set_key_state (code , make )
164
172
173
+ keys = Keys ([board .SCK ], value_when_pressed = False )
165
174
166
175
handler = KeyboardHandler ()
167
176
@@ -181,6 +190,9 @@ def handle_report(self, report_value):
181
190
182
191
try :
183
192
while True :
193
+ if (event := keys .events .get ()):
194
+ handler .set_key_state (POWER_KEY_SENDS , event .pressed )
195
+
184
196
sm .write (QUERY )
185
197
deadline = ticks_add (ticks_ms (), 100 )
186
198
while ticks_less (ticks_ms (), deadline ):
0 commit comments