init
commit
15df2eff31
|
@ -0,0 +1,149 @@
|
|||
#!/usr/bin/env python
|
||||
import RPi.GPIO as GPIO
|
||||
import pygame
|
||||
import pygame.freetype
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
import _thread
|
||||
|
||||
sys.path.append("home/pi/go/bin/")
|
||||
photo_folder = "/home/pi/fotobox_bilder"
|
||||
qr_path = "/home/pi/fotobox/qr_small.png"
|
||||
qr_image = None
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input
|
||||
GPIO.setup(18, GPIO.OUT) # LED
|
||||
GPIO.setup(17, GPIO.OUT) # green led
|
||||
|
||||
WIDTH = 1680
|
||||
HEIGHT = 1050
|
||||
|
||||
|
||||
def io_remote():
|
||||
# switch on ready
|
||||
GPIO.output(17, 1)
|
||||
# wait for button press
|
||||
GPIO.wait_for_edge(22, GPIO.RISING, bouncetime=100)
|
||||
# switch of green light
|
||||
GPIO.output(17, 0)
|
||||
|
||||
|
||||
def get_file_name():
|
||||
# name mit Timestamp versehen
|
||||
ts = time.gmtime()
|
||||
readable_ts = time.strftime("%H_%M_%S", ts)
|
||||
photo_name = "/bhwp_2020_" + readable_ts + ".jpg"
|
||||
return photo_folder + photo_name
|
||||
|
||||
|
||||
def load_image(img_path):
|
||||
return pygame.image.load(img_path).convert()
|
||||
|
||||
|
||||
def signal_hook(running=True):
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
runnig = False
|
||||
pygame.quit()
|
||||
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
|
||||
pygame.display.toggle_fullscreen()
|
||||
|
||||
|
||||
def display_image(screen, img):
|
||||
try:
|
||||
img = pygame.transform.scale(img, (WIDTH, HEIGHT))
|
||||
screen.blit(img, (0, 0))
|
||||
except:
|
||||
pass
|
||||
pygame.display.flip()
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
def display_qr(screen, qr):
|
||||
screen.blit(qr, (1330, 700))
|
||||
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 sync_photo(photo_path):
|
||||
# hochladen des bildes
|
||||
print("Uploading file..")
|
||||
print(os.path.isfile(photo_path))
|
||||
subprocess.run(
|
||||
["rclone", "copy", "{}".format(photo_path), "fotobox_remote:fotobox"]
|
||||
)
|
||||
print("photo uploaded!")
|
||||
|
||||
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 0)
|
||||
_thread.start_new_thread(signal_hook, ())
|
||||
if not qr_image:
|
||||
qr_img = load_image(qr_path)
|
||||
|
||||
while 1:
|
||||
print("Starting...")
|
||||
GPIO.output(18, 0)
|
||||
while 1:
|
||||
display_qr(screen, qr_img)
|
||||
io_remote()
|
||||
try:
|
||||
display_image(screen, img)
|
||||
except NameError:
|
||||
pass
|
||||
display_text(screen, "Geschafft! Erstmal chillen...", color=(10, 50, 255))
|
||||
# shoot picture
|
||||
photo_path = get_file_name()
|
||||
print(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:
|
||||
continue
|
||||
try:
|
||||
img = load_image(photo_path)
|
||||
display_image(screen, img)
|
||||
display_text(
|
||||
screen, "Zuerst das Vergnügen, dann der Upload in die cloud...", size=50
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
if os.path.isfile(photo_path):
|
||||
sync_photo(photo_path)
|
||||
except:
|
||||
print("not uplloaded")
|
||||
|
||||
display_image(screen, img)
|
||||
display_text(screen, "Kamera is breit!", color=(20, 230, 20))
|
||||
print("Return to main process")
|
||||
|
||||
# gdrive about --service-account fotobox-265418-e52db5a765c2.json
|
||||
# gdrive --service-account fotobox-265418-e52db5a765c2.json share ~/fotobox_bilder
|
||||
|
||||
# gdrive --service-account fotobox-265418-e52db5a765c2.json sync list
|
|
@ -0,0 +1,240 @@
|
|||
from xmlrpc.client import DateTime
|
||||
# import RPi.GPIO as GPIO
|
||||
from gpiozero import GPIO
|
||||
import pygame
|
||||
import pygame.freetype
|
||||
from webdav3.client import Client
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
import _thread
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
sys.path.append("home/pi/go/bin/")
|
||||
photo_folder = "/Users/rootrapp/Downloads/Screenshot 2023-06-19 at 18-43-27 QLC Quick Beginner Overview.png"
|
||||
qr_path = "/home/pi/fotobox_fabi/qr_small.png"
|
||||
qr_image = None
|
||||
|
||||
#
|
||||
# Fürs Layout
|
||||
#
|
||||
##from pathlib import Path
|
||||
##from PyPDF2 import PdfReader
|
||||
#
|
||||
from reportlab.pdfgen.canvas import Canvas
|
||||
from reportlab.lib.units import mm
|
||||
from reportlab.lib import colors
|
||||
#for print
|
||||
import os
|
||||
#
|
||||
#
|
||||
##pdf_path = (
|
||||
## Path.home()
|
||||
## / "/home/pi/fotobox_fabi/layout.pdf")
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
#GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input
|
||||
GPIO.setup(20, GPIO.IN) #, pull_up_down=GPIO.PUD_UP) # input
|
||||
#GPIO.setup(18, GPIO.OUT) # LED
|
||||
#GPIO.setup(17, GPIO.OUT) # green led
|
||||
|
||||
WIDTH = 1920
|
||||
HEIGHT = 1080
|
||||
|
||||
#
|
||||
# Fürs layout versucht er ein pdf zu lesen.
|
||||
#
|
||||
|
||||
def readpdf():
|
||||
pdf = PdfReader(str(pdf_path))
|
||||
print("pdf.getNumPages()")
|
||||
|
||||
def io_remote():
|
||||
# switch on ready
|
||||
#sGPIO.output(21, 1)
|
||||
# wait for button press
|
||||
GPIO.wait_for_edge(20, GPIO.RISING, bouncetime=100)
|
||||
# switch of green light
|
||||
#GPIO.output(17, 0)
|
||||
|
||||
def buttonPressed():
|
||||
LOGGER.debug(GPIO.input(20))
|
||||
if(GPIO.input(20)):
|
||||
time.sleep(0.1)
|
||||
if(GPIO.input(20)):
|
||||
return 1
|
||||
return 0
|
||||
#time.sleep(0.1)
|
||||
#if(GPIO.input(20)==1):
|
||||
#return true
|
||||
#return false
|
||||
|
||||
def get_file_name():
|
||||
# name mit Timestamp versehen
|
||||
ts = time.gmtime()
|
||||
readable_ts = time.strftime("%H_%M_%S", ts)
|
||||
photo_name = "/sommerparty_2023_" + readable_ts + ".jpg"
|
||||
return photo_folder + photo_name
|
||||
|
||||
|
||||
def load_image(img_path):
|
||||
return pygame.image.load(img_path).convert()
|
||||
|
||||
|
||||
def signal_hook(running=True):
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
runnig = False
|
||||
pygame.quit()
|
||||
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
|
||||
pygame.display.toggle_fullscreen()
|
||||
|
||||
|
||||
def display_image(screen, img):
|
||||
#readpdf()
|
||||
try:
|
||||
img = pygame.transform.scale(img, (WIDTH, HEIGHT))
|
||||
screen.blit(img, (0, 0))
|
||||
#screen.blit(pygame.transform.rotate(screen, 180), (0,0))
|
||||
except:
|
||||
pass
|
||||
pygame.display.flip()
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
def display_qr(screen, qr):
|
||||
screen.blit(qr, (1530, 700))
|
||||
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))
|
||||
screen.blit(pygame.transform.rotate(screen, 180), (0,0))
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
def sync_photo(photo_path):
|
||||
# hochladen des bildes
|
||||
print("Uploading file..")
|
||||
print(os.path.isfile(photo_path))
|
||||
subprocess.run(
|
||||
["rclone", "copy", "{}".format(photo_path), "https://cloud.bauhaeusle.de/remote.php/dav/files/admin"]
|
||||
)
|
||||
print("photo uploaded!")
|
||||
|
||||
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 0)
|
||||
_thread.start_new_thread(signal_hook, ())
|
||||
if not qr_image:
|
||||
qr_img = load_image(qr_path)
|
||||
|
||||
sync_photo(photo_path=photo_folder)
|
||||
while 0:
|
||||
print("Starting...")
|
||||
#(GPIO.output(21, 0)
|
||||
while 1:
|
||||
##display_qr(screen, qr_img)
|
||||
#io_remote()
|
||||
while buttonPressed() == 0:
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
screen.fill(color=(255, 255, 255))
|
||||
pygame.display.update()
|
||||
display_text(screen, "Kamera ist breit!", color=(250, 150, 0))
|
||||
#try:
|
||||
# display_image(screen, img)
|
||||
#except NameError:
|
||||
# pass
|
||||
#display_text(screen, "Cheeeeeeese!", color=(250, 250, 10))
|
||||
#display_text(screen, "Geschafft! Erstmal chillen...", color=(10, 50, 255))
|
||||
# shoot picture
|
||||
photo_path = get_file_name()
|
||||
print(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 captureFailError:
|
||||
#handling does not work:
|
||||
#print("failed to capture image!")
|
||||
#photo_path = "/home/pi/fotobox_fabi/pic.jpg"
|
||||
pass
|
||||
|
||||
|
||||
pygame.display.update()
|
||||
screen.fill(color=(0, 0, 0))
|
||||
display_text(screen, "Geschafft! Erstmal chillen...", color=(10, 50, 255))
|
||||
|
||||
|
||||
try:
|
||||
img = load_image(photo_path)
|
||||
print(img.shape)
|
||||
display_image(screen, img)
|
||||
display_text(
|
||||
screen, "Zuerst das Vergnügen, dann der Upload in die cloud...", size=50
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
#try:
|
||||
# if os.path.isfile(photo_path):
|
||||
# sync_photo(photo_path)
|
||||
#except:
|
||||
# print("not uplloaded")
|
||||
|
||||
#printout:
|
||||
#generate pdf:
|
||||
#canvas = Canvas("StickerPrint.pdf", pagesize=(105 * mm, 149 * mm))
|
||||
#width_print = 95
|
||||
#height_print= 1664 * (width_print / 2496)
|
||||
##set image twize with a frame each:
|
||||
#canvas.drawInlineImage(photo_path, 5*mm, 5*mm, width = width_print*mm, height = height_print*mm)
|
||||
#canvas.rect(5*mm, 5*mm, width_print*mm, height_print*mm, stroke=1, fill=0)
|
||||
#canvas.drawInlineImage(photo_path, 5*mm, (149/2+5)*mm, width = width_print*mm, height = height_print*mm)
|
||||
#canvas.rect(5*mm, (149/2+5)*mm, width_print*mm, height_print*mm, stroke=1, fill=0)
|
||||
#canvas.save()
|
||||
#print:
|
||||
#os.system("lp /home/pi/fotobox_fabi/StickerPrint.pdf")
|
||||
|
||||
display_image(screen, img)
|
||||
display_text(screen, "Kamera is breit!", color=(20, 230, 20))
|
||||
print("Return to main process")
|
||||
|
||||
# gdrive about --service-account fotobox-265418-e52db5a765c2.json
|
||||
# gdrive --service-account fotobox-265418-e52db5a765c2.json share ~/fotobox_bilder
|
||||
|
||||
# gdrive --service-account fotobox-265418-e52db5a765c2.json sync list
|
||||
|
||||
def sync_photo(photo_path):
|
||||
options = {
|
||||
'webdav_hostname': "https://cloud.bauhaeusle.de/remote.php/dav",
|
||||
'webdav_login': "bh",
|
||||
'webdav_password': "forever2023!"
|
||||
}
|
||||
client = Client(options)
|
||||
client.verify = False # To not check SSL certificates (Default = True)
|
||||
#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)
|
|
@ -0,0 +1,4 @@
|
|||
pygame
|
||||
RPi.GPIO; platform_system == "Linux"
|
||||
webdavclient3
|
||||
gpiozero
|
|
@ -0,0 +1,31 @@
|
|||
import subprocess
|
||||
from webdav3.client import Client
|
||||
|
||||
from xmlrpc.client import DateTime
|
||||
import os
|
||||
|
||||
def sync_photo(photo_path):
|
||||
# hochladen des bildes
|
||||
print("Uploading file..")
|
||||
print(os.path.isfile(photo_path))
|
||||
subprocess.run(
|
||||
["rclone", "copy", "{}".format(photo_path), "https://cloud.bauhaeusle.de/remote.php/dav/files/admin"]
|
||||
)
|
||||
print("photo uploaded!")
|
||||
|
||||
|
||||
def sync_phot2(photo_path):
|
||||
options = {
|
||||
'webdav_hostname': "https://cloud.bauhaeusle.de/remote.php/dav",
|
||||
'webdav_login': "bh",
|
||||
'webdav_password': "forever2023!"
|
||||
}
|
||||
client = Client(options)
|
||||
client.verify = False # To not check SSL certificates (Default = True)
|
||||
#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)
|
||||
sync_photo(photo_path="/Users/rootrapp/Downloads/Screenshot 2023-06-19 at 18-43-27 QLC Quick Beginner Overview.png")
|
||||
|
||||
|
Loading…
Reference in New Issue