Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Merge requests
!438
feat(hid-demo): Allow keeping buttons pressed
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat(hid-demo): Allow keeping buttons pressed
schneider/hid-demo-2
into
master
Overview
2
Commits
1
Pipelines
1
Changes
1
Merged
schneider
requested to merge
schneider/hid-demo-2
into
master
4 years ago
Overview
2
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
ed72e5f2
1 commit,
4 years ago
1 file
+
49
−
19
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
preload/apps/hid/__init__.py
+
49
−
19
Options
@@ -26,31 +26,40 @@ def keyboard_demo():
disp
.
clear
()
disp
.
print
(
"
card10
"
,
posy
=
0
)
disp
.
print
(
"
Keyboard
"
,
posy
=
20
)
disp
.
print
(
"
F1
9
"
,
posy
=
60
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
Backspace
"
,
posy
=
40
,
posx
=
2
0
,
fg
=
color
.
RED
)
disp
.
print
(
"
Type
"
,
posy
=
60
,
posx
=
100
,
fg
=
color
.
GREEN
)
disp
.
print
(
"
<-
F1
3
"
,
posy
=
60
,
font
=
2
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
Backspace
->
"
,
posy
=
40
,
font
=
2
,
posx
=
3
0
,
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!
"
)
el
if
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
():
Loading