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
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
François Revol
firmware
Commits
bd31fa5c
Commit
bd31fa5c
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(hid): Improve demo app
parent
0a5c478b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/apps/hid/__init__.py
+81
-26
81 additions, 26 deletions
preload/apps/hid/__init__.py
with
81 additions
and
26 deletions
preload/apps/hid/__init__.py
+
81
−
26
View file @
bd31fa5c
...
...
@@ -3,6 +3,7 @@ import color
import
display
import
ble_hid
import
bhi160
import
config
from
adafruit_hid.keyboard
import
Keyboard
from
adafruit_hid.keyboard_layout_us
import
KeyboardLayoutUS
...
...
@@ -15,10 +16,13 @@ from adafruit_hid.consumer_control import ConsumerControl
import
time
import
os
disp
=
display
.
open
()
def
keyboard_demo
():
disp
=
display
.
open
()
disp
.
clear
()
disp
.
print
(
"
card10
"
,
posy
=
0
)
disp
.
print
(
"
Keyboard
"
,
posy
=
20
)
...
...
@@ -50,7 +54,6 @@ def keyboard_demo():
def
mouse_demo
():
disp
=
display
.
open
()
disp
.
clear
()
disp
.
print
(
"
card10
"
,
posy
=
0
)
disp
.
print
(
"
Mouse
"
,
posy
=
20
)
...
...
@@ -86,7 +89,6 @@ def mouse_demo():
def
control_demo
():
disp
=
display
.
open
()
disp
.
clear
()
disp
.
print
(
"
card10
"
,
posy
=
0
)
disp
.
print
(
"
Control
"
,
posy
=
20
)
...
...
@@ -111,26 +113,79 @@ def control_demo():
cc
.
send
(
ConsumerControlCode
.
PLAY_PAUSE
)
disp
=
display
.
open
()
disp
.
clear
()
disp
.
print
(
"
card10 HID
"
,
posy
=
0
)
disp
.
print
(
"
Demo
"
,
posy
=
20
)
disp
.
print
(
"
KBD
"
,
posy
=
60
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
Mouse
"
,
posy
=
40
,
posx
=
80
,
fg
=
color
.
RED
)
disp
.
print
(
"
Control
"
,
posy
=
60
,
posx
=
60
,
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
:
mouse_demo
()
elif
b_new
==
buttons
.
BOTTOM_RIGHT
:
control_demo
()
elif
b_new
==
buttons
.
BOTTOM_LEFT
:
keyboard_demo
()
def
selection_screen
():
disp
.
clear
()
disp
.
print
(
"
card10 HID
"
,
posy
=
0
)
disp
.
print
(
"
Demo
"
,
posy
=
20
)
disp
.
print
(
"
KBD
"
,
posy
=
60
,
fg
=
color
.
BLUE
)
disp
.
print
(
"
Mouse
"
,
posy
=
40
,
posx
=
80
,
fg
=
color
.
RED
)
disp
.
print
(
"
Control
"
,
posy
=
60
,
posx
=
60
,
fg
=
color
.
GREEN
)
disp
.
update
()
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
:
mouse_demo
()
elif
b_new
==
buttons
.
BOTTOM_RIGHT
:
control_demo
()
elif
b_new
==
buttons
.
BOTTOM_LEFT
:
keyboard_demo
()
def
set_config
(
enable
):
if
enable
:
config
.
set_string
(
"
ble_hid_enable
"
,
"
true
"
)
else
:
config
.
set_string
(
"
ble_hid_enable
"
,
"
false
"
)
disp
.
clear
()
disp
.
print
(
"
resetting
"
,
posy
=
0
,
fg
=
[
0
,
255
,
255
])
disp
.
print
(
"
to toggle
"
,
posy
=
20
,
fg
=
[
0
,
255
,
255
])
disp
.
print
(
"
HID state
"
,
posy
=
40
,
fg
=
[
0
,
255
,
255
])
disp
.
update
()
os
.
reset
()
def
welcome_screen
(
is_enabled
):
disp
.
clear
()
disp
.
print
(
"
card10 HID
"
,
posy
=
0
)
disp
.
print
(
"
Demo
"
,
posy
=
20
)
if
is_enabled
:
disp
.
print
(
"
Start ->
"
,
posy
=
40
,
posx
=
40
,
fg
=
color
.
GREEN
)
disp
.
print
(
"
<- Disable
"
,
posy
=
60
,
posx
=
0
,
fg
=
color
.
RED
)
else
:
disp
.
print
(
"
Enable ->
"
,
posy
=
40
,
posx
=
30
,
fg
=
color
.
GREEN
)
disp
.
update
()
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
is_enabled
:
# while buttons.read(): pass
selection_screen
()
else
:
set_config
(
True
)
elif
b_new
==
buttons
.
BOTTOM_LEFT
:
if
is_enabled
:
set_config
(
False
)
is_enabled
=
False
try
:
enabled
=
config
.
get_string
(
"
ble_hid_enable
"
)
if
enabled
.
lower
()
==
"
true
"
or
enabled
==
"
1
"
:
is_enabled
=
True
except
OSError
:
pass
welcome_screen
(
is_enabled
)
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