Created
April 1, 2020 22:49
-
-
Save ktemkin/d4ceca1859d789645e3a7589c01756dd to your computer and use it in GitHub Desktop.
GreatFET-based push to talk button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This file is part of LUNA. | |
# | |
import asyncio | |
import logging | |
from greatfet import GreatFET | |
from facedancer import main | |
from facedancer.devices.keyboard import USBKeyboardDevice | |
from facedancer.classes.hid.keyboard import KeyboardModifiers, KeyboardKeys | |
device = USBKeyboardDevice() | |
BUTTON = 'J1_P3' | |
KEYCODE = KeyboardKeys.PAUSE | |
async def handle_button_presses(): | |
# Steal the GreatFET from our device. | |
# (This is lazy; we probably should have created it ourself and passed it to the Device initializer.) | |
gf = device.backend.device | |
# Grab our button, and set it to be an input. | |
button = gf.gpio.get_pin(BUTTON) | |
button.set_direction(button.DIRECTION_IN) | |
while True: | |
# Sleep for a little bit to let the USB processing happen. | |
# This is the USB interrupt interval; so sleeping for any less than | |
# this isn't really useful anyways. | |
await asyncio.sleep(0.1) | |
# ... and then process our button state. | |
if button.read(): | |
device.all_keys_up() | |
else: | |
device.key_down(KEYCODE) | |
main(device, handle_button_presses()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment