-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyled-client.py
45 lines (34 loc) · 1023 Bytes
/
pyled-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import socketio
import os
from PIL import Image
from PIL import ImageDraw
import time
from rgbmatrix import RGBMatrix, RGBMatrixOptions
import io
HOST = os.environ.get('HOST', 'http://localhost')
PORT = os.environ.get('PORT', 5000)
# Configuration for the matrix
options = RGBMatrixOptions()
options.rows = 64
options.cols = 64
options.chain_length = 1
options.parallel = 1
options.hardware_mapping = 'adafruit-hat'
options.multiplexing = 0
options.gpio_slowdown = 5 #try higher values
options.show_refresh_rate = True
options.pixel_mapper_config = "Rotate:90"
matrix = RGBMatrix(options = options)
def set_image(image_bytes):
try:
i = io.BytesIO(image_bytes)
image = Image.open(i)
image = image.convert('RGB')
image = image.resize((options.rows, options.cols))
matrix.Clear()
matrix.SetImage(image, 0, 0, unsafe=False)
except Exception as e:
print(e)
sio = socketio.Client()
sio.connect(f'{HOST}:{PORT}')
sio.on('new_image', set_image)