Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
T
test-project-please-ignore
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Progetti
test-project-please-ignore
Commits
36b53bde
Commit
36b53bde
authored
Oct 21, 2018
by
Aljaž Srebrnič
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved lightning stuff to separate thread, added some objects
parent
307cc753
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
35 deletions
+51
-35
lighting.py
lighting.py
+51
-35
No files found.
lighting.py
View file @
36b53bde
...
@@ -3,48 +3,62 @@
...
@@ -3,48 +3,62 @@
from
time
import
sleep
from
time
import
sleep
from
random
import
randint
from
random
import
randint
import
configparser
import
configparser
from
threading
import
Thread
import
zmq
import
zmq
import
spidev
import
spidev
import
ws2812
import
ws2812
activeFlag
=
True
c
=
0
rand
=
1
r
=
255
def
get_color
():
if
activeFlag
==
True
:
global
c
global
r
global
rand
if
c
+
rand
>
80
:
rand
=
randint
(
1
,
8
)
*
(
-
1
)
return
(
80
,
255
,
0
)
elif
c
+
rand
<
0
:
rand
=
randint
(
1
,
8
)
return
(
0
,
255
,
0
)
else
:
c
=
c
+
rand
return
(
c
,
255
,
0
)
else
:
fade
()
class
Color
:
green
:
int
red
:
int
blue
:
int
def
as_tuple
(
self
):
return
self
.
green
,
self
.
red
,
self
.
blue
def
light_flame
():
class
ColorManager
(
Thread
):
current_rand
=
1
current_color
=
Color
(
0
,
0
,
0
)
activeFlag
=
True
spi
=
spidev
.
SpiDev
()
spi
=
spidev
.
SpiDev
()
spi
.
open
(
1
,
0
)
while
True
:
def
__init__
(
self
)
:
ws2812
.
write2812
(
spi
,
[
get_color
()
*
4
]
)
super
().
__init__
(
)
s
leep
(
0.001
)
s
elf
.
spi
.
open
(
1
,
0
)
def
fade
():
def
get_color
(
self
):
if
r
>
0
:
if
self
.
current_color
.
green
+
self
.
current_rand
>
80
:
r
--
self
.
current_rand
=
-
randint
(
1
,
8
)
if
c
>
0
:
self
.
current_color
=
Color
(
80
,
255
,
0
)
c
--
elif
self
.
current_colorgreen
+
self
.
current_rand
<
0
:
return
(
c
,
r
,
0
)
rand
=
randint
(
1
,
8
)
self
.
current_color
=
Color
(
0
,
255
,
0
)
else
:
self
.
current_color
.
green
+=
rand
self
.
current_color
.
red
=
255
self
.
current_color
.
blue
=
0
def
fade
(
self
):
if
self
.
current_color
.
red
>
0
:
self
.
current_color
.
red
-=
1
if
self
.
current_color
.
green
>
0
:
self
.
current_color
.
green
-=
1
def
start_fade
(
self
):
self
.
activeFlag
=
False
def
run
(
self
):
while
self
.
is_alive
():
if
self
.
activeFlag
:
self
.
get_color
()
else
:
self
.
fade
()
ws2812
.
write2812
(
self
.
spi
,
[
self
.
current_color
.
as_tuple
()
*
4
])
sleep
(
0.001
)
def
main
():
def
main
():
...
@@ -64,18 +78,20 @@ def main():
...
@@ -64,18 +78,20 @@ def main():
topicfilter
=
"events"
topicfilter
=
"events"
socket
.
setsockopt_string
(
zmq
.
SUBSCRIBE
,
topicfilter
)
socket
.
setsockopt_string
(
zmq
.
SUBSCRIBE
,
topicfilter
)
cm
=
ColorManager
()
while
True
:
while
True
:
string
=
socket
.
recv
()
string
=
socket
.
recv
()
topic
,
messagedata
=
string
.
split
()
topic
,
messagedata
=
string
.
split
()
print
(
topic
,
messagedata
)
print
(
topic
,
messagedata
)
if
messagedata
==
b
"liftoff"
:
if
messagedata
==
b
"liftoff"
:
light_flame
()
cm
=
ColorManager
()
cm
.
start
()
elif
messagedata
==
b
"stage_1_separation"
:
elif
messagedata
==
b
"stage_1_separation"
:
light_flame
()
pass
elif
messagedata
==
b
"stage_2_separation"
:
elif
messagedata
==
b
"stage_2_separation"
:
light_flame
()
cm
.
start_fade
()
activeFlag
=
False
else
:
else
:
print
(
"Unhandled message"
)
print
(
"Unhandled message"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment