Compare commits
3 Commits
9eb08d9d96
...
5a460f7b54
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a460f7b54 | |||
| 50a3d6f29f | |||
| 0e23e048da |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
|
/.idea/
|
||||||
|
/venv/
|
||||||
|
|
||||||
/images/
|
/images/
|
||||||
/tmp?.jpg
|
/tmp?.jpg
|
||||||
|
|||||||
27
FakeGPIO/__init__.py
Normal file
27
FakeGPIO/__init__.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
BOARD = 1
|
||||||
|
HIGH = 1
|
||||||
|
LOW = 0
|
||||||
|
OUT = 1
|
||||||
|
IN = 0
|
||||||
|
FALLING = 0
|
||||||
|
RISING = 1
|
||||||
|
|
||||||
|
|
||||||
|
def setmode(x):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def setwarnings(x):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def setup(gpio, mode, initial=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def output(gpio, state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def add_event_detect(gpio, edge, callback, bouncetime=None):
|
||||||
|
pass
|
||||||
BIN
FakeGPIO/__init__.pyc
Normal file
BIN
FakeGPIO/__init__.pyc
Normal file
Binary file not shown.
28
FakePicamera/__init__.py
Normal file
28
FakePicamera/__init__.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
class Overlay(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.alpha = 0
|
||||||
|
|
||||||
|
|
||||||
|
class PiCamera(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.resolution = None
|
||||||
|
|
||||||
|
def start_preview(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def add_overlay(self, *args, **kwargs):
|
||||||
|
return Overlay()
|
||||||
|
|
||||||
|
def remove_overlay(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def capture(self, filename, format, *args, **kwargs):
|
||||||
|
print("FAKE: capture(%s, %s)" % (filename, format))
|
||||||
|
img = Image.new("RGB", self.resolution, (255, 255, 255))
|
||||||
|
img.save(filename, format)
|
||||||
|
|
||||||
|
def close(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
BIN
FakePicamera/__init__.pyc
Normal file
BIN
FakePicamera/__init__.pyc
Normal file
Binary file not shown.
61
photobox.py
61
photobox.py
@ -1,22 +1,28 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import sys, os, inspect
|
import datetime
|
||||||
import pytz, datetime
|
import imp
|
||||||
from time import sleep
|
import inspect
|
||||||
from PIL import Image
|
import os
|
||||||
from shutil import copyfile
|
import sys
|
||||||
from math import floor
|
from math import floor
|
||||||
import RPi.GPIO as GPIO
|
from shutil import copyfile
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
import picamera
|
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
from PIL import Image
|
||||||
import time
|
|
||||||
|
|
||||||
# ~ import server
|
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
imp.find_module('RPi')
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
except ImportError:
|
||||||
|
import FakeGPIO as GPIO
|
||||||
|
|
||||||
|
try:
|
||||||
|
imp.find_module('picamera')
|
||||||
|
import picamera
|
||||||
|
except ImportError:
|
||||||
|
import FakePicamera as picamera
|
||||||
|
|
||||||
__all__ = ["monotonic_time"]
|
__all__ = ["monotonic_time"]
|
||||||
|
|
||||||
@ -24,16 +30,19 @@ import ctypes
|
|||||||
|
|
||||||
CLOCK_MONOTONIC_RAW = 4 # see <linux/time.h>
|
CLOCK_MONOTONIC_RAW = 4 # see <linux/time.h>
|
||||||
|
|
||||||
|
|
||||||
class timespec(ctypes.Structure):
|
class timespec(ctypes.Structure):
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
('tv_sec', ctypes.c_long),
|
('tv_sec', ctypes.c_long),
|
||||||
('tv_nsec', ctypes.c_long)
|
('tv_nsec', ctypes.c_long)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
librt = ctypes.CDLL('librt.so.1', use_errno=True)
|
librt = ctypes.CDLL('librt.so.1', use_errno=True)
|
||||||
clock_gettime = librt.clock_gettime
|
clock_gettime = librt.clock_gettime
|
||||||
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
|
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
|
||||||
|
|
||||||
|
|
||||||
def monotonic_time():
|
def monotonic_time():
|
||||||
t = timespec()
|
t = timespec()
|
||||||
if clock_gettime(CLOCK_MONOTONIC_RAW, ctypes.pointer(t)) != 0:
|
if clock_gettime(CLOCK_MONOTONIC_RAW, ctypes.pointer(t)) != 0:
|
||||||
@ -42,11 +51,8 @@ def monotonic_time():
|
|||||||
return t.tv_sec + t.tv_nsec * 1e-9
|
return t.tv_sec + t.tv_nsec * 1e-9
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
|
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
|
||||||
|
|
||||||
|
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
HEIGHT = 480
|
HEIGHT = 480
|
||||||
@ -75,14 +81,11 @@ THUMB_HEIGHT = int(THUMB_WIDTH / 1.333)
|
|||||||
IMAGES_ORIGINAL = os.path.join(IMAGE_DIR, "original")
|
IMAGES_ORIGINAL = os.path.join(IMAGE_DIR, "original")
|
||||||
IMAGES_TODO = os.path.join(IMAGE_DIR, "todo")
|
IMAGES_TODO = os.path.join(IMAGE_DIR, "todo")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
spot_mode = 0
|
spot_mode = 0
|
||||||
session_start = monotonic_time()
|
session_start = monotonic_time()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# GPIO helpers
|
# GPIO helpers
|
||||||
|
|
||||||
def led_border(state):
|
def led_border(state):
|
||||||
@ -102,14 +105,12 @@ def next_spot_mode():
|
|||||||
set_spot_mode(spot_mode + 1)
|
set_spot_mode(spot_mode + 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# user interface
|
# user interface
|
||||||
|
|
||||||
def button_press(gpio_id):
|
def button_press(gpio_id):
|
||||||
next_spot_mode()
|
next_spot_mode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# INIT GPIO
|
# INIT GPIO
|
||||||
GPIO.setmode(GPIO.BOARD)
|
GPIO.setmode(GPIO.BOARD)
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
@ -136,18 +137,15 @@ led_border(True)
|
|||||||
sleep(0.02)
|
sleep(0.02)
|
||||||
led_border(False)
|
led_border(False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# INIT PYGAME
|
# INIT PYGAME
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# LOAD GRAPHICS
|
# LOAD GRAPHICS
|
||||||
gfx = {}
|
gfx = {}
|
||||||
|
|
||||||
|
|
||||||
def _load(name):
|
def _load(name):
|
||||||
filename = "%s.png" % name
|
filename = "%s.png" % name
|
||||||
path = os.path.join(GRAPHICS_DIR, filename)
|
path = os.path.join(GRAPHICS_DIR, filename)
|
||||||
@ -157,6 +155,7 @@ def _load(name):
|
|||||||
|
|
||||||
gfx[name] = (img, rect)
|
gfx[name] = (img, rect)
|
||||||
|
|
||||||
|
|
||||||
_load("begin")
|
_load("begin")
|
||||||
_load("loading")
|
_load("loading")
|
||||||
_load("yes")
|
_load("yes")
|
||||||
@ -166,8 +165,6 @@ _load("end_no")
|
|||||||
_load("saved")
|
_load("saved")
|
||||||
_load("canceled")
|
_load("canceled")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# LOAD COUNTDOWN OVERLAYS
|
# LOAD COUNTDOWN OVERLAYS
|
||||||
img_cdn = []
|
img_cdn = []
|
||||||
pad_cdn = []
|
pad_cdn = []
|
||||||
@ -185,7 +182,6 @@ for i in range(0, COUNTDOWN):
|
|||||||
pad_cdn.append(pad)
|
pad_cdn.append(pad)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# FUNCTIONS ========================================================================================
|
# FUNCTIONS ========================================================================================
|
||||||
|
|
||||||
def waitForEvent():
|
def waitForEvent():
|
||||||
@ -201,7 +197,6 @@ def waitForEvent():
|
|||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def waitForTouch():
|
def waitForTouch():
|
||||||
pos = (-1, -1)
|
pos = (-1, -1)
|
||||||
while True:
|
while True:
|
||||||
@ -213,7 +208,6 @@ def waitForTouch():
|
|||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def maintainance():
|
def maintainance():
|
||||||
screen.fill(COLOR_BACK)
|
screen.fill(COLOR_BACK)
|
||||||
screen.blit(maintain, maintain_rect)
|
screen.blit(maintain, maintain_rect)
|
||||||
@ -223,7 +217,6 @@ def maintainance():
|
|||||||
pos = waitForTouch()
|
pos = waitForTouch()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def waitForBegin():
|
def waitForBegin():
|
||||||
screen.fill(COLOR_BACK)
|
screen.fill(COLOR_BACK)
|
||||||
screen.blit(*gfx["begin"])
|
screen.blit(*gfx["begin"])
|
||||||
@ -235,17 +228,15 @@ def waitForBegin():
|
|||||||
maintainance()
|
maintainance()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def countdown(camera, pad, img):
|
def countdown(camera, pad, img):
|
||||||
sleep(PIC_INTERVAL)
|
sleep(PIC_INTERVAL)
|
||||||
o = camera.add_overlay(pad.tostring(), size=img.size)
|
o = camera.add_overlay(pad.tobytes(), size=img.size)
|
||||||
o.alpha = OVERLAY_ALPHA
|
o.alpha = OVERLAY_ALPHA
|
||||||
o.layer = 3
|
o.layer = 3
|
||||||
sleep(TEXT_INTERVAL)
|
sleep(TEXT_INTERVAL)
|
||||||
camera.remove_overlay(o)
|
camera.remove_overlay(o)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def makePhotos():
|
def makePhotos():
|
||||||
# CLEAR SCREEN
|
# CLEAR SCREEN
|
||||||
screen.fill(COLOR_BACK)
|
screen.fill(COLOR_BACK)
|
||||||
@ -284,7 +275,6 @@ def makePhotos():
|
|||||||
camera.close()
|
camera.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def chooseImages():
|
def chooseImages():
|
||||||
# clear screen
|
# clear screen
|
||||||
screen.fill(COLOR_BACK)
|
screen.fill(COLOR_BACK)
|
||||||
@ -309,7 +299,6 @@ def chooseImages():
|
|||||||
|
|
||||||
x = x + THUMB_WIDTH + BORDER
|
x = x + THUMB_WIDTH + BORDER
|
||||||
|
|
||||||
|
|
||||||
save = False
|
save = False
|
||||||
cancel = False
|
cancel = False
|
||||||
any_choice = False
|
any_choice = False
|
||||||
@ -369,7 +358,6 @@ def chooseImages():
|
|||||||
return (choices, save)
|
return (choices, save)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def saveImages(choices):
|
def saveImages(choices):
|
||||||
local = datetime.datetime.now()
|
local = datetime.datetime.now()
|
||||||
session_age = (monotonic_time() - session_start)
|
session_age = (monotonic_time() - session_start)
|
||||||
@ -399,7 +387,6 @@ def saveImages(choices):
|
|||||||
copyfile(path_original, path_todo)
|
copyfile(path_original, path_todo)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
waitForBegin()
|
waitForBegin()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user