works with false positives

master
fotobox 2023-07-07 21:54:34 +02:00
parent 185e586766
commit 152832515c
3 changed files with 42 additions and 25 deletions

View File

@ -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
}

55
main.py
View File

@ -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__":

View File

@ -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)