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
Commits
ed72e5f2
Commit
ed72e5f2
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(hid-demo): Allow keeping buttons pressed
parent
acf4aa2e
No related branches found
No related tags found
1 merge request
!438
feat(hid-demo): Allow keeping buttons pressed
Pipeline
#5061
passed
4 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/apps/hid/__init__.py
+49
-19
49 additions, 19 deletions
preload/apps/hid/__init__.py
with
49 additions
and
19 deletions
preload/apps/hid/__init__.py
+
49
−
19
View file @
ed72e5f2
...
...
@@ -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
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment