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
dbfbd539
Commit
dbfbd539
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Add states
parent
f2e656ba
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
+54
-11
54 additions, 11 deletions
stechuhr_client/client.py
with
54 additions
and
11 deletions
stechuhr_client/client.py
+
54
−
11
View file @
dbfbd539
...
...
@@ -75,6 +75,10 @@ success_off_time = "[0.05]"
success_on_time =
"
[0.05]
"
[buzzer]
active = true
[server]
address =
"
127.0.0.1
"
port = 80
...
...
@@ -112,6 +116,7 @@ def dispatch_led(ledstate, config):
Dispatch a LED thread with a given LED state
"""
led_thread
=
threading
.
Thread
(
target
=
set_led
,
args
=
(
ledstate
,
config
,
))
led_thread
.
daemon
=
True
led_thread
.
start
()
def
set_led
(
ledstate
,
config
):
...
...
@@ -149,23 +154,58 @@ def dispatch_buzzer(state, config):
"""
Dispatch a Buzzer thread with a given Buzzer state
"""
# If the buzzer is not active, return before starting a thread
if
not
config
[
"
buzzer
"
][
"
active
"
]:
return
# Start a daemonized buzzer thread
buzzer_thread
=
threading
.
Thread
(
target
=
set_buzzer
,
args
=
(
state
,
config
,
))
buzzer_thread
.
daemon
=
True
buzzer_thread
.
start
()
def
set_buzzer
(
state
,
config
):
global
buzzer_pin
f
=
220
state
=
str
(
state
).
strip
().
lower
()
if
state
in
[
"
startup
"
,
"
ready
"
]:
f
=
1000
buzzer
=
GPIO
.
PWM
(
buzzer_pin
,
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.1
)
buzzer
.
stop
()
time
.
sleep
(
0.1
)
for
i
in
[
1
,
3
,
1
,
2
,
3
,
4
,
5
,
6
,
1
]:
buzzer
.
ChangeFrequency
((
1
+
i
)
*
0.083333333
*
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.1
)
buzzer
.
stop
()
time
.
sleep
(
0.1
)
elif
state
in
[
"
success
"
]:
f
=
1000
buzzer
=
GPIO
.
PWM
(
buzzer_pin
,
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
1
)
buzzer
.
stop
()
time
.
sleep
(
0.
5
)
for
i
in
range
(
1
,
1
0
)
:
buzzer
.
ChangeFrequency
(
i
*
f
)
# Set frequency to 1 Khz
time
.
sleep
(
0.
1
)
for
i
in
[
12
,
1
]
:
buzzer
.
ChangeFrequency
(
(
1
+
i
)
*
0.083333333
*
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
1
)
buzzer
.
stop
()
time
.
sleep
(
0.5
)
time
.
sleep
(
0.1
)
elif
state
in
[
"
failure
"
]:
f
=
1000
buzzer
=
GPIO
.
PWM
(
buzzer_pin
,
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.1
)
buzzer
.
stop
()
time
.
sleep
(
0.1
)
for
i
in
[
5
,
3
,
2
]:
buzzer
.
ChangeFrequency
((
1
+
i
)
*
0.083333333
*
f
)
# Set frequency to 1 Khz
buzzer
.
start
(
50
)
# Set dutycycle to 10
time
.
sleep
(
0.1
)
buzzer
.
stop
()
time
.
sleep
(
0.1
)
def
process_request
(
output_queue
,
config
=
None
,
logger
=
None
):
...
...
@@ -182,9 +222,11 @@ def process_request(output_queue, config=None, logger=None):
if
success
:
logger
.
info
(
"
Server Response: Success
"
)
dispatch_led
(
"
success
"
,
config
)
dispatch_buzzer
(
"
success
"
,
config
)
else
:
logger
.
info
(
"
Server Response: Failed
"
)
dispatch_led
(
"
failure
"
,
config
)
dispatch_buzzer
(
"
failure
"
,
config
)
else
:
time
.
sleep
(
0.01
)
...
...
@@ -356,8 +398,8 @@ def main():
outputThread
=
threading
.
Thread
(
target
=
process_request
,
args
=
(
output_queue
,
config
,
logger
),
daemon
=
True
)
outputThread
.
start
()
# Dispatch a startup sound to signal readyness
dispatch_buzzer
(
"
startup
"
,
config
)
exit
()
# Set the LED to display readyness
dispatch_led
(
"
startup
"
,
config
)
...
...
@@ -374,6 +416,7 @@ def main():
else
:
logger
.
warning
(
"
Didn
'
t register as a valid ID: {}
"
.
format
(
potential_id
[:
1024
]))
dispatch_led
(
"
failure
"
,
config
)
dispatch_buzzer
(
"
failure
"
,
config
)
else
:
time
.
sleep
(
0.01
)
...
...
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