Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tv_panel
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hermod
tv_panel
Commits
fff03801
Commit
fff03801
authored
7 years ago
by
Hermod
Browse files
Options
Downloads
Patches
Plain Diff
[Badge] Fix: statusRGB_listener was taking 100% CPU after first time
parent
fca1be81
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/statusRGB_listener.py
+36
-29
36 additions, 29 deletions
scripts/statusRGB_listener.py
with
36 additions
and
29 deletions
scripts/statusRGB_listener.py
+
36
−
29
View file @
fff03801
...
...
@@ -4,8 +4,7 @@
import
os
import
sys
import
time
import
argparse
import
select
import
subprocess
from
neopixel
import
Adafruit_NeoPixel
,
ws
...
...
@@ -29,6 +28,7 @@ LED_INVERT = False # True to invert the signal (when using NPN transistor
LED_CHANNEL
=
0
# set to '1' for GPIOs 13, 19, 41, 45 or 53
LED_STRIP
=
ws
.
WS2811_STRIP_GRB
# Strip type and colour ordering
# Pipe where the code listen for color commands
PIPE_PATH
=
'
/dev/rgb_pipe
'
...
...
@@ -44,25 +44,12 @@ def sanitize_color(s):
return
r
,
g
,
b
if
__name__
==
'
__main__
'
:
if
not
os
.
path
.
exists
(
PIPE_PATH
):
os
.
mkfifo
(
PIPE_PATH
)
os
.
system
(
'
chmod 666
'
+
PIPE_PATH
)
# Acces r+w for non-root users
# Create NeoPixel object with appropriate configuration.
strip
=
Adafruit_NeoPixel
(
LED_COUNT
,
LED_PIN
,
LED_FREQ_HZ
,
LED_DMA
,
LED_INVERT
,
LED_BRIGHTNESS
,
LED_CHANNEL
,
LED_STRIP
)
# Intialize the library (must be called once before other functions).
strip
.
begin
()
with
open
(
PIPE_PATH
,
'
r
'
)
as
fifo
:
while
True
:
select
.
select
([
fifo
],[],[
fifo
])
data0
=
fifo
.
read
().
strip
()
def
command_string_to_display
(
cs
,
strip
):
"""
Display the color based on the
'
color time
'
string
"""
data
=
data0
.
split
(
'
'
)
colors
=
sanitize_color
(
data
[
0
])
if
colors
is
None
:
continue
return
1
r
,
g
,
b
=
colors
try
:
t
=
float
(
data
[
1
])
...
...
@@ -75,6 +62,26 @@ if __name__ == '__main__':
time
.
sleep
(
t
)
strip
.
setPixelColorRGB
(
0
,
0
,
0
,
0
)
strip
.
show
()
return
0
strip
.
setPixelColorRGB
(
0
,
0
,
0
,
0
)
strip
.
show
()
if
__name__
==
'
__main__
'
:
if
os
.
path
.
exists
(
PIPE_PATH
):
os
.
remove
(
PIPE_PATH
)
os
.
mkfifo
(
PIPE_PATH
)
os
.
system
(
'
chown root:hermod {0} && chmod g+rw {0}
'
.
format
(
PIPE_PATH
))
# rw access for hermod group
# Create NeoPixel object with appropriate configuration.
strip
=
Adafruit_NeoPixel
(
LED_COUNT
,
LED_PIN
,
LED_FREQ_HZ
,
LED_DMA
,
LED_INVERT
,
LED_BRIGHTNESS
,
LED_CHANNEL
,
LED_STRIP
)
# Intialize the library (must be called once before other functions).
strip
.
begin
()
# Listen to the pipe and display colors
while
True
:
data0
=
subprocess
.
check_output
([
'
cat
'
,
PIPE_PATH
]).
decode
(
'
utf-8
'
)
command_string_to_display
(
data0
,
strip
)
command_string_to_display
(
'
000000
'
,
strip
)
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