66import board
77import rp2pio
88import usb_hid
9+ from keypad import Keys
910from adafruit_hid .consumer_control import ConsumerControl
1011from adafruit_hid .keyboard import Keyboard
12+ from adafruit_hid .keyboard import Keycode
1113from adafruit_pioasm import Program
1214from adafruit_ticks import ticks_add , ticks_less , ticks_ms
1315
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+
1420from next_keycode import (
1521 cc_value ,
1622 is_cc ,
2026 shift_modifiers ,
2127)
2228
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 )
2634
2735pio_program = Program (
2836 """
@@ -162,6 +170,7 @@ def handle_report(self, report_value):
162170 else :
163171 self .set_key_state (code , make )
164172
173+ keys = Keys ([board .SCK ], value_when_pressed = False )
165174
166175handler = KeyboardHandler ()
167176
@@ -181,6 +190,9 @@ def handle_report(self, report_value):
181190
182191try :
183192 while True :
193+ if (event := keys .events .get ()):
194+ handler .set_key_state (POWER_KEY_SENDS , event .pressed )
195+
184196 sm .write (QUERY )
185197 deadline = ticks_add (ticks_ms (), 100 )
186198 while ticks_less (ticks_ms (), deadline ):
0 commit comments