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

Merge branch 'schneider/hid-demo-2' into 'master'

feat(hid-demo): Allow keeping buttons pressed

See merge request !438
parents acf4aa2e ed72e5f2
No related branches found
No related tags found
1 merge request!438feat(hid-demo): Allow keeping buttons pressed
Pipeline #5062 passed
......@@ -26,31 +26,40 @@ def keyboard_demo():
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.print("<-F13", posy=60, font=2, fg=color.BLUE)
disp.print("Backspace->", posy=40, font=2, posx=30, fg=color.RED)
disp.print("Type->", posy=60, posx=90, font=2, fg=color.GREEN)
disp.update()
k = Keyboard(ble_hid.devices)
kl = KeyboardLayoutUS(k)
backspace_pressed = False
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 b_new & buttons.TOP_RIGHT:
# print("back") # for debug in REPL
k.send(Keycode.BACKSPACE)
elif b_new == buttons.BOTTOM_RIGHT:
if not backspace_pressed:
k.press(Keycode.BACKSPACE)
backspace_pressed = True
else:
if backspace_pressed:
k.release(Keycode.BACKSPACE)
backspace_pressed = False
if 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:
if b_new & buttons.BOTTOM_LEFT:
# add shift modifier
k.send(Keycode.SHIFT, Keycode.F19)
# k.send(Keycode.SHIFT, Keycode.F13)
k.send(Keycode.F13)
def mouse_demo():
......@@ -72,20 +81,41 @@ def mouse_demo():
m.move(x, y)
def get_buttons():
b = buttons.read()
return (
b & buttons.BOTTOM_LEFT,
b & buttons.TOP_RIGHT,
b & buttons.BOTTOM_RIGHT,
)
sensor = bhi160.BHI160Orientation(sample_rate=10, callback=send_report)
b_old = buttons.read()
left_old, middle_old, right_old = get_buttons()
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)
left_new, middle_new, right_new = get_buttons()
if left_new != left_old:
if left_new:
m.press(Mouse.LEFT_BUTTON)
else:
m.release(Mouse.LEFT_BUTTON)
if middle_new != middle_old:
if middle_new:
m.press(Mouse.MIDDLE_BUTTON)
else:
m.release(Mouse.MIDDLE_BUTTON)
if right_new != right_old:
if right_new:
m.press(Mouse.RIGHT_BUTTON)
else:
m.release(Mouse.RIGHT_BUTTON)
left_old, middle_old, right_old = (left_new, middle_new, right_new)
def control_demo():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment