printer working

This commit is contained in:
Patrick Haßel 2025-06-27 22:42:20 +02:00
parent 00deaff4fe
commit 21a7e0cede
4 changed files with 28 additions and 56 deletions

View File

@ -14,6 +14,7 @@ class Event:
self.title = data['title'] self.title = data['title']
self.date = datetime.strptime(data['date'], '%Y-%m-%d') self.date = datetime.strptime(data['date'], '%Y-%m-%d')
self.password = data['password'] self.password = data['password']
self.gallery = bool(data['gallery'])
self.frame_factor = float(data['frame_factor']) if 'frame_factor' in data else 1.0 self.frame_factor = float(data['frame_factor']) if 'frame_factor' in data else 1.0
self.frame_photo_sized = shrink_cover(Image.open("./data/frames/" + data['frame']), PHOTO_WIDTH, PHOTO_HEIGHT) self.frame_photo_sized = shrink_cover(Image.open("./data/frames/" + data['frame']), PHOTO_WIDTH, PHOTO_HEIGHT)
self.frame = pil_image_to_surface(shrink_cover(self.frame_photo_sized, int(WIDTH * self.frame_factor), int(HEIGHT * self.frame_factor))) self.frame = pil_image_to_surface(shrink_cover(self.frame_photo_sized, int(WIDTH * self.frame_factor), int(HEIGHT * self.frame_factor)))

View File

@ -3,9 +3,9 @@ import time
from typing import List from typing import List
from PIL import Image from PIL import Image
from escpos.escpos import Escpos from escpos.escpos import Escpos
from ConsolePrinter import ConsolePrinter from escpos.printer import Usb
from serial import SerialException
from Event import Event, load_event from Event import Event, load_event
from Photo import Photo from Photo import Photo
@ -137,20 +137,21 @@ class Fotobox:
elif self._printer is not None and not self._printed and PRINT_RECT.collidepoint(event.pos): elif self._printer is not None and not self._printed and PRINT_RECT.collidepoint(event.pos):
print("PRINT") print("PRINT")
try: try:
self._printer.set(align='center', font='b', width=2, height=2)
self._printer.text("Fotobox\n")
self._printer.set(align='center', font='a', width=1, height=1) self._printer.set(align='center', font='a', width=1, height=1)
self._printer.text("Fotobox\n")
url = "http%s://%s" % ('s' if HTTPS else '', DOMAIN)
if self._event is not None: if self._event is not None:
self._printer.text(self._event.date.strftime("%d.%m.%Y") + "\n")
self._printer.text(self._event.title + "\n") self._printer.text(self._event.title + "\n")
self._printer.text(self._event.url_without_protocol + "\n") self._printer.text(self._event.date.strftime("%d.%m.%Y") + "\n")
self._printer.text("Passwort: " + self._event.password + "\n") if self._event.gallery:
else: self._printer.text(self._event.url_without_protocol + "\n")
self._printer.text(datetime.now().strftime("%d.%m.%Y") + "\n") self._printer.text("Passwort: " + self._event.password + "\n")
self._printer.text(self._idle_url_without_protocol + "\n") self._printer.text("Dein Foto findest du hier:\n")
self._printer.qr(self._choice.urlWithProtocol, center=True) self._printer.qr(self._choice.urlWithProtocol, center=True, size=5)
self._printer.text(self._choice.urlWithoutProtocol) self._printer.text(url + "\n")
self._printer.cut() self._printer.text("/p/" + self._choice.code + "\n")
self._printer.text(" \n")
self._printer.text(" \n")
self._printed = True self._printed = True
except Exception as e: except Exception as e:
@ -218,16 +219,19 @@ class Fotobox:
photo.prepare(self._event) photo.prepare(self._event)
self._set_state(State.CHOOSE) self._set_state(State.CHOOSE)
elif new_state == State.CHOOSE: elif new_state == State.CHOOSE:
self._choice = None if DEBUG:
self._choice = self._photos[0]
self._set_state(State.QR)
else:
self._choice = None
elif new_state == State.QR: elif new_state == State.QR:
self._printed = False self._printed = False
try: try:
if self._printer is None or not self._printer.is_online(): if self._printer is None or not self._printer.is_online():
# self._printer = Serial(devfile='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) self._printer = Usb(0x0483, 0x5840, 0, interface=0, out_ep=0x04, in_ep=0x82)
self._printer = ConsolePrinter()
self._printer.profile.media['width']['pixels'] = 512 self._printer.profile.media['width']['pixels'] = 512
print("Printer AVAILABLE") print("Printer AVAILABLE")
except SerialException: except Exception:
self._printer = None self._printer = None
print("No printer available") print("No printer available")

View File

@ -8,7 +8,7 @@ from pygame import Surface
from pygame.time import Clock from pygame.time import Clock
from qrcode.main import QRCode from qrcode.main import QRCode
DEBUG: bool = False DEBUG: bool = True
WIDTH: int = 800 WIDTH: int = 800
HEIGHT: int = 480 HEIGHT: int = 480
@ -17,9 +17,9 @@ BORDER: int = 10
PHOTO_WIDTH = 2592 PHOTO_WIDTH = 2592
PHOTO_HEIGHT = 1944 PHOTO_HEIGHT = 1944
SHOOTING_COUNT: int = 2 SHOOTING_COUNT: int = 1 if DEBUG else 2
SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75 SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75
COUNTDOWN_COUNT: int = 1 if DEBUG else 1 COUNTDOWN_COUNT: int = 0 if DEBUG else 3
CHOICE_BORDER: int = 5 CHOICE_BORDER: int = 5
@ -135,4 +135,4 @@ def now():
def generate_code(groups: int): def generate_code(groups: int):
return '-'.join(''.join(random.choices('23456789abcdefghjkmnpqrstuvwxyz', k=4)) for _ in range(groups)) return '-'.join(''.join(random.choices('23456789ABCDEFGHJKMNPQRSTUVWXYZ', k=4)) for _ in range(groups))

View File

@ -1,38 +1,5 @@
#!/bin/bash #!/bin/bash
WATCH_DIR="./data/photos/upload" cd "$(dirname "$0")/data/photos/upload" || exit 1
if [ ! -d "$WATCH_DIR" ]; then rsync -a ./* fotobox@mc.ph87.de:/srv/fotobox.online/html/p/
echo "watch dir not found: $WATCH_DIR"
exit 1
fi
UPLOAD_URL="https://fotobox.online/upload"
FOTOBOX_KEY="bla..." # TODO
SLEEP_INTERVAL=10
while true; do
for filepath in "$WATCH_DIR"/*; do
[ -e "$filepath" ] || continue
filename=$(basename "$filepath")
filesize=$(stat -c %s "$filepath")
echo "uploading: $filepath"
response=$(curl -s -w "\n%{http_code}" -F "file=@${filepath}" -F "filename=${filename}" -F "fotoboxKey=${FOTOBOX_KEY}" "$UPLOAD_URL")
body=$(echo "$response" | head -n 1)
status=$(echo "$response" | tail -n 1)
expected="Fotobox2|||${filename}|||${filesize}"
if [ "$status" -eq 200 ] && [ "$body" = "$expected" ]; then
echo "SUCCESS"
rm -f "$filepath"
else
echo "FAILED: CODE=$status, Response=$body"
fi
done
sleep "$SLEEP_INTERVAL"
done