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
52749dbb
Commit
52749dbb
authored
1 year ago
by
nicolas.albanesi
Browse files
Options
Downloads
Patches
Plain Diff
Display text and image working
parent
698bbf83
Branches
Branches containing commit
No related tags found
1 merge request
!1
merge Nico
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
hepialight/boot.py
+0
-0
0 additions, 0 deletions
hepialight/boot.py
hepialight/main.py
+167
-0
167 additions, 0 deletions
hepialight/main.py
hepialight/userlib.py
+0
-0
0 additions, 0 deletions
hepialight/userlib.py
mapping/main.py
+0
-152
0 additions, 152 deletions
mapping/main.py
with
167 additions
and
152 deletions
mapping
/boot.py
→
hepialight
/boot.py
+
0
−
0
View file @
52749dbb
File moved
This diff is collapsed.
Click to expand it.
hepialight/main.py
0 → 100644
+
167
−
0
View file @
52749dbb
id
=
[
0
,
0
]
matsize
=
[
0
,
0
]
def
color16_to_32
(
color
):
color
=
int
(
color
)
r
=
((
color
>>
11
)
&
0x1F
)
*
2
**
3
g
=
((
color
>>
5
)
&
0x3F
)
*
2
**
2
b
=
(
color
&
0x1F
)
*
2
**
3
return
r
<<
16
|
g
<<
8
|
b
def
disp_img_data
(
data
):
for
i
in
range
(
NBR_LIGNES
):
for
j
in
range
(
NBR_COLONNES
):
allumer_led
(
j
,
NBR_LIGNES
-
1
-
i
,
data
[
i
*
NBR_COLONNES
+
j
])
def
data_to_color16
(
data
):
d_color16
=
[]
for
i
in
range
(
0
,
len
(
data
),
2
):
d_color16
.
append
(
data
[
i
]
<<
8
|
data
[
i
+
1
])
return
list
(
map
(
color16_to_32
,
d_color16
))
def
display_id
():
afficher_texte
(
"
{}, {}
"
.
format
(
id
[
0
],
id
[
1
]),
speed
=
0.01
)
def
msg_to_str
(
msg
):
return
str
(
msg
)[
2
:
-
1
]
def
send_passthrough_str
(
msg
,
x
,
y
):
x
=
int
(
x
)
y
=
int
(
y
)
if
x
>
id
[
0
]:
d
=
E
elif
x
<
id
[
0
]:
d
=
O
elif
y
>
id
[
1
]:
d
=
N
else
:
d
=
S
envoyer_msg
(
d
,
"
PT;{},{};{}
"
.
format
(
x
,
y
,
msg
))
def
send_passthrough_bytes
(
msg
,
x
,
y
):
x
=
int
(
x
)
y
=
int
(
y
)
if
x
>
id
[
0
]:
d
=
E
elif
x
<
id
[
0
]:
d
=
O
elif
y
>
id
[
1
]:
d
=
N
else
:
d
=
S
envoyer_msg
(
d
,
msg
)
def
send_xy
(
x
,
y
,
msg
):
send_passthrough_str
(
msg
,
x
,
y
)
def
send_text_xy
(
x
,
y
,
text
,
color
=
ROUGE
,
speed
=
0.1
):
send_xy
(
x
,
y
,
"
TEXT;{};{};{}
"
.
format
(
color
,
speed
,
text
))
def
send_moving_xy
(
x
,
y
,
text
,
color
=
ROUGE
,
speed
=
0.1
):
send_xy
(
x
,
y
,
"
MOVING;{};{};{}
"
.
format
(
color
,
speed
,
text
))
def
check_presence
(
d
):
envoyer_msg
(
d
,
"
PING
"
)
for
x
in
range
(
10
):
time
.
sleep
(
0.1
)
ret
=
recevoir_msg
(
d
)
if
ret
==
b
"
PONG
"
:
return
True
return
False
def
update_id
(
new_id
):
global
id
id
[
0
]
=
int
(
new_id
[
0
])
id
[
1
]
=
int
(
new_id
[
1
])
envoyer_msg
(
N
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
],
id
[
1
]
+
1
))
envoyer_msg
(
E
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
]
+
1
,
id
[
1
]))
if
not
check_presence
(
N
)
and
not
check_presence
(
E
):
send_xy
(
0
,
0
,
"
MATSIZE;{},{}
"
.
format
(
id
[
0
],
id
[
1
]))
display_id
()
def
handle_receive
(
msg
,
msg_bytes
,
d
):
print
(
"
Received from {} : {}
"
.
format
(
d
,
msg
))
if
msg
.
startswith
(
"
SET_ID
"
):
tmp_id
=
msg
[
7
:].
split
(
"
,
"
)
update_id
(
tmp_id
)
elif
msg
==
"
PING
"
:
envoyer_msg
(
d
,
"
PONG
"
)
elif
msg
==
"
DISP_ID
"
:
display_id
()
elif
msg
.
startswith
(
"
PT;
"
):
msgs
=
msg
.
split
(
"
;
"
)
m
=
msgs
[
2
:]
m
=
"
;
"
.
join
(
m
)
x
,
y
=
msgs
[
1
].
split
(
"
,
"
)
x
=
int
(
x
)
y
=
int
(
y
)
if
x
==
id
[
0
]
and
y
==
id
[
1
]:
handle_receive
(
m
,
msg_bytes
[
7
:],
d
)
return
print
(
"
sending passthrough to {},{}: {}
"
.
format
(
x
,
y
,
m
))
send_passthrough_bytes
(
msg_bytes
,
x
,
y
)
elif
msg
.
startswith
(
"
MATSIZE
"
):
x
,
y
=
msg
.
split
(
"
;
"
)[
-
1
].
split
(
"
,
"
)
print
(
"
Matsize : {} {}
"
.
format
(
x
,
y
))
matsize
=
[
int
(
x
),
int
(
y
)]
elif
msg
.
startswith
(
"
TEXT
"
):
msgs
=
msg
.
split
(
"
;
"
)
color
=
int
(
msgs
[
1
])
speed
=
float
(
msgs
[
2
])
afficher_texte
(
msgs
[
3
],
color
,
speed
)
elif
msg
.
startswith
(
"
MOVING
"
):
msgs
=
msg
.
split
(
"
;
"
)
color
=
int
(
msgs
[
1
])
speed
=
float
(
msgs
[
2
])
text
=
msgs
[
3
]
time
.
sleep
(
speed
*
11
)
send_moving_xy
(
id
[
0
]
-
1
,
id
[
1
],
text
,
color
=
color
,
speed
=
speed
)
afficher_texte
(
text
,
color
,
speed
)
elif
msg
.
startswith
(
"
IMAGE
"
):
print
(
"
IMAGE LEN : {}
"
.
format
(
len
(
msg_bytes
[
6
:])))
img
=
data_to_color16
(
msg_bytes
[
6
:])
disp_img_data
(
img
)
# send_text_xy(1,0,text,speed=speed);time.sleep(speed*13);afficher_texte(text,speed=speed)
# Main
afficher_texte
(
"
Ready
"
,
VERT
,
speed
=
0.01
)
while
True
:
for
d
in
[
N
,
S
,
E
,
O
]:
msg_bytes
=
recevoir_msg
(
d
)
if
msg_bytes
==
b
""
:
continue
msg
=
msg_to_str
(
msg_bytes
)
handle_receive
(
msg
,
msg_bytes
,
d
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mapping
/userlib.py
→
hepialight
/userlib.py
+
0
−
0
View file @
52749dbb
File moved
This diff is collapsed.
Click to expand it.
mapping/main.py
deleted
100644 → 0
+
0
−
152
View file @
698bbf83
id
=
[
0
,
0
]
matsize
=
[
0
,
0
]
def
color16_to_32
(
color
):
color
=
int
(
color
)
r
=
((
color
>>
11
)
&
0xFF
)
*
2
**
3
g
=
((
color
>>
5
)
&
0xFF
)
*
2
**
2
b
=
(
color
&
0xFF
)
*
2
**
3
return
r
<<
16
|
g
<<
8
|
b
def
disp_img_data
(
data
):
for
i
in
range
(
NBR_LIGNES
):
for
j
in
range
(
NBR_COLONNES
):
allumer_led
(
i
,
j
,
data
[
i
*
NBR_LIGNES
+
j
])
def
data_to_color16
(
data
):
d_color16
=
[]
for
i
in
range
(
0
,
len
(
data
),
2
):
d_color16
.
append
(
data
[
i
]
<<
8
|
data
[
i
+
1
])
return
list
(
map
(
color16_to_32
,
d_color16
))
def
display_id
():
afficher_texte
(
"
{}, {}
"
.
format
(
id
[
0
],
id
[
1
]),
speed
=
0.01
)
def
msg_to_str
(
msg
):
return
str
(
msg
)[
2
:
-
1
]
def
send_passthrough
(
msg
,
x
,
y
):
x
=
int
(
x
)
y
=
int
(
y
)
if
x
>
id
[
0
]:
d
=
E
elif
x
<
id
[
0
]:
d
=
O
elif
y
>
id
[
1
]:
d
=
N
else
:
d
=
S
envoyer_msg
(
d
,
"
PT;{},{};{}
"
.
format
(
x
,
y
,
msg
))
def
send_xy
(
x
,
y
,
msg
):
send_passthrough
(
msg
,
x
,
y
)
def
send_text_xy
(
x
,
y
,
text
,
color
=
ROUGE
,
speed
=
0.1
):
send_xy
(
x
,
y
,
"
TEXT;{};{};{}
"
.
format
(
color
,
speed
,
text
))
def
send_moving_xy
(
x
,
y
,
text
,
color
=
ROUGE
,
speed
=
0.1
):
send_xy
(
x
,
y
,
"
MOVING;{};{};{}
"
.
format
(
color
,
speed
,
text
))
def
check_presence
(
d
):
envoyer_msg
(
d
,
"
PING
"
)
for
x
in
range
(
10
):
time
.
sleep
(
0.1
)
ret
=
recevoir_msg
(
d
)
if
ret
==
b
"
PONG
"
:
return
True
return
False
def
update_id
(
new_id
):
global
id
id
[
0
]
=
int
(
new_id
[
0
])
id
[
1
]
=
int
(
new_id
[
1
])
envoyer_msg
(
N
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
],
id
[
1
]
+
1
))
envoyer_msg
(
E
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
]
+
1
,
id
[
1
]))
if
not
check_presence
(
N
)
and
not
check_presence
(
E
):
send_xy
(
0
,
0
,
"
MATSIZE;{},{}
"
.
format
(
id
[
0
],
id
[
1
]))
display_id
()
def
handle_receive
(
msg
,
msg_bytes
,
d
):
print
(
"
Received from {} : {}
"
.
format
(
d
,
msg
))
if
msg
.
startswith
(
"
SET_ID
"
):
tmp_id
=
msg
[
7
:].
split
(
"
,
"
)
update_id
(
tmp_id
)
elif
msg
==
"
PING
"
:
envoyer_msg
(
d
,
"
PONG
"
)
elif
msg
==
"
DISP_ID
"
:
display_id
()
elif
msg
.
startswith
(
"
PT;
"
):
msgs
=
msg
.
split
(
"
;
"
)
m
=
msgs
[
2
:]
m
=
"
;
"
.
join
(
m
)
x
,
y
=
msgs
[
1
].
split
(
"
,
"
)
x
=
int
(
x
)
y
=
int
(
y
)
if
x
==
id
[
0
]
and
y
==
id
[
1
]:
handle_receive
(
m
,
msg_bytes
[
7
:],
d
)
return
print
(
"
sending passthrough to {},{}: {}
"
.
format
(
x
,
y
,
m
))
send_passthrough
(
m
,
x
,
y
)
elif
msg
.
startswith
(
"
MATSIZE
"
):
x
,
y
=
msg
.
split
(
"
;
"
)[
-
1
].
split
(
"
,
"
)
print
(
"
Matsize : {} {}
"
.
format
(
x
,
y
))
matsize
=
[
int
(
x
),
int
(
y
)]
elif
msg
.
startswith
(
"
TEXT
"
):
msgs
=
msg
.
split
(
"
;
"
)
color
=
int
(
msgs
[
1
])
speed
=
float
(
msgs
[
2
])
afficher_texte
(
msgs
[
3
],
color
,
speed
)
elif
msg
.
startswith
(
"
MOVING
"
):
msgs
=
msg
.
split
(
"
;
"
)
color
=
int
(
msgs
[
1
])
speed
=
float
(
msgs
[
2
])
text
=
msgs
[
3
]
time
.
sleep
(
speed
*
11
)
send_moving_xy
(
id
[
0
]
-
1
,
id
[
1
],
text
,
color
=
color
,
speed
=
speed
)
afficher_texte
(
text
,
color
,
speed
)
elif
msg
.
startswith
(
"
IMAGE
"
):
print
(
"
IMAGE LEN : {}
"
.
format
(
len
(
msg_bytes
[
6
:])))
img
=
data_to_color16
(
msg_bytes
[
6
:])
disp_img_data
(
img
)
# send_text_xy(1,0,text,speed=speed);time.sleep(speed*13);afficher_texte(text,speed=speed)
# Main
afficher_texte
(
"
Ready
"
,
VERT
,
speed
=
0.01
)
while
True
:
for
d
in
[
N
,
S
,
E
,
O
]:
msg_bytes
=
recevoir_msg
(
d
)
if
msg_bytes
==
b
""
:
continue
msg
=
msg_to_str
(
msg_bytes
)
handle_receive
(
msg
,
msg_bytes
,
d
)
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