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
1db3a131
Commit
1db3a131
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(hid): Improve demo app
parent
44951ee7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!382
HID over BLE
Pipeline
#5012
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.py
+113
-8
113 additions, 8 deletions
preload/apps/hid.py
with
113 additions
and
8 deletions
preload/apps/hid.py
+
113
−
8
View file @
1db3a131
...
@@ -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
(
"
R
emo
te
"
,
posy
=
20
)
disp
.
print
(
"
D
emo
"
,
posy
=
20
)
disp
.
print
(
"
Play
"
,
posy
=
60
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
KBD
"
,
posy
=
60
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
Vol+
"
,
posy
=
40
,
posx
=
10
0
,
fg
=
color
.
RED
)
disp
.
print
(
"
Mouse
"
,
posy
=
40
,
posx
=
8
0
,
fg
=
color
.
RED
)
disp
.
print
(
"
V
ol
-
"
,
posy
=
60
,
posx
=
10
0
,
fg
=
color
.
GREEN
)
disp
.
print
(
"
Contr
ol
"
,
posy
=
60
,
posx
=
6
0
,
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
:
c
c
.
send
(
ConsumerControlCode
.
VOLUME_DECREMENT
)
c
ontrol_demo
(
)
elif
b_new
==
buttons
.
BOTTOM_LEFT
:
elif
b_new
==
buttons
.
BOTTOM_LEFT
:
cc
.
send
(
ConsumerControlCode
.
PLAY_PAUSE
)
keyboard_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