Skip to content

Instantly share code, notes, and snippets.

@vitorio
Last active March 17, 2024 22:53
Show Gist options
  • Save vitorio/29743a890c5104f58c6d275585d25f4f to your computer and use it in GitHub Desktop.
Save vitorio/29743a890c5104f58c6d275585d25f4f to your computer and use it in GitHub Desktop.
Force a kiosk into BIOS to boot from a USB drive + offer ⊞ key after boot, Adafruit Neo Trinkey, CircuitPython 8.x
import board
import touchio
import storage
import usb_cdc
import usb_midi
import usb_hid
# Neo Trinkey
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
# If the capacitive terminals ARE NOT pinched between your fingers, set up the BIOS keyboard
# via todbot @ https://gist.github.com/todbot/707e4e3d393313cf31cdab56bf9d4255
if touch1.raw_value > 1500 or touch2.raw_value > 1500:
pass
else:
storage.disable_usb_drive()
storage.remount("/", False)
usb_cdc.disable()
usb_midi.disable()
usb_hid.enable((usb_hid.Device.KEYBOARD), boot_device=1)
import time
import board
import touchio
import usb_hid
import supervisor
import neopixel
import os
import microcontroller
from rainbowio import colorwheel
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
# Remember to use the MPY versions or you'll get a MemoryError
from adafruit_debouncer import Debouncer
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, auto_write=False)
pixels.brightness = 0.025
# Don't autoreload, since we have to hold the capacitive terminals to boot normally
supervisor.runtime.autoreload = False
def rainbow(color_index):
for led in range(4):
pixel_index = (led * 256 // 4) + color_index
pixels[led] = colorwheel(pixel_index & 255)
pixels.show()
color = 0
# If the capacitive terminals ARE NOT pinched between your fingers, set up the BIOS keyboard
# via todbot @ https://gist.github.com/todbot/707e4e3d393313cf31cdab56bf9d4255
if touch1.raw_value > 1500 or touch2.raw_value > 1500:
pass
else:
pixels.fill((255, 255, 0))
pixels.show()
# Wait for USB to come up
while not supervisor.runtime.usb_connected:
pass
pixels.fill((0, 255, 0))
pixels.show()
kbd = Keyboard(usb_hid.devices)
BIOSKEYB = True
if 'boottime.txt' in os.listdir():
if os.stat('boottime.txt')[6] < 90:
BIOSKEYB = False
with open('boottime.txt', 'w') as bt:
bt.write('')
bt.flush()
if BIOSKEYB:
# Mash DELETE 20 times to get into BIOS
for a in range(20):
kbd.send(Keycode.DELETE)
time.sleep(0.25)
time.sleep(5)
# F6 is Advanced Settings
kbd.send(Keycode.F6)
time.sleep(1)
# Left Arrow moves us to the exit screen
kbd.send(Keycode.LEFT_ARROW)
time.sleep(1)
# End moves us to the flash drive
kbd.send(Keycode.END)
time.sleep(1)
# Enter boots
kbd.send(Keycode.ENTER)
touch1db = Debouncer(touch1)
touch2db = Debouncer(touch2)
sec = 0
tick = time.monotonic()
TIMECHECK = True
while True:
touch1db.update()
touch2db.update()
if touch1db.fell:
kbd.send(Keycode.WINDOWS)
elif touch2db.fell:
kbd.send(Keycode.WINDOWS)
color = color + 1
if color > 255:
color = 0
rainbow(color)
if TIMECHECK:
if sec <= 90:
if time.monotonic() - tick >= 5.0:
with open('boottime.txt', 'a') as bt:
bt.write(' ')
bt.flush()
tick = time.monotonic()
sec = sec + 5
else:
os.remove('boottime.txt')
TIMECHECK = False
if not supervisor.runtime.usb_connected:
microcontroller.reset()
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment