forked from TDTP/pantallas-led
makeitwork
parent
54daec5249
commit
a18c5c1784
|
@ -5,6 +5,7 @@ import numpy as np
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from import_data import export_data
|
from import_data import export_data
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
import subprocess
|
||||||
from getData import Paradero
|
from getData import Paradero
|
||||||
|
|
||||||
def reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto):
|
def reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto):
|
||||||
|
@ -19,8 +20,9 @@ def reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto):
|
||||||
imagen_redimensionada.save(output_path)
|
imagen_redimensionada.save(output_path)
|
||||||
print("Imagen redimensionada y guardada con éxito en", output_path)
|
print("Imagen redimensionada y guardada con éxito en", output_path)
|
||||||
|
|
||||||
except Exception as e:
|
except:
|
||||||
print("Ocurrió un error:", str(e))
|
import traceback
|
||||||
|
print(traceback.format_exc())
|
||||||
|
|
||||||
def aprox(n):
|
def aprox(n):
|
||||||
return int(np.round(n))
|
return int(np.round(n))
|
||||||
|
@ -75,17 +77,34 @@ def main():
|
||||||
bus_stop = Paradero()
|
bus_stop = Paradero()
|
||||||
|
|
||||||
data = bus_stop.get_data()
|
data = bus_stop.get_data()
|
||||||
data1 = data[0]
|
if data is not None:
|
||||||
data2 = data[1]
|
data1 = data[0]
|
||||||
|
data2 = data[1]
|
||||||
|
|
||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
# Calcula el tiempo restante a la llegada
|
# Calcula el tiempo restante a la llegada
|
||||||
remaining_time1 = data1['timeRemaining']
|
remaining_time1 = data1['timeRemaining']
|
||||||
remaining_time2 = data2['timeRemaining']
|
remaining_time2 = data2['timeRemaining']
|
||||||
# Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
|
# Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
|
||||||
min_time1, max_time1 = obtain_min_max_time(remaining_time1)
|
min_time1, max_time1 = obtain_min_max_time(remaining_time1)
|
||||||
min_time2, max_time2 = obtain_min_max_time(remaining_time2)
|
min_time2, max_time2 = obtain_min_max_time(remaining_time2)
|
||||||
|
ruta1 = data1['route']
|
||||||
|
direccion1 = data1['direction']
|
||||||
|
ruta2 = data2['route']
|
||||||
|
direccion2 = data2['direction']
|
||||||
|
|
||||||
|
else:
|
||||||
|
remaining_time1 = 'N/A'
|
||||||
|
remaining_time2 = 'N/A'
|
||||||
|
min_time1 = 'N/A'
|
||||||
|
min_time2 = 'N/A'
|
||||||
|
max_time1 = 'N/A'
|
||||||
|
max_time2 = 'N/A'
|
||||||
|
ruta1 = "00"
|
||||||
|
direccion1 = "X"
|
||||||
|
ruta2 = "99"
|
||||||
|
direccion2 = "Y"
|
||||||
|
|
||||||
# Selecciona el tema
|
# Selecciona el tema
|
||||||
theme = 'night'
|
theme = 'night'
|
||||||
|
@ -135,8 +154,8 @@ def main():
|
||||||
poster1.set_colors()
|
poster1.set_colors()
|
||||||
|
|
||||||
# Se setea la ruta y la direccion en la que va
|
# Se setea la ruta y la direccion en la que va
|
||||||
poster1.set_bus_number(bus_number=data1["route"])
|
poster1.set_bus_number(bus_number=ruta1)
|
||||||
poster1.set_bus_letter(bus_letter=data1["direction"])
|
poster1.set_bus_letter(bus_letter=direccion1)
|
||||||
|
|
||||||
# Genera la imagen de la linea del bus
|
# Genera la imagen de la linea del bus
|
||||||
poster2 = BusPoster(aprox(1.1*(1/3)*height), aprox(1.1*(1/3)*width))
|
poster2 = BusPoster(aprox(1.1*(1/3)*height), aprox(1.1*(1/3)*width))
|
||||||
|
@ -157,8 +176,8 @@ def main():
|
||||||
poster2.load_barlow()
|
poster2.load_barlow()
|
||||||
poster2.set_colors()
|
poster2.set_colors()
|
||||||
# Se setea la ruta y la direccion en la que va
|
# Se setea la ruta y la direccion en la que va
|
||||||
poster2.set_bus_number(bus_number=data2["route"])
|
poster2.set_bus_number(bus_number=ruta2)
|
||||||
poster2.set_bus_letter(bus_letter=data2["direction"])
|
poster2.set_bus_letter(bus_letter=direccion2)
|
||||||
|
|
||||||
# Se agregan todas las imagenes al canvas
|
# Se agregan todas las imagenes al canvas
|
||||||
full_panel.add_image(time_anmc1, (aprox((0.6)*width), aprox(0.05*height)))
|
full_panel.add_image(time_anmc1, (aprox((0.6)*width), aprox(0.05*height)))
|
||||||
|
@ -167,14 +186,15 @@ def main():
|
||||||
full_panel.add_image(poster2, (aprox((0.05)*width), aprox((0.5)*height)))
|
full_panel.add_image(poster2, (aprox((0.05)*width), aprox((0.5)*height)))
|
||||||
#full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height)))
|
#full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height)))
|
||||||
full_panel.get_image()
|
full_panel.get_image()
|
||||||
full_panel.save_image('/app/example/poster.png')
|
full_panel.save_image('/srv/ledram/poster.png')
|
||||||
|
|
||||||
nuevo_alto = 40 # Reemplaza con el alto deseado en píxeles
|
nuevo_alto = 40 # Reemplaza con el alto deseado en píxeles
|
||||||
nuevo_ancho = 160 # Reemplaza con el ancho deseado en píxeles
|
nuevo_ancho = 160 # Reemplaza con el ancho deseado en píxeles
|
||||||
input_path = f'/app/example/poster.png'
|
input_path = f'/srv/ledram/poster.png'
|
||||||
output_path = f'/app/example/poster_{nuevo_alto}_{nuevo_ancho}.png'
|
output_path = '/srv/ledram/next.png'
|
||||||
|
|
||||||
reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto)
|
reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto)
|
||||||
|
subprocess.run(['cp', output_path, '/srv/ledram/current.png'])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -65,7 +65,8 @@ class MyDraw():
|
||||||
|
|
||||||
def load_barlow(self, font_size=None):
|
def load_barlow(self, font_size=None):
|
||||||
# Ruta a la fuente TTF personalizada
|
# Ruta a la fuente TTF personalizada
|
||||||
font_path = "/app/assets/fonts/Barlow-Medium.ttf"
|
# font_path = "../../assets/fonts/Barlow-Medium.ttf"
|
||||||
|
font_path = "assets/fonts/Barlow-Medium.ttf"
|
||||||
# Carga la fuente
|
# Carga la fuente
|
||||||
if font_size is None:
|
if font_size is None:
|
||||||
self.font = ImageFont.truetype(font_path, self.prms['font_size'])
|
self.font = ImageFont.truetype(font_path, self.prms['font_size'])
|
||||||
|
|
|
@ -49,14 +49,17 @@ class TimeAnnouncement(MyDraw):
|
||||||
text_bbox = self.font.getbbox(text)
|
text_bbox = self.font.getbbox(text)
|
||||||
base_font_width, base_font_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
|
base_font_width, base_font_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
|
||||||
|
|
||||||
if (int(max_time) <= 1):
|
try:
|
||||||
text = "< 1 min"
|
if (int(max_time) <= 1):
|
||||||
elif (int(min_time) >= 10):
|
text = "< 1 min"
|
||||||
print(max_time)
|
elif (int(min_time) >= 10):
|
||||||
text = f"> {max_time} min"
|
print(max_time)
|
||||||
else:
|
text = f"> {max_time} min"
|
||||||
text = f'{min_time} a {max_time} min'
|
else:
|
||||||
|
text = f'{min_time} a {max_time} min'
|
||||||
|
except:
|
||||||
|
text = 'N/A'
|
||||||
|
|
||||||
self.load_barlow(font_size=70)
|
self.load_barlow(font_size=70)
|
||||||
text_bbox = self.font.getbbox(text)
|
text_bbox = self.font.getbbox(text)
|
||||||
font_width, font_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
|
font_width, font_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
|
||||||
|
|
|
@ -24,7 +24,7 @@ sed -i -e 's/ isocpus=3//g' /boot/cmdline.txt
|
||||||
sed -i -e 's/$/ isocpus=3/' /boot/cmdline.txt
|
sed -i -e 's/$/ isocpus=3/' /boot/cmdline.txt
|
||||||
|
|
||||||
#copia la biblioteca al directorio de trabajo
|
#copia la biblioteca al directorio de trabajo
|
||||||
cp -R rgbmatrix /srv/rgbmatrix
|
cp -R /home/soporte/rpi-rgb-led-matrix/bindings/python/rgbmatrix /srv/rgbmatrix
|
||||||
|
|
||||||
#copia el sub-sistema de renderizado
|
#copia el sub-sistema de renderizado
|
||||||
mkdir /srv/subsystem
|
mkdir /srv/subsystem
|
||||||
|
|
|
@ -40,13 +40,17 @@ else:
|
||||||
|
|
||||||
#guarda el tiempo de modificación
|
#guarda el tiempo de modificación
|
||||||
tstam = os.stat(img_path).st_mtime
|
tstam = os.stat(img_path).st_mtime
|
||||||
matrix.SetImage(Image.open(img_path).convert('RGB'))
|
|
||||||
|
with Image.open(img_path) as image:
|
||||||
|
matrix.SetImage(image.convert('RGB'))
|
||||||
|
|
||||||
|
#matrix.SetImage(Image.open(img_path).convert('RGB'))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
ntstam = os.stat(img_path).st_mtime
|
ntstam = os.stat(img_path).st_mtime
|
||||||
#si el bufer fue modificado, lo carga en la pantalla led
|
#si el bufer fue modificado, lo carga en la pantalla led
|
||||||
if ntstam > tstam:
|
if ntstam > tstam:
|
||||||
image=Image.open(img_path)
|
with Image.open(img_path) as image:
|
||||||
matrix.SetImage(image.convert('RGB'))
|
matrix.SetImage(image.convert('RGB'))
|
||||||
tstam = ntstam
|
tstam = ntstam
|
||||||
|
|
Loading…
Reference in New Issue