Compare commits

...

2 Commits

Author SHA1 Message Date
21a7e0cede printer working 2025-06-27 22:42:20 +02:00
00deaff4fe code clean 2025-06-27 21:30:05 +02:00
4 changed files with 31 additions and 69 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
@ -35,15 +35,15 @@ class Fotobox:
camera.hflip = True camera.hflip = True
camera.resolution = (2592, 1944) camera.resolution = (2592, 1944)
camera.rotation = 270 camera.rotation = 270
camera.preview_configuration.main.size = res camera.preview_configuration.main.size = res
camera.preview_configuration.main.format = 'BGR888' camera.preview_configuration.main.format = 'BGR888'
camera.preview_configuration.transform = Transform(hflip=1, vflip=1) camera.preview_configuration.transform = Transform(hflip=1, vflip=1)
camera.configure("preview") camera.configure("preview")
#####################
# here configure still capture
self._capture_config = camera.create_still_configuration() self._capture_config = camera.create_still_configuration()
camera.still_configuration.main.size = (2592, 1944) camera.still_configuration.main.size = (2592, 1944)
#####################
camera.start() camera.start()
self._camera = camera self._camera = camera
@ -97,11 +97,6 @@ class Fotobox:
image = Image.fromarray(frame) image = Image.fromarray(frame)
self._photos.append(Photo(self._shooting_timer.current(), image)) self._photos.append(Photo(self._shooting_timer.current(), image))
#stream = io.BytesIO()
#self._camera.capture(stream, format='rgb')
#stream.seek(0)
#self._photos.append(Photo(self._shooting_timer.current(), Image.open(stream)))
screen.fill((0, 0, 0)) screen.fill((0, 0, 0))
pygame.display.flip() pygame.display.flip()
@ -142,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.date.strftime("%d.%m.%Y") + "\n")
if self._event.gallery:
self._printer.text(self._event.url_without_protocol + "\n") self._printer.text(self._event.url_without_protocol + "\n")
self._printer.text("Passwort: " + self._event.password + "\n") self._printer.text("Passwort: " + self._event.password + "\n")
else: self._printer.text("Dein Foto findest du hier:\n")
self._printer.text(datetime.now().strftime("%d.%m.%Y") + "\n") self._printer.qr(self._choice.urlWithProtocol, center=True, size=5)
self._printer.text(self._idle_url_without_protocol + "\n") self._printer.text(url + "\n")
self._printer.qr(self._choice.urlWithProtocol, center=True) self._printer.text("/p/" + self._choice.code + "\n")
self._printer.text(self._choice.urlWithoutProtocol) self._printer.text(" \n")
self._printer.cut() self._printer.text(" \n")
self._printed = True self._printed = True
except Exception as e: except Exception as e:
@ -211,10 +207,6 @@ class Fotobox:
print(new_state) print(new_state)
self._state = new_state self._state = new_state
if new_state == State.COUNTDOWN: if new_state == State.COUNTDOWN:
#config = self._camera.create_preview_configuration(main={"size": (PHOTO_WIDTH, PHOTO_HEIGHT)})
#self._camera.configure(config)
#self._camera.start_preview()
#self._camera.start()
self._countdown_timer.restart() self._countdown_timer.restart()
elif new_state == State.SHOOTING: elif new_state == State.SHOOTING:
self._photos = [] self._photos = []
@ -223,21 +215,23 @@ class Fotobox:
print("Starting shooting: S%04d-%s" % (self._shooting_number, iso(self._shooting_datetime))) print("Starting shooting: S%04d-%s" % (self._shooting_number, iso(self._shooting_datetime)))
self._shooting_timer.restart() self._shooting_timer.restart()
elif new_state == State.PREPARE: elif new_state == State.PREPARE:
#self._camera.stop_preview()
for photo in self._photos: for photo in self._photos:
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:
if DEBUG:
self._choice = self._photos[0]
self._set_state(State.QR)
else:
self._choice = None 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