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

feat(hid): Improve demo app

parent 44951ee7
No related branches found
No related tags found
1 merge request!382HID over BLE
Pipeline #5012 passed
...@@ -2,17 +2,122 @@ import buttons ...@@ -2,17 +2,122 @@ import buttons
import color import color
import display import display
import ble_hid import ble_hid
import bhi160
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse
from adafruit_hid.consumer_control_code import ConsumerControlCode from adafruit_hid.consumer_control_code import ConsumerControlCode
from adafruit_hid.consumer_control import ConsumerControl from adafruit_hid.consumer_control import ConsumerControl
import time
def keyboard_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Keyboard", posy=20)
disp.print("F19", posy=60, fg=color.BLUE)
disp.print("Backspace", posy=40, posx=20, fg=color.RED)
disp.print("Type", posy=60, posx=100, fg=color.GREEN)
disp.update()
k = Keyboard(ble_hid.devices)
kl = KeyboardLayoutUS(k)
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:
# print("back") # for debug in REPL
k.send(Keycode.BACKSPACE)
elif b_new == buttons.BOTTOM_RIGHT:
# use keyboard_layout for words
kl.write("Demo with a long text to show how fast a card10 can type!")
elif b_new == buttons.BOTTOM_LEFT:
# add shift modifier
k.send(Keycode.SHIFT, Keycode.F19)
def mouse_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Mouse", posy=20)
disp.print("Left", posy=60, fg=color.BLUE)
disp.print("Midd", posy=40, posx=100, fg=color.RED)
disp.print("Right", posy=60, posx=80, fg=color.GREEN)
disp.update()
m = Mouse(ble_hid.devices)
def send_report(samples):
if len(samples) > 0:
x = -int(samples[0].z)
y = -int(samples[0].y)
print("Reporting", x, y)
m.move(x, y)
sensor = bhi160.BHI160Orientation(sample_rate=10, callback=send_report)
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:
m.click(Mouse.MIDDLE_BUTTON)
elif b_new == buttons.BOTTOM_RIGHT:
m.click(Mouse.RIGHT_BUTTON)
elif b_new == buttons.BOTTOM_LEFT:
m.click(Mouse.LEFT_BUTTON)
def control_demo():
disp = display.open()
disp.clear()
disp.print(" card10", posy=0)
disp.print(" Control", posy=20)
disp.print("Play", posy=60, fg=color.BLUE)
disp.print("Vol+", posy=40, posx=100, fg=color.RED)
disp.print("Vol-", posy=60, posx=100, 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:
cc.send(ConsumerControlCode.VOLUME_INCREMENT)
elif b_new == buttons.BOTTOM_RIGHT:
cc.send(ConsumerControlCode.VOLUME_DECREMENT)
elif b_new == buttons.BOTTOM_LEFT:
cc.send(ConsumerControlCode.PLAY_PAUSE)
disp = display.open() disp = display.open()
disp.clear() disp.clear()
disp.print(" card10", posy=0) disp.print("card10 HID", posy=0)
disp.print(" Remote", posy=20) disp.print(" Demo", posy=20)
disp.print("Play", posy=60, fg=color.BLUE) disp.print("KBD", posy=60, fg=color.BLUE)
disp.print("Vol+", posy=40, posx=100, fg=color.RED) disp.print("Mouse", posy=40, posx=80, fg=color.RED)
disp.print("Vol-", posy=60, posx=100, fg=color.GREEN) disp.print("Control", posy=60, posx=60, fg=color.GREEN)
disp.update() disp.update()
cc = ConsumerControl(ble_hid.devices) cc = ConsumerControl(ble_hid.devices)
...@@ -24,8 +129,8 @@ while True: ...@@ -24,8 +129,8 @@ while True:
print(b_new) print(b_new)
b_old = b_new b_old = b_new
if b_new == buttons.TOP_RIGHT: if b_new == buttons.TOP_RIGHT:
cc.send(ConsumerControlCode.VOLUME_INCREMENT) mouse_demo()
elif b_new == buttons.BOTTOM_RIGHT: elif b_new == buttons.BOTTOM_RIGHT:
cc.send(ConsumerControlCode.VOLUME_DECREMENT) control_demo()
elif b_new == buttons.BOTTOM_LEFT: elif b_new == buttons.BOTTOM_LEFT:
cc.send(ConsumerControlCode.PLAY_PAUSE) keyboard_demo()
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