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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andy B-S
firmware
Commits
26c92b15
Commit
26c92b15
authored
5 years ago
by
Adimote
Browse files
Options
Downloads
Patches
Plain Diff
fix linting errors
parent
e803d28b
No related branches found
No related tags found
No related merge requests found
Pipeline
#3509
failed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/apps/joust/__init__.py
+32
-14
32 additions, 14 deletions
preload/apps/joust/__init__.py
with
32 additions
and
14 deletions
preload/apps/joust/__init__.py
+
32
−
14
View file @
26c92b15
...
...
@@ -16,13 +16,17 @@ COLOR_ORANGE=(255,125,0)
COLOR_WHITE
=
(
255
,
255
,
255
)
ACCELEROMETER
=
bhi160
.
BHI160Accelerometer
()
class
JoustSensor
:
NUM_READINGS
=
1
def
__init__
(
self
):
self
.
sensor
=
ACCELEROMETER
self
.
last_accels
=
[]
self
.
jerk
=
0.0
self
.
threshold
=
1.8
def
get_jerk
(
self
):
readings
=
list
()
while
not
readings
:
...
...
@@ -35,9 +39,11 @@ class JoustSensor:
jerk_z
=
sum
([
a
.
z
for
a
in
self
.
last_accels
])
/
JoustSensor
.
NUM_READINGS
self
.
jerk
=
(
jerk_x
**
2
+
jerk_y
**
2
+
jerk_z
**
2
)
**
0.5
return
self
.
jerk
def
too_fast
(
self
):
return
self
.
get_jerk
()
>
self
.
threshold
def
wait_button
():
utime
.
sleep_ms
(
1000
)
while
True
:
...
...
@@ -56,45 +62,56 @@ def wait_button():
return
"
UL
"
return
"
??
"
def
joining_game
():
set_display
(
"
JOIN ?
"
,
COLOR_WHITE
)
set_color
(
COLOR_WHITE
)
def
status_in_game
():
set_display
(
"
IN GAME
"
,
COLOR_GREEN
)
set_color
(
COLOR_GREEN
)
def
status_out_game
():
set_display
(
"
DROPPED
"
,
COLOR_RED
)
set_color
(
COLOR_RED
)
def
set_display
(
text
,
colr
):
with
display
.
open
()
as
disp
:
disp
.
clear
()
disp
.
print
(
text
,
fg
=
colr
,
bg
=
(
0
,
0
,
0
),
posx
=
30
,
posy
=
30
)
disp
.
update
()
def
set_color
(
colr
):
for
i
in
range
(
15
):
leds
.
prep
(
i
,
colr
)
leds
.
update
()
def
countdown
(
n
):
colr
=
COLOR_WHITE
for
i
in
range
(
n
,
0
,
-
1
):
if
i
==
3
:
colr
=
COLOR_RED
elif
i
==
2
:
colr
=
COLOR_ORANGE
elif
i
==
1
:
colr
=
COLOR_GREEN
if
i
==
3
:
colr
=
COLOR_RED
elif
i
==
2
:
colr
=
COLOR_ORANGE
elif
i
==
1
:
colr
=
COLOR_GREEN
set_display
(
"
START: %d
"
%
i
,
colr
)
leds
.
clear
()
vibra
.
vibrate
(
300
)
utime
.
sleep_ms
(
1000
)
vibra
.
vibrate
(
1000
)
def
change_status
(
status
):
status
()
vibra
.
vibrate
(
1000
)
def
run
():
print
(
"
Starting ...
"
)
acc
=
JoustSensor
()
...
...
@@ -113,4 +130,5 @@ def run():
elif
current_status
==
status_out_game
:
wait_button
()
run
()
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