Skip to content

Instantly share code, notes, and snippets.

@pickeditmate
Forked from ktemkin/push_to_talk.py
Created February 6, 2023 19:46
Show Gist options
  • Save pickeditmate/2585b51d7ce6c58c4d59c42b1dacf1a5 to your computer and use it in GitHub Desktop.
Save pickeditmate/2585b51d7ce6c58c4d59c42b1dacf1a5 to your computer and use it in GitHub Desktop.
GreatFET-based push to talk button
#
# 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