Skip to content

Instantly share code, notes, and snippets.

@willwade
Last active January 25, 2021 11:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willwade/19b495293c5cdb1e241fdd1421a96756 to your computer and use it in GitHub Desktop.
Save willwade/19b495293c5cdb1e241fdd1421a96756 to your computer and use it in GitHub Desktop.
Presses Home keys, then types predictable. Useful for disabled people waking up a iPad. This is in circuitPython.
"""
Whatever state the iPad is in this code will wake the device up
Attach a button to Feather nRF52840. Set the pin on line 21.
WARNING 1: DO NOT HAVE A PASSCODE FOR IPAD!
WARNING 2: NOT FULLY TESTED. Dare say there are some use cases where this will go wrong. Like if iPad doesnt wake up quick enough
WARNING 3: Feel free to adapt line 59 to the app of your choosing BUT if the app isnt on the device it wont work.
"""
import time
import board
from digitalio import DigitalInOut, Direction, Pull
import adafruit_ble
from adafruit_ble.advertising import Advertisement
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.standard.hid import HIDService
from adafruit_ble.services.standard.device_info import DeviceInfoService
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
button_1 = DigitalInOut(board.D5)
button_1.direction = Direction.INPUT
hid = HIDService()
device_info = DeviceInfoService(
software_revision=adafruit_ble.__version__, manufacturer="Ace Centre"
)
advertisement = ProvideServicesAdvertisement(hid)
advertisement.appearance = 961
scan_response = Advertisement()
scan_response.complete_name = "AceWakeButton"
ble = adafruit_ble.BLERadio()
if not ble.connected:
print("advertising")
ble.start_advertising(advertisement, scan_response)
else:
print("already connected")
print(ble.connections)
k = Keyboard(hid.devices)
kl = KeyboardLayoutUS(k)
while True:
while not ble.connected:
pass
print("Start typing:")
while ble.connected:
if button_1.value is False:
k.press(Keycode.COMMAND, Keycode.H)
k.release_all()
k.press(Keycode.COMMAND, Keycode.SPACE)
k.release_all()
k.press(Keycode.COMMAND, Keycode.A)
k.release_all()
k.send(Keycode.DELETE)
time.sleep(0.2)
kl.write("Predictable")
time.sleep(0.1)
k.send(Keycode.ENTER)
time.sleep(0.4)
ble.start_advertising(advertisement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment