Skip to content
Snippets Groups Projects
Commit bd31fa5c authored by schneider's avatar schneider
Browse files

feat(hid): Improve demo app

parent 0a5c478b
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ import color
import display
import ble_hid
import bhi160
import config
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
......@@ -15,10 +16,13 @@ from adafruit_hid.consumer_control import ConsumerControl
import time
import os
disp = display.open()
def keyboard_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Keyboard", posy=20)
......@@ -50,7 +54,6 @@ def keyboard_demo():
def mouse_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Mouse", posy=20)
......@@ -86,7 +89,6 @@ def mouse_demo():
def control_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Control", posy=20)
......@@ -111,26 +113,79 @@ def control_demo():
cc.send(ConsumerControlCode.PLAY_PAUSE)
disp = display.open()
disp.clear()
disp.print("card10 HID", posy=0)
disp.print(" Demo", posy=20)
disp.print("KBD", posy=60, fg=color.BLUE)
disp.print("Mouse", posy=40, posx=80, fg=color.RED)
disp.print("Control", posy=60, posx=60, fg=color.GREEN)
disp.update()
cc = ConsumerControl(ble_hid.devices)
b_old = buttons.read()
while True:
b_new = buttons.read()
if not b_old == b_new:
print(b_new)
b_old = b_new
if b_new == buttons.TOP_RIGHT:
mouse_demo()
elif b_new == buttons.BOTTOM_RIGHT:
control_demo()
elif b_new == buttons.BOTTOM_LEFT:
keyboard_demo()
def selection_screen():
disp.clear()
disp.print("card10 HID", posy=0)
disp.print(" Demo", posy=20)
disp.print("KBD", posy=60, fg=color.BLUE)
disp.print("Mouse", posy=40, posx=80, fg=color.RED)
disp.print("Control", posy=60, posx=60, fg=color.GREEN)
disp.update()
b_old = buttons.read()
while True:
b_new = buttons.read()
if not b_old == b_new:
print(b_new)
b_old = b_new
if b_new == buttons.TOP_RIGHT:
mouse_demo()
elif b_new == buttons.BOTTOM_RIGHT:
control_demo()
elif b_new == buttons.BOTTOM_LEFT:
keyboard_demo()
def set_config(enable):
if enable:
config.set_string("ble_hid_enable", "true")
else:
config.set_string("ble_hid_enable", "false")
disp.clear()
disp.print("resetting", posy=0, fg=[0, 255, 255])
disp.print("to toggle", posy=20, fg=[0, 255, 255])
disp.print("HID state", posy=40, fg=[0, 255, 255])
disp.update()
os.reset()
def welcome_screen(is_enabled):
disp.clear()
disp.print("card10 HID", posy=0)
disp.print(" Demo", posy=20)
if is_enabled:
disp.print("Start ->", posy=40, posx=40, fg=color.GREEN)
disp.print("<- Disable", posy=60, posx=0, fg=color.RED)
else:
disp.print("Enable ->", posy=40, posx=30, fg=color.GREEN)
disp.update()
b_old = buttons.read()
while True:
b_new = buttons.read()
if not b_old == b_new:
print(b_new)
b_old = b_new
if b_new == buttons.TOP_RIGHT:
if is_enabled:
# while buttons.read(): pass
selection_screen()
else:
set_config(True)
elif b_new == buttons.BOTTOM_LEFT:
if is_enabled:
set_config(False)
is_enabled = False
try:
enabled = config.get_string("ble_hid_enable")
if enabled.lower() == "true" or enabled == "1":
is_enabled = True
except OSError:
pass
welcome_screen(is_enabled)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment