119 lines
3.3 KiB
Python
119 lines
3.3 KiB
Python
import pygame
|
|
|
|
import configparser
|
|
import logging
|
|
import RPi.GPIO as GPIO
|
|
import subprocess
|
|
import time
|
|
import _thread
|
|
|
|
import uploader
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
PIN_BUTTON = 22
|
|
|
|
def get_config():
|
|
"""Read config from ./config.ini"""
|
|
config = configparser.ConfigParser()
|
|
config.read('config.json')
|
|
return config
|
|
|
|
|
|
def get_file_name(prefix="photobox", path="~"):
|
|
# name mit Timestamp versehen
|
|
ts = time.gmtime()
|
|
readable_ts = time.strftime("%H_%M_%S", ts)
|
|
photo_name = "/" + prefix + readable_ts + ".jpg"
|
|
return path + photo_name
|
|
|
|
|
|
def display_qr(screen, qr):
|
|
screen.blit(qr, (1330, 700))
|
|
pygame.display.flip()
|
|
pygame.display.update()
|
|
|
|
|
|
def load_image(img_path):
|
|
return pygame.image.load(img_path).convert()
|
|
|
|
def display_image(screen, img, width, height):
|
|
try:
|
|
img = pygame.transform.scale(img, (width, height))
|
|
screen.blit(img, (0, 0))
|
|
except:
|
|
pass
|
|
pygame.display.flip()
|
|
pygame.display.update()
|
|
|
|
|
|
def display_text(screen, text, color=(20, 240, 100), size=70):
|
|
font = pygame.freetype.Font(
|
|
"/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf", size
|
|
)
|
|
text_renderd, text_rect = font.render(text, color)
|
|
screen_rect = screen.get_rect()
|
|
text_rect.centerx = screen_rect.centerx
|
|
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)
|
|
|
|
|
|
def signal_hook(running=True):
|
|
while running:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
pygame.quit()
|
|
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
|
|
pygame.display.toggle_fullscreen()
|
|
|
|
def run():
|
|
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()
|
|
|
|
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)
|
|
|
|
|
|
LOGGER.info(photo_path)
|
|
# Capture photo
|
|
try:
|
|
subprocess.run(
|
|
[
|
|
"gphoto2",
|
|
"--capture-image-and-download",
|
|
"--camera='Canon EOS 350D (normal mode)'",
|
|
"--filename={}".format(photo_path),
|
|
"--force-overwrite",
|
|
]
|
|
)
|
|
except:
|
|
LOGGER.info("Failed to capture image.")
|
|
continue
|
|
|
|
try:
|
|
img = load_image(photo_path)
|
|
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")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run() |