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
External 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
fleur
firmware
Commits
50839184
Commit
50839184
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Plain Diff
Merge 'Refactor BHI160 App'
See merge request
card10/firmware!316
parents
d974cd2f
003aa2a0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/apps/bhi160/__init__.py
+39
-37
39 additions, 37 deletions
preload/apps/bhi160/__init__.py
with
39 additions
and
37 deletions
preload/apps/bhi160/__init__.py
+
39
−
37
View file @
50839184
import
bhi160
import
display
import
utime
import
buttons
disp
=
display
.
open
()
sensor
=
0
sensors
=
[
{
"
sensor
"
:
bhi160
.
BHI160Orientation
(),
"
name
"
:
"
Orientation
"
},
{
"
sensor
"
:
bhi160
.
BHI160Accelerometer
(),
"
name
"
:
"
Accelerometer
"
},
{
"
sensor
"
:
bhi160
.
BHI160Gyroscope
(),
"
name
"
:
"
Gyroscope
"
},
{
"
sensor
"
:
bhi160
.
BHI160Magnetometer
(),
"
name
"
:
"
Magnetometer
"
},
import
color
import
contextlib
import
display
import
itertools
import
simple_menu
STATUS_COLORS
=
[
color
.
RED
,
# Orange
color
.
RED
*
0.5
+
color
.
YELLOW
*
0.5
,
color
.
YELLOW
,
color
.
GREEN
,
]
while
True
:
# Read and print sample
samples
=
sensors
[
sensor
][
"
sensor
"
].
read
()
if
len
(
samples
)
>
0
:
disp
.
clear
()
sample
=
samples
[
0
]
with
contextlib
.
ExitStack
()
as
cx
:
disp
=
cx
.
enter_context
(
display
.
open
())
color
=
[
255
,
0
,
0
]
if
sample
.
status
==
1
:
color
=
[
255
,
128
,
0
]
elif
sample
.
status
==
2
:
color
=
[
255
,
255
,
0
]
elif
sample
.
status
==
3
:
color
=
[
0
,
200
,
0
]
args
=
{
"
sample_rate
"
:
10
,
"
sample_buffer_len
"
:
20
}
disp
.
print
(
sensors
[
sensor
][
"
name
"
],
posy
=
0
)
disp
.
print
(
"
X: %f
"
%
sample
.
x
,
posy
=
20
,
fg
=
color
)
disp
.
print
(
"
Y: %f
"
%
sample
.
y
,
posy
=
40
,
fg
=
color
)
disp
.
print
(
"
Z: %f
"
%
sample
.
z
,
posy
=
60
,
fg
=
color
)
sensor_iter
=
itertools
.
cycle
(
[
(
cx
.
enter_context
(
bhi160
.
BHI160Orientation
(
**
args
)),
"
Orientation
"
),
(
cx
.
enter_context
(
bhi160
.
BHI160Accelerometer
(
**
args
)),
"
Accel
"
),
(
cx
.
enter_context
(
bhi160
.
BHI160Gyroscope
(
**
args
)),
"
Gyro
"
),
(
cx
.
enter_context
(
bhi160
.
BHI160Magnetometer
(
**
args
)),
"
Magnetic
"
),
]
)
sensor
,
sensor_name
=
next
(
sensor_iter
)
disp
.
update
()
for
ev
in
simple_menu
.
button_events
(
timeout
=
0.1
):
# Pressing the bottom right button cycles through sensors
if
ev
==
buttons
.
BOTTOM_RIGHT
:
sensor
,
sensor_name
=
next
(
sensor_iter
)
# Read button
v
=
buttons
.
read
(
buttons
.
BOTTOM_RIGHT
)
if
v
==
0
:
button_pressed
=
False
samples
=
sensor
.
read
()
if
not
samples
:
continue
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_RIGHT
!=
0
:
button_pressed
=
True
sensor
=
(
sensor
+
1
)
%
len
(
sensors
)
sample
=
samples
[
-
1
]
col
=
STATUS_COLORS
[
sample
.
status
]
utime
.
sleep
(
0.1
)
disp
.
clear
()
disp
.
print
(
"
{:^11s}
"
.
format
(
sensor_name
),
posy
=
0
,
posx
=
3
)
disp
.
print
(
"
X:{: 9.4f}
"
.
format
(
sample
.
x
),
posy
=
20
,
fg
=
col
)
disp
.
print
(
"
Y:{: 9.4f}
"
.
format
(
sample
.
y
),
posy
=
40
,
fg
=
col
)
disp
.
print
(
"
Z:{: 9.4f}
"
.
format
(
sample
.
z
),
posy
=
60
,
fg
=
col
)
disp
.
update
()
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