|
|
@ -5,6 +5,8 @@ import signal
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from pyA20.gpio import gpio, port
|
|
|
|
from pyA20.gpio import gpio, port
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
@ -13,7 +15,11 @@ except ImportError:
|
|
|
|
class Tmpobj():
|
|
|
|
class Tmpobj():
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
port = Tmpobj()
|
|
|
|
port = Tmpobj()
|
|
|
|
port.PG0 = 42
|
|
|
|
port.PB3 = 42
|
|
|
|
|
|
|
|
port.PB4 = 42
|
|
|
|
|
|
|
|
port.PB5 = 42
|
|
|
|
|
|
|
|
port.PB6 = 42
|
|
|
|
|
|
|
|
port.PB7 = 42
|
|
|
|
|
|
|
|
|
|
|
|
from bureau import Bureau, add_api
|
|
|
|
from bureau import Bureau, add_api
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +33,11 @@ class Photography(Bureau):
|
|
|
|
name = "Photography Dept."
|
|
|
|
name = "Photography Dept."
|
|
|
|
prefix = "PX"
|
|
|
|
prefix = "PX"
|
|
|
|
version = 0
|
|
|
|
version = 0
|
|
|
|
doc_light_pin = port.PG0
|
|
|
|
landscape_pin = port.PB3
|
|
|
|
|
|
|
|
a3_pin = port.PB4
|
|
|
|
|
|
|
|
a4_pin = port.PB5
|
|
|
|
|
|
|
|
a5_pin = port.PB6
|
|
|
|
|
|
|
|
doc_light_pin = port.PB7
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
Bureau.__init__(self)
|
|
|
|
Bureau.__init__(self)
|
|
|
@ -37,6 +47,16 @@ class Photography(Bureau):
|
|
|
|
gpio.setcfg(self.doc_light_pin, gpio.OUTPUT)
|
|
|
|
gpio.setcfg(self.doc_light_pin, gpio.OUTPUT)
|
|
|
|
gpio.output(self.doc_light_pin, gpio.LOW)
|
|
|
|
gpio.output(self.doc_light_pin, gpio.LOW)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set pins and pullups for switches
|
|
|
|
|
|
|
|
gpio.setcfg(self.landscape_pin, gpio.INPUT)
|
|
|
|
|
|
|
|
gpio.pullup(self.landscape_pin, gpio.PULLUP)
|
|
|
|
|
|
|
|
gpio.setcfg(self.a3_pin, gpio.INPUT)
|
|
|
|
|
|
|
|
gpio.pullup(self.a3_pin, gpio.PULLUP)
|
|
|
|
|
|
|
|
gpio.setcfg(self.a4_pin, gpio.INPUT)
|
|
|
|
|
|
|
|
gpio.pullup(self.a4_pin, gpio.PULLUP)
|
|
|
|
|
|
|
|
gpio.setcfg(self.a5_pin, gpio.INPUT)
|
|
|
|
|
|
|
|
gpio.pullup(self.a5_pin, gpio.PULLUP)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _doc_light_on(self):
|
|
|
|
def _doc_light_on(self):
|
|
|
|
gpio.output(self.doc_light_pin, gpio.HIGH)
|
|
|
|
gpio.output(self.doc_light_pin, gpio.HIGH)
|
|
|
@ -83,7 +103,34 @@ class Photography(Bureau):
|
|
|
|
filelist[i] = os.path.join("/tmp/webcam", f)
|
|
|
|
filelist[i] = os.path.join("/tmp/webcam", f)
|
|
|
|
newest = max(filelist, key=lambda x: os.stat(x).st_mtime)
|
|
|
|
newest = max(filelist, key=lambda x: os.stat(x).st_mtime)
|
|
|
|
shutil.copyfile(newest, tmpimg.name)
|
|
|
|
shutil.copyfile(newest, tmpimg.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# crop
|
|
|
|
|
|
|
|
img = Image.open(tmpimg.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#TODO: crop here to trim calibrated extra pixels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xsize, ysize = img.size
|
|
|
|
|
|
|
|
if gpio.input(self.a3_pin) == 0:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
if gpio.input(self.a4_pin) == 0:
|
|
|
|
|
|
|
|
offset = (xsize - ysize) / 2
|
|
|
|
|
|
|
|
box = (offset, 0, (offset + ysize), xsize / 2)
|
|
|
|
|
|
|
|
img = img.crop(box)
|
|
|
|
|
|
|
|
elif gpio.input(self.a5_pin) == 0:
|
|
|
|
|
|
|
|
offset = xsize / 4
|
|
|
|
|
|
|
|
box = (offset, 0, (offset + (xsize / 2)), ysize / 2)
|
|
|
|
|
|
|
|
img = img.crop(box)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
offset = (xsize - (ysize / 2)) / 2
|
|
|
|
|
|
|
|
box = (offset, 0, (offset + (ysize / 2)), xsize / 4)
|
|
|
|
|
|
|
|
img = img.crop(box)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# rotate
|
|
|
|
|
|
|
|
if gpio.input(self.landscape_pin) == 0:
|
|
|
|
|
|
|
|
img = img.transpose(Image.ROTATE_90)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img.save(tmpimg.name)
|
|
|
|
|
|
|
|
img.close()
|
|
|
|
self._doc_light_off()
|
|
|
|
self._doc_light_off()
|
|
|
|
return {"photo": tmpimg.name}
|
|
|
|
return {"photo": tmpimg.name}
|
|
|
|
|
|
|
|
|
|
|
|