Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uni_ete_hepialight_mqtt
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jonas.stirnema
uni_ete_hepialight_mqtt
Commits
08b22fcf
Commit
08b22fcf
authored
1 year ago
by
nicolas.albanesi
Browse files
Options
Downloads
Patches
Plain Diff
modified the discovery method
parent
52749dbb
No related branches found
No related tags found
1 merge request
!1
merge Nico
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hepialight/main.py
+17
-4
17 additions, 4 deletions
hepialight/main.py
with
17 additions
and
4 deletions
hepialight/main.py
+
17
−
4
View file @
08b22fcf
id
=
[
0
,
0
]
id
=
[
0
,
0
]
matsize
=
[
0
,
0
]
matsize
=
[
0
,
0
]
# Display and images functions
def
color16_to_32
(
color
):
def
color16_to_32
(
color
):
color
=
int
(
color
)
color
=
int
(
color
)
r
=
((
color
>>
11
)
&
0x1F
)
*
2
**
3
r
=
((
color
>>
11
)
&
0x1F
)
*
2
**
3
...
@@ -27,6 +29,7 @@ def display_id():
...
@@ -27,6 +29,7 @@ def display_id():
def
msg_to_str
(
msg
):
def
msg_to_str
(
msg
):
return
str
(
msg
)[
2
:
-
1
]
return
str
(
msg
)[
2
:
-
1
]
# Used by the send_xy functions
def
send_passthrough_str
(
msg
,
x
,
y
):
def
send_passthrough_str
(
msg
,
x
,
y
):
x
=
int
(
x
)
x
=
int
(
x
)
y
=
int
(
y
)
y
=
int
(
y
)
...
@@ -42,6 +45,7 @@ def send_passthrough_str(msg, x, y):
...
@@ -42,6 +45,7 @@ def send_passthrough_str(msg, x, y):
envoyer_msg
(
d
,
"
PT;{},{};{}
"
.
format
(
x
,
y
,
msg
))
envoyer_msg
(
d
,
"
PT;{},{};{}
"
.
format
(
x
,
y
,
msg
))
# Not meant to be used by the user
def
send_passthrough_bytes
(
msg
,
x
,
y
):
def
send_passthrough_bytes
(
msg
,
x
,
y
):
x
=
int
(
x
)
x
=
int
(
x
)
y
=
int
(
y
)
y
=
int
(
y
)
...
@@ -57,6 +61,7 @@ def send_passthrough_bytes(msg, x, y):
...
@@ -57,6 +61,7 @@ def send_passthrough_bytes(msg, x, y):
envoyer_msg
(
d
,
msg
)
envoyer_msg
(
d
,
msg
)
# Send commands to a specific matrix
def
send_xy
(
x
,
y
,
msg
):
def
send_xy
(
x
,
y
,
msg
):
send_passthrough_str
(
msg
,
x
,
y
)
send_passthrough_str
(
msg
,
x
,
y
)
...
@@ -67,6 +72,7 @@ def send_moving_xy(x, y, text, color=ROUGE, speed=0.1):
...
@@ -67,6 +72,7 @@ def send_moving_xy(x, y, text, color=ROUGE, speed=0.1):
send_xy
(
x
,
y
,
"
MOVING;{};{};{}
"
.
format
(
color
,
speed
,
text
))
send_xy
(
x
,
y
,
"
MOVING;{};{};{}
"
.
format
(
color
,
speed
,
text
))
# Check if there is a connected matrix in the d direction
def
check_presence
(
d
):
def
check_presence
(
d
):
envoyer_msg
(
d
,
"
PING
"
)
envoyer_msg
(
d
,
"
PING
"
)
...
@@ -78,13 +84,18 @@ def check_presence(d):
...
@@ -78,13 +84,18 @@ def check_presence(d):
return
False
return
False
# Update the ID of the current matrix, and update the id of the neighbours
def
update_id
(
new_id
):
def
update_id
(
new_id
):
global
id
global
id
id
[
0
]
=
int
(
new_id
[
0
])
id
[
0
]
=
int
(
new_id
[
0
])
id
[
1
]
=
int
(
new_id
[
1
])
id
[
1
]
=
int
(
new_id
[
1
])
envoyer_msg
(
N
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
],
id
[
1
]
+
1
))
# The matrices which are in the x = 0 pos, update the id North and East.
# The others only broadcast East.
if
(
id
[
0
]
==
0
):
envoyer_msg
(
N
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
],
id
[
1
]
+
1
))
envoyer_msg
(
E
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
]
+
1
,
id
[
1
]))
envoyer_msg
(
E
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
]
+
1
,
id
[
1
]))
if
not
check_presence
(
N
)
and
not
check_presence
(
E
):
if
not
check_presence
(
N
)
and
not
check_presence
(
E
):
...
@@ -93,6 +104,8 @@ def update_id(new_id):
...
@@ -93,6 +104,8 @@ def update_id(new_id):
display_id
()
display_id
()
# Handle the commands received via UART
def
handle_receive
(
msg
,
msg_bytes
,
d
):
def
handle_receive
(
msg
,
msg_bytes
,
d
):
print
(
"
Received from {} : {}
"
.
format
(
d
,
msg
))
print
(
"
Received from {} : {}
"
.
format
(
d
,
msg
))
...
@@ -149,8 +162,8 @@ def handle_receive(msg, msg_bytes, d):
...
@@ -149,8 +162,8 @@ def handle_receive(msg, msg_bytes, d):
img
=
data_to_color16
(
msg_bytes
[
6
:])
img
=
data_to_color16
(
msg_bytes
[
6
:])
disp_img_data
(
img
)
disp_img_data
(
img
)
# send_text_xy(1,0,text,speed=speed);time.sleep(speed*13);afficher_texte(text,speed=speed)
elif
msg
==
"
OK
"
:
update_id
(
id
)
# Main
# Main
...
...
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