This commit is contained in:
Patrick Haßel 2018-08-15 12:19:10 +02:00
parent 0e23e048da
commit 50a3d6f29f
2 changed files with 278 additions and 299 deletions

View File

@ -1,39 +1,40 @@
#!/usr/bin/python
import sys, os, inspect
import pytz, datetime
from time import sleep
from PIL import Image
from shutil import copyfile
import datetime
import inspect
import os
import sys
from math import floor
import RPi.GPIO as GPIO
from shutil import copyfile
from time import sleep
import RPi.GPIO as GPIO
import picamera
import pygame
import random
import time
from PIL import Image
# ~ import server
__all__ = ["monotonic_time"]
import ctypes
CLOCK_MONOTONIC_RAW = 4 # see <linux/time.h>
class timespec(ctypes.Structure):
_fields_ = [
('tv_sec', ctypes.c_long),
('tv_nsec', ctypes.c_long)
]
librt = ctypes.CDLL('librt.so.1', use_errno=True)
clock_gettime = librt.clock_gettime
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
def monotonic_time():
t = timespec()
if clock_gettime(CLOCK_MONOTONIC_RAW, ctypes.pointer(t)) != 0:
@ -42,11 +43,8 @@ def monotonic_time():
return t.tv_sec + t.tv_nsec * 1e-9
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
# CONFIGURATION
WIDTH = 800
HEIGHT = 480
@ -75,14 +73,11 @@ THUMB_HEIGHT = int(THUMB_WIDTH / 1.333)
IMAGES_ORIGINAL = os.path.join(IMAGE_DIR, "original")
IMAGES_TODO = os.path.join(IMAGE_DIR, "todo")
# global variables
spot_mode = 0
session_start = monotonic_time()
# GPIO helpers
def led_border(state):
@ -102,14 +97,12 @@ def next_spot_mode():
set_spot_mode(spot_mode + 1)
# user interface
def button_press(gpio_id):
next_spot_mode()
# INIT GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
@ -136,18 +129,15 @@ led_border(True)
sleep(0.02)
led_border(False)
# INIT PYGAME
pygame.init()
pygame.mouse.set_visible(False)
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# LOAD GRAPHICS
gfx = {}
def _load(name):
filename = "%s.png" % name
path = os.path.join(GRAPHICS_DIR, filename)
@ -157,6 +147,7 @@ def _load(name):
gfx[name] = (img, rect)
_load("begin")
_load("loading")
_load("yes")
@ -166,8 +157,6 @@ _load("end_no")
_load("saved")
_load("canceled")
# LOAD COUNTDOWN OVERLAYS
img_cdn = []
pad_cdn = []
@ -185,7 +174,6 @@ for i in range(0, COUNTDOWN):
pad_cdn.append(pad)
# FUNCTIONS ========================================================================================
def waitForEvent():
@ -201,7 +189,6 @@ def waitForEvent():
return events
def waitForTouch():
pos = (-1, -1)
while True:
@ -213,7 +200,6 @@ def waitForTouch():
return pos
def maintainance():
screen.fill(COLOR_BACK)
screen.blit(maintain, maintain_rect)
@ -223,7 +209,6 @@ def maintainance():
pos = waitForTouch()
def waitForBegin():
screen.fill(COLOR_BACK)
screen.blit(*gfx["begin"])
@ -235,7 +220,6 @@ def waitForBegin():
maintainance()
def countdown(camera, pad, img):
sleep(PIC_INTERVAL)
o = camera.add_overlay(pad.tostring(), size=img.size)
@ -245,7 +229,6 @@ def countdown(camera, pad, img):
camera.remove_overlay(o)
def makePhotos():
# CLEAR SCREEN
screen.fill(COLOR_BACK)
@ -284,7 +267,6 @@ def makePhotos():
camera.close()
def chooseImages():
# clear screen
screen.fill(COLOR_BACK)
@ -309,7 +291,6 @@ def chooseImages():
x = x + THUMB_WIDTH + BORDER
save = False
cancel = False
any_choice = False
@ -369,7 +350,6 @@ def chooseImages():
return (choices, save)
def saveImages(choices):
local = datetime.datetime.now()
session_age = (monotonic_time() - session_start)
@ -399,7 +379,6 @@ def saveImages(choices):
copyfile(path_original, path_todo)
try:
while 1:
waitForBegin()