Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stechuhr-client
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pandemic_Response
stechuhr-client
Commits
72c924ac
Commit
72c924ac
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Make buzzer global
parent
6ce30265
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stechuhr_client/client.py
+11
-12
11 additions, 12 deletions
stechuhr_client/client.py
with
11 additions
and
12 deletions
stechuhr_client/client.py
+
11
−
12
View file @
72c924ac
...
@@ -107,6 +107,7 @@ LEDS = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
...
@@ -107,6 +107,7 @@ LEDS = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
buzzer_pin
=
18
buzzer_pin
=
18
GPIO
.
setup
(
buzzer_pin
,
GPIO
.
OUT
)
GPIO
.
setup
(
buzzer_pin
,
GPIO
.
OUT
)
BUZZER
=
GPIO
.
PWM
(
buzzer_pin
,
440
)
# Set frequency to 1 Khz
# from input-event-codes.h
# from input-event-codes.h
# type can be EV_SYN, EV_KEY or EV_MSC
# type can be EV_SYN, EV_KEY or EV_MSC
...
@@ -180,31 +181,29 @@ def dispatch_buzzer(state, config):
...
@@ -180,31 +181,29 @@ def dispatch_buzzer(state, config):
buzzer_thread
.
start
()
buzzer_thread
.
start
()
def
set_buzzer
(
state
,
config
):
def
set_buzzer
(
state
,
config
):
global
buzzer_pin
global
BUZZER
buzzer
=
GPIO
.
PWM
(
buzzer_pin
,
f
)
# Set frequency to 1 Khz
state
=
str
(
state
).
strip
().
lower
()
state
=
str
(
state
).
strip
().
lower
()
if
state
in
[
"
startup
"
,
"
ready
"
]:
if
state
in
[
"
startup
"
,
"
ready
"
]:
buzzer
=
GPIO
.
PWM
(
buzzer_pin
,
f
)
# Set frequency to 1 Khz
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
startup_notes
"
]):
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
startup_notes
"
]):
buzzer
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
BUZZER
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
BUZZER
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
startup_note_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
startup_note_lengths
"
],
i
))
buzzer
.
stop
()
BUZZER
.
stop
()
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
startup_note_stop_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
startup_note_stop_lengths
"
],
i
))
elif
state
in
[
"
success
"
]:
elif
state
in
[
"
success
"
]:
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
success_notes
"
]):
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
success_notes
"
]):
buzzer
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
BUZZER
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
BUZZER
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
success_note_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
success_note_lengths
"
],
i
))
buzzer
.
stop
()
BUZZER
.
stop
()
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
success_note_stop_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
success_note_stop_lengths
"
],
i
))
elif
state
in
[
"
failure
"
]:
elif
state
in
[
"
failure
"
]:
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
failure_notes
"
]):
for
i
,
note
in
enumerate
(
config
[
"
buzzer
"
][
"
failure_notes
"
]):
buzzer
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
BUZZER
.
ChangeFrequency
(
midinumber_to_hertz
(
note
))
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
BUZZER
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
failure_note_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
failure_note_lengths
"
],
i
))
buzzer
.
stop
()
BUZZER
.
stop
()
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
failure_note_stop_lengths
"
],
i
))
time
.
sleep
(
repeat
(
config
[
"
buzzer
"
][
"
failure_note_stop_lengths
"
],
i
))
...
...
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