From 152832515c4cf574236297165b89d634af2c7afa Mon Sep 17 00:00:00 2001 From: fotobox Date: Fri, 7 Jul 2023 21:54:34 +0200 Subject: [PATCH] works with false positives --- config.json | 6 +++--- main.py | 55 +++++++++++++++++++++++++++++++++++------------------ uploader.py | 6 +++--- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/config.json b/config.json index 3b06ef0..670df06 100644 --- a/config.json +++ b/config.json @@ -1,8 +1,8 @@ -{ - "photo_folder": "/home/pi/fotobox_bilder", +{ +"photo_folder": "/home/pi/fotobox_bilder", "qr_path": "/home/pi/fotobox/qr_small.png", "photo_prefix": "bh_sommerparty_23", "qr_image": null, "width": 1920, - "height": 1080 + "height": 1200 } \ No newline at end of file diff --git a/main.py b/main.py index 57345e7..b661fda 100644 --- a/main.py +++ b/main.py @@ -1,22 +1,31 @@ -import pygame - +# -*- coding: utf-8 -*- import configparser +from ctypes import cdll +import json import logging -import RPi.GPIO as GPIO import subprocess import time -import _thread +import threading + +import RPi.GPIO as GPIO +import pygame import uploader +cdll.LoadLibrary('/usr/lib/arm-linux-gnueabihf/libX11.so.6') +cdll.LoadLibrary('/usr/lib/arm-linux-gnueabihf/libX11-xcb.so.1') +PIN_BUTTON = 21 +GPIO.setmode(GPIO.BCM) +GPIO.setup(PIN_BUTTON, GPIO.IN) #, pull_up_down=GPIO.PUD_UP) # input + LOGGER = logging.getLogger(__name__) -PIN_BUTTON = 22 + def get_config(): - """Read config from ./config.ini""" - config = configparser.ConfigParser() - config.read('config.json') + """Read config from ./config.json""" + with open('config.json', 'r') as config_file: + config = json.load(config_file) return config @@ -35,7 +44,9 @@ def display_qr(screen, qr): def load_image(img_path): - return pygame.image.load(img_path).convert() + image = pygame.image.load(img_path) + image = image.convert() # Convert the image to the display format + return image def display_image(screen, img, width, height): try: @@ -57,10 +68,10 @@ def display_text(screen, text, color=(20, 240, 100), size=70): screen.blit(text_renderd, (50, 50)) pygame.display.update() + def io_remote(): # wait for button press - GPIO.wait_for_edge(PIN_BUTTON, GPIO.RISING, bouncetime=100) - + GPIO.wait_for_edge(PIN_BUTTON, GPIO.BOTH, bouncetime=100): def signal_hook(running=True): while running: @@ -72,21 +83,25 @@ def signal_hook(running=True): pygame.display.toggle_fullscreen() def run(): + print("start") config = get_config() pygame.init() - _thread.start_new_thread(signal_hook, ()) - screen = pygame.display.set_mode((config.WIDTH, config.HEIGHT), 0, 0) - qr_img = pygame.image.load(config.qr_path).convert() + # Start the signal_hook function in a separate thread + thread = threading.Thread(target=signal_hook) + thread.start() + screen = pygame.display.set_mode((config["width"], config["height"]), 0, 0) + qr_img = load_image(config["qr_path"]) while 1: LOGGER.info("Starting...") while 1: display_qr(screen, qr_img) io_remote() - photo_path = get_file_name(prefix=config.prefix, path=config.photo_folder) + photo_path = get_file_name(prefix=config["photo_prefix"], path=config["photo_folder"]) LOGGER.info(photo_path) + print(photo_path) # Capture photo try: subprocess.run( @@ -94,7 +109,7 @@ def run(): "gphoto2", "--capture-image-and-download", "--camera='Canon EOS 350D (normal mode)'", - "--filename={}".format(photo_path), + "--filename={0}".format(photo_path), "--force-overwrite", ] ) @@ -104,15 +119,17 @@ def run(): try: img = load_image(photo_path) - display_image(screen, img, config.width, config.height) + display_image(screen, img, config["width"], config["height"]) display_text( screen, "Zuerst das Vergnügen, dann der Upload in die cloud...", size=50 ) except: LOGGER.info("Failed to display image.") pass - - uploader.sync_photo(photo_path="/Users/rootrapp/Downloads/Screenshot 2023-06-19 at 18-43-27 QLC Quick Beginner Overview.png") + + display_image(screen, img, config["width"], config["height"]) + uploader.sync_photo2(photo_path=photo_path) + display_text(screen, "Kamera is breit!", color=(20, 230, 20)) if __name__ == "__main__": diff --git a/uploader.py b/uploader.py index 2be02f9..fdf3515 100644 --- a/uploader.py +++ b/uploader.py @@ -19,9 +19,9 @@ def sync_photo(photo_path): LOGGER.info("photo uploaded!") -def sync_phot2(photo_path): +def sync_photo2(photo_path): options = { - 'webdav_hostname': "https://cloud.bauhaeusle.de/remote.php/dav", + 'webdav_hostname': "https://cloud.bauhaeusle.de/remote.php/dav/files", 'webdav_login': "bh", 'webdav_password': "forever2023!" } @@ -30,6 +30,6 @@ def sync_phot2(photo_path): #client.session.proxies(...) # To set proxy directly into the session (Optional) #client.session.auth(...) # To set proxy auth directly into the session (Optional) - client.upload_sync(remote_path="BestOf/Fotobox", local_path=photo_path) + client.upload_sync(remote_path="/bh/BestOf/Fotobox/" + photo_path.split("/")[-1] , local_path=photo_path)