Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a460f7b54 | |||
| 50a3d6f29f | |||
| 0e23e048da |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
/.idea/
|
||||
/venv/
|
||||
|
||||
/images/
|
||||
/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.
23974
get-pip.py
23974
get-pip.py
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
INTERVAL="10"
|
||||
|
||||
while true; do
|
||||
uploads="$(find "$(dirname "$0")/images/0-CURRENT/upload" -maxdepth 1 -type f -name '*.jpg')"
|
||||
if [ "$uploads" != "" ]; then
|
||||
scp $uploads root@10.17.0.2:/root/monitor/images && rm -f $uploads
|
||||
fi
|
||||
sleep $INTERVAL
|
||||
done
|
||||
83
photobox.py
83
photobox.py
@ -1,22 +1,28 @@
|
||||
#!/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 imp
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
from math import floor
|
||||
import RPi.GPIO as GPIO
|
||||
from shutil import copyfile
|
||||
from time import sleep
|
||||
|
||||
import picamera
|
||||
import pygame
|
||||
import random
|
||||
import time
|
||||
|
||||
# ~ import server
|
||||
|
||||
from PIL import Image
|
||||
|
||||
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"]
|
||||
|
||||
@ -24,16 +30,19 @@ 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 +51,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
|
||||
@ -74,16 +80,12 @@ THUMB_HEIGHT = int(THUMB_WIDTH / 1.333)
|
||||
|
||||
IMAGES_ORIGINAL = os.path.join(IMAGE_DIR, "original")
|
||||
IMAGES_TODO = os.path.join(IMAGE_DIR, "todo")
|
||||
IMAGES_UPLOAD = os.path.join(IMAGE_DIR, "upload")
|
||||
|
||||
|
||||
|
||||
# global variables
|
||||
spot_mode = 0
|
||||
session_start = monotonic_time()
|
||||
|
||||
|
||||
|
||||
# GPIO helpers
|
||||
|
||||
def led_border(state):
|
||||
@ -103,14 +105,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)
|
||||
@ -137,18 +137,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)
|
||||
@ -158,6 +155,7 @@ def _load(name):
|
||||
|
||||
gfx[name] = (img, rect)
|
||||
|
||||
|
||||
_load("begin")
|
||||
_load("loading")
|
||||
_load("yes")
|
||||
@ -167,8 +165,6 @@ _load("end_no")
|
||||
_load("saved")
|
||||
_load("canceled")
|
||||
|
||||
|
||||
|
||||
# LOAD COUNTDOWN OVERLAYS
|
||||
img_cdn = []
|
||||
pad_cdn = []
|
||||
@ -186,7 +182,6 @@ for i in range(0, COUNTDOWN):
|
||||
pad_cdn.append(pad)
|
||||
|
||||
|
||||
|
||||
# FUNCTIONS ========================================================================================
|
||||
|
||||
def waitForEvent():
|
||||
@ -202,7 +197,6 @@ def waitForEvent():
|
||||
return events
|
||||
|
||||
|
||||
|
||||
def waitForTouch():
|
||||
pos = (-1, -1)
|
||||
while True:
|
||||
@ -214,7 +208,6 @@ def waitForTouch():
|
||||
return pos
|
||||
|
||||
|
||||
|
||||
def maintainance():
|
||||
screen.fill(COLOR_BACK)
|
||||
screen.blit(maintain, maintain_rect)
|
||||
@ -224,7 +217,6 @@ def maintainance():
|
||||
pos = waitForTouch()
|
||||
|
||||
|
||||
|
||||
def waitForBegin():
|
||||
screen.fill(COLOR_BACK)
|
||||
screen.blit(*gfx["begin"])
|
||||
@ -232,21 +224,19 @@ def waitForBegin():
|
||||
|
||||
# wait
|
||||
pos = waitForTouch()
|
||||
# if pos[0] > 720 and pos[1] > 400:
|
||||
# maintainance()
|
||||
|
||||
if pos[0] > 720 and pos[1] > 400:
|
||||
maintainance()
|
||||
|
||||
|
||||
def countdown(camera, pad, img):
|
||||
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.layer = 3
|
||||
sleep(TEXT_INTERVAL)
|
||||
camera.remove_overlay(o)
|
||||
|
||||
|
||||
|
||||
def makePhotos():
|
||||
# CLEAR SCREEN
|
||||
screen.fill(COLOR_BACK)
|
||||
@ -257,7 +247,7 @@ def makePhotos():
|
||||
camera.vflip = False
|
||||
camera.hflip = True
|
||||
camera.resolution = (2592, 1944)
|
||||
camera.rotation = 0
|
||||
camera.rotation = 90
|
||||
camera.start_preview()
|
||||
|
||||
# COUNTDOWN
|
||||
@ -285,7 +275,6 @@ def makePhotos():
|
||||
camera.close()
|
||||
|
||||
|
||||
|
||||
def chooseImages():
|
||||
# clear screen
|
||||
screen.fill(COLOR_BACK)
|
||||
@ -302,7 +291,7 @@ def chooseImages():
|
||||
img = pygame.transform.scale(img, (THUMB_WIDTH, THUMB_HEIGHT))
|
||||
rect = img.get_rect()
|
||||
rect.x = x
|
||||
rect.y = 120
|
||||
rect.y = 146
|
||||
|
||||
img_tmp.append(img)
|
||||
rect_tmp.append(rect)
|
||||
@ -310,7 +299,6 @@ def chooseImages():
|
||||
|
||||
x = x + THUMB_WIDTH + BORDER
|
||||
|
||||
|
||||
save = False
|
||||
cancel = False
|
||||
any_choice = False
|
||||
@ -338,7 +326,7 @@ def chooseImages():
|
||||
(img, rect) = gfx["no"]
|
||||
|
||||
rect.x = x + (THUMB_WIDTH - rect.width) / 2
|
||||
rect.y = 300
|
||||
rect.y = 340
|
||||
screen.blit(img, rect)
|
||||
|
||||
x = x + THUMB_WIDTH + BORDER
|
||||
@ -348,13 +336,13 @@ def chooseImages():
|
||||
|
||||
# wait for new event (touch screen / mouse / keyboard)
|
||||
pos = waitForTouch()
|
||||
if pos[1] < 400:
|
||||
if pos[1] > 140:
|
||||
# toggle image
|
||||
i = int(floor((pos[0] - BORDER / 2) / (THUMB_WIDTH + BORDER)))
|
||||
if i >= 0 and i < SHOT_COUNT:
|
||||
choices[i] = (choices[i] + 1) % 2
|
||||
|
||||
elif pos[1] > 420:
|
||||
elif pos[1] < 100:
|
||||
# top menu buttons
|
||||
if pos[0] > 0 and pos[0] < 266:
|
||||
cancel = True
|
||||
@ -370,7 +358,6 @@ def chooseImages():
|
||||
return (choices, save)
|
||||
|
||||
|
||||
|
||||
def saveImages(choices):
|
||||
local = datetime.datetime.now()
|
||||
session_age = (monotonic_time() - session_start)
|
||||
@ -385,11 +372,6 @@ def saveImages(choices):
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
try:
|
||||
os.makedirs(IMAGES_UPLOAD)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
print("saving images...")
|
||||
for i in range(0, SHOT_COUNT):
|
||||
if choices[i] > 0:
|
||||
@ -400,12 +382,9 @@ def saveImages(choices):
|
||||
path_tmp = "tmp%s.jpg" % i
|
||||
path_original = os.path.join(IMAGES_ORIGINAL, filename)
|
||||
path_todo = os.path.join(IMAGES_TODO, filename)
|
||||
path_upload = os.path.join(IMAGES_UPLOAD, filename)
|
||||
|
||||
os.rename(path_tmp, path_original)
|
||||
copyfile(path_original, path_todo)
|
||||
os.rename(path_todo, path_upload)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from escpos.printer import Serial
|
||||
|
||||
printer = Serial(devfile='/dev/usb/lp0', baudrate=9600)
|
||||
|
||||
printer.text("Test")
|
||||
printer.qr("https://fotobox.online/")
|
||||
printer.cut()
|
||||
58
upload-daemon.sh
Executable file
58
upload-daemon.sh
Executable file
@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIRNAME=$(dirname "$0")
|
||||
REALPATH=$(realpath "$DIRNAME")
|
||||
|
||||
INTERVAL="10"
|
||||
FAILURE_PAUSE="10"
|
||||
IMAGE_PATH="$REALPATH/images/0-CURRENT"
|
||||
|
||||
BASE_URL="https://fotobox.online/upload"
|
||||
#BASE_URL="http://fotobox.online:8888/upload"
|
||||
#BASE_URL="http://10.50.0.30:8888/upload"
|
||||
|
||||
FOTOBOX_ID="B8:27:EB:AA:C9:8F"
|
||||
FOTOBOX_KEY="eDAOMohrcJY3"
|
||||
|
||||
while true; do
|
||||
date=$(date +'%Y-%m-%d %H:%M:%S')
|
||||
|
||||
cd "$IMAGE_PATH"
|
||||
mkdir "todo" 2> /dev/null
|
||||
mkdir "upload" 2> /dev/null
|
||||
mkdir "lowres" 2> /dev/null
|
||||
|
||||
cd "$IMAGE_PATH/todo"
|
||||
todos="$(find . -maxdepth 1 -type f -name '*.jpg')"
|
||||
if [ "$todos" != "" ]; then
|
||||
echo "$date: converting:"
|
||||
for todo in $todos; do
|
||||
echo -n " - '$todo' ... "
|
||||
( convert "$todo" -resize 1000x -quality 0.7 "../lowres/$todo" && cp "../lowres/$todo" "../upload/$todo" && rm -f "$todo" && echo "OK" ) || echo "ERROR"
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
|
||||
cd "$IMAGE_PATH/upload"
|
||||
uploads="$(find . -maxdepth 1 -type f -name '*.jpg')"
|
||||
if [ "$uploads" != "" ]; then
|
||||
echo "$date: uploading:"
|
||||
for upload in $uploads; do
|
||||
echo -n " - '$upload' ... "
|
||||
timestamp_fotobox=$(date +'%Y-%m-%dT%H:%M:%S.%N%z')
|
||||
timestamp_shot=$(basename "$upload" | sed 's|.jpg||g')
|
||||
url="$BASE_URL/$FOTOBOX_ID/$FOTOBOX_KEY/$timestamp_fotobox/$timestamp_shot/"
|
||||
result=$(curl -s --form "image=@$upload" "$url" 2>&1)
|
||||
echo "$result"
|
||||
if [ "$result" == "OK" ]; then
|
||||
rm -f "$upload"
|
||||
else
|
||||
sleep $FAILURE_PAUSE
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# SLEEP
|
||||
sleep $INTERVAL
|
||||
done
|
||||
46
upload.sh
46
upload.sh
@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIRECTORY="/data0/FotoboxSync/0-CURRENT/"
|
||||
|
||||
cd "$(dirname "$0")" || exit 1
|
||||
|
||||
while true; do
|
||||
|
||||
list="$(ls images/0-CURRENT/upload/* 2>/dev/null)"
|
||||
|
||||
if [ "$list" != "" ]; then
|
||||
ssh media@10.0.0.50 mkdir -p $DIRECTORY
|
||||
|
||||
count=$(echo "$list" | wc -l)
|
||||
echo "found $count files"
|
||||
|
||||
sync
|
||||
sleep 3
|
||||
sync
|
||||
|
||||
echo "$list" | while read file; do
|
||||
|
||||
echo "Uploading:"
|
||||
echo "$file"
|
||||
|
||||
scp "$file" media@10.0.0.50:"$DIRECTORY"
|
||||
success="$?"
|
||||
|
||||
if [ "$success" == "0" ]; then
|
||||
echo "OK"
|
||||
rm -f "$file"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
sleep 60
|
||||
|
||||
done
|
||||
Loading…
Reference in New Issue
Block a user