forked from TDTP/pantallas-led
makeitwork
parent
54daec5249
commit
a18c5c1784
|
@ -5,6 +5,7 @@ import numpy as np
|
|||
from datetime import datetime, timedelta
|
||||
from import_data import export_data
|
||||
from PIL import Image
|
||||
import subprocess
|
||||
from getData import Paradero
|
||||
|
||||
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)
|
||||
print("Imagen redimensionada y guardada con éxito en", output_path)
|
||||
|
||||
except Exception as e:
|
||||
print("Ocurrió un error:", str(e))
|
||||
except:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
|
||||
def aprox(n):
|
||||
return int(np.round(n))
|
||||
|
@ -75,17 +77,34 @@ def main():
|
|||
bus_stop = Paradero()
|
||||
|
||||
data = bus_stop.get_data()
|
||||
data1 = data[0]
|
||||
data2 = data[1]
|
||||
if data is not None:
|
||||
data1 = data[0]
|
||||
data2 = data[1]
|
||||
|
||||
print(data)
|
||||
print(data)
|
||||
|
||||
# Calcula el tiempo restante a la llegada
|
||||
remaining_time1 = data1['timeRemaining']
|
||||
remaining_time2 = data2['timeRemaining']
|
||||
# Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
|
||||
min_time1, max_time1 = obtain_min_max_time(remaining_time1)
|
||||
min_time2, max_time2 = obtain_min_max_time(remaining_time2)
|
||||
# Calcula el tiempo restante a la llegada
|
||||
remaining_time1 = data1['timeRemaining']
|
||||
remaining_time2 = data2['timeRemaining']
|
||||
# Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
|
||||
min_time1, max_time1 = obtain_min_max_time(remaining_time1)
|
||||
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
|
||||
theme = 'night'
|
||||
|
@ -135,8 +154,8 @@ def main():
|
|||
poster1.set_colors()
|
||||
|
||||
# Se setea la ruta y la direccion en la que va
|
||||
poster1.set_bus_number(bus_number=data1["route"])
|
||||
poster1.set_bus_letter(bus_letter=data1["direction"])
|
||||
poster1.set_bus_number(bus_number=ruta1)
|
||||
poster1.set_bus_letter(bus_letter=direccion1)
|
||||
|
||||
# Genera la imagen de la linea del bus
|
||||
poster2 = BusPoster(aprox(1.1*(1/3)*height), aprox(1.1*(1/3)*width))
|
||||
|
@ -157,8 +176,8 @@ def main():
|
|||
poster2.load_barlow()
|
||||
poster2.set_colors()
|
||||
# Se setea la ruta y la direccion en la que va
|
||||
poster2.set_bus_number(bus_number=data2["route"])
|
||||
poster2.set_bus_letter(bus_letter=data2["direction"])
|
||||
poster2.set_bus_number(bus_number=ruta2)
|
||||
poster2.set_bus_letter(bus_letter=direccion2)
|
||||
|
||||
# Se agregan todas las imagenes al canvas
|
||||
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(bm, (aprox(0.02*width),aprox((1/6)*height)))
|
||||
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_ancho = 160 # Reemplaza con el ancho deseado en píxeles
|
||||
input_path = f'/app/example/poster.png'
|
||||
output_path = f'/app/example/poster_{nuevo_alto}_{nuevo_ancho}.png'
|
||||
input_path = f'/srv/ledram/poster.png'
|
||||
output_path = '/srv/ledram/next.png'
|
||||
|
||||
reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto)
|
||||
subprocess.run(['cp', output_path, '/srv/ledram/current.png'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -65,7 +65,8 @@ class MyDraw():
|
|||
|
||||
def load_barlow(self, font_size=None):
|
||||
# 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
|
||||
if font_size is None:
|
||||
self.font = ImageFont.truetype(font_path, self.prms['font_size'])
|
||||
|
|
|
@ -49,14 +49,17 @@ class TimeAnnouncement(MyDraw):
|
|||
text_bbox = self.font.getbbox(text)
|
||||
base_font_width, base_font_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
|
||||
|
||||
if (int(max_time) <= 1):
|
||||
text = "< 1 min"
|
||||
elif (int(min_time) >= 10):
|
||||
print(max_time)
|
||||
text = f"> {max_time} min"
|
||||
else:
|
||||
text = f'{min_time} a {max_time} min'
|
||||
|
||||
try:
|
||||
if (int(max_time) <= 1):
|
||||
text = "< 1 min"
|
||||
elif (int(min_time) >= 10):
|
||||
print(max_time)
|
||||
text = f"> {max_time} min"
|
||||
else:
|
||||
text = f'{min_time} a {max_time} min'
|
||||
except:
|
||||
text = 'N/A'
|
||||
|
||||
self.load_barlow(font_size=70)
|
||||
text_bbox = self.font.getbbox(text)
|
||||
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
|
||||
|
||||
#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
|
||||
mkdir /srv/subsystem
|
||||
|
|
|
@ -40,13 +40,17 @@ else:
|
|||
|
||||
#guarda el tiempo de modificación
|
||||
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:
|
||||
time.sleep(0.1)
|
||||
ntstam = os.stat(img_path).st_mtime
|
||||
#si el bufer fue modificado, lo carga en la pantalla led
|
||||
if ntstam > tstam:
|
||||
image=Image.open(img_path)
|
||||
matrix.SetImage(image.convert('RGB'))
|
||||
with Image.open(img_path) as image:
|
||||
matrix.SetImage(image.convert('RGB'))
|
||||
tstam = ntstam
|
||||
|
|
Loading…
Reference in New Issue