Skip to content

Commit 4a265ea

Browse files
committed
Adding kill-switch on boot (pressing any button); more buttons
1 parent 67413e3 commit 4a265ea

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

pico/boot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import board
66
import digitalio
77
import storage
8-
from buttons import btns, pins
8+
from buttons import btns, pins, CONFIG_BUTTON
9+
import sys
910

10-
print(f"Checking if btn[0]={pins[0]} is pressed.")
11+
print(f"Checking that no buttons are pressed at boot.")
1112

1213
# If write pin is connected to ground on start-up, CircuitPython can write to CIRCUITPY filesystem.
13-
if not btns[0].value:
14+
if not CONFIG_BUTTON.value:
1415
print("Mounting as read-only for host! Disabling storage and serial port.")
1516
storage.remount("/", readonly=False)
1617
storage.disable_usb_drive()
1718
usb_cdc.disable()
19+
elif not all(btn.value for btn in btns):
20+
print("Not all buttons were 'up'. Exiting")
21+
sys.exit(-1)
1822
else:
1923
print("Not pressed. Starting in RW mode.")

pico/buttons.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import board
22
import digitalio
33

4-
pins = [board.GP0, board.GP1]
4+
pins = [board.GP0, board.GP1, board.GP2, board.GP3, board.GP4, board.GP5]
55
btns = []
66
for pin in pins:
77
btn = digitalio.DigitalInOut(pin)
88
btn.direction = digitalio.Direction.INPUT
99
btn.pull = digitalio.Pull.UP
1010
btns.append(btn)
11+
12+
CONFIG_BUTTON = btns[0]

pico/code.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import board
66
import digitalio
77
import json
8-
from buttons import btns, pins
8+
import sys
9+
from buttons import btns, pins, CONFIG_BUTTON
910
BUTTON_COUNT = len(btns)
1011

1112
print("Starting")
@@ -18,6 +19,13 @@
1819

1920
keyboard = Keyboard(usb_hid.devices)
2021

22+
23+
if not CONFIG_BUTTON.value:
24+
print("Don't care about the config button. It only has special meaning for the boot script.")
25+
if not all(btn.value for btn in btns):
26+
print("Not all buttons were 'up'. Exiting")
27+
sys.exit(-1)
28+
2129
try:
2230
with open("config.json", "rt") as f:
2331
config = json.load(f)

pico/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[["ALT", "TAB"], null]
1+
[["A"], ["B"], ["C"], ["D"], ["E"], ["F"]]

0 commit comments

Comments
 (0)