Adjust capture and add logging
This commit is contained in:
parent
19352bf409
commit
738e688c51
|
@ -5,7 +5,12 @@ from pathlib import Path
|
|||
from flask import Flask, request, abort, send_from_directory
|
||||
from flask_cors import CORS
|
||||
|
||||
import power, capture, download
|
||||
import power, capture, download, settings
|
||||
|
||||
import logging
|
||||
log = logging.getLogger('werkzeug')
|
||||
if not settings.DEBUG:
|
||||
log.setLevel(logging.ERROR)
|
||||
|
||||
build_folder = Path('../client/build')
|
||||
output_folder = Path('./output')
|
||||
|
@ -14,9 +19,10 @@ CORS(app)
|
|||
|
||||
STANDBY = 0
|
||||
WARMUP = 1
|
||||
CAPTURING = 2
|
||||
WRITING = 3
|
||||
DOWNLOADING = 4
|
||||
CAPTURING_PHOTO = 2
|
||||
CAPTURING_GRID = 3
|
||||
WRITING = 4
|
||||
DOWNLOADING = 5
|
||||
|
||||
status = STANDBY
|
||||
|
||||
|
@ -27,7 +33,6 @@ def status_get():
|
|||
@app.route('/api/clients', methods=['POST'])
|
||||
def clients_post():
|
||||
content = request.json
|
||||
print('Recieved:', content)
|
||||
|
||||
phone = str(content['phone'])
|
||||
|
||||
|
@ -45,6 +50,7 @@ def clients_post():
|
|||
|
||||
client_id = folder
|
||||
|
||||
print('POST client:', content, 'cid:', client_id)
|
||||
return {'client_id': client_id}
|
||||
|
||||
@app.route('/api/clients/<cid>', methods=['GET'])
|
||||
|
@ -61,6 +67,7 @@ def clients_get(cid):
|
|||
photo_glob = path.glob('*.jpg')
|
||||
res['has_photos'] = bool(list(photo_glob))
|
||||
|
||||
print('GET client:', cid, 'res:', res)
|
||||
return res
|
||||
|
||||
@app.route('/api/clients/<cid>/session', methods=['GET'])
|
||||
|
@ -90,12 +97,14 @@ def session_delete(cid):
|
|||
for p in photo_glob:
|
||||
p.unlink()
|
||||
|
||||
print('DELETE session:', cid)
|
||||
return ''
|
||||
|
||||
@app.route('/api/clients/<cid>/session', methods=['POST'])
|
||||
def session_post(cid):
|
||||
global status
|
||||
|
||||
print('POST session:', cid)
|
||||
folder = cid
|
||||
path = output_folder / cid
|
||||
|
||||
|
@ -103,14 +112,14 @@ def session_post(cid):
|
|||
abort(404)
|
||||
|
||||
# go through the photo taking process
|
||||
status = WARMUP
|
||||
|
||||
try:
|
||||
# warmup
|
||||
status = WARMUP
|
||||
power.lights_on()
|
||||
time.sleep(4)
|
||||
time.sleep(2)
|
||||
power.lights_off()
|
||||
time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
except BaseException as e:
|
||||
print('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e)))
|
||||
print()
|
||||
|
@ -118,27 +127,30 @@ def session_post(cid):
|
|||
print()
|
||||
abort(500)
|
||||
|
||||
status = CAPTURING
|
||||
|
||||
# capture
|
||||
status = CAPTURING_PHOTO
|
||||
power.lights_on()
|
||||
time.sleep(0.25)
|
||||
capture.trigger_capture()
|
||||
time.sleep(1)
|
||||
power.grid_on()
|
||||
time.sleep(0.25)
|
||||
capture.trigger_capture()
|
||||
time.sleep(1)
|
||||
power.grid_off()
|
||||
power.lights_off()
|
||||
time.sleep(2)
|
||||
|
||||
#status = CAPTURING_GRID
|
||||
#power.grid_on()
|
||||
#time.sleep(2)
|
||||
#capture.trigger_capture()
|
||||
#time.sleep(2)
|
||||
#power.grid_off()
|
||||
|
||||
status = WRITING
|
||||
time.sleep(3)
|
||||
power.lights_off()
|
||||
|
||||
status = DOWNLOADING
|
||||
download.download_all_photos(path)
|
||||
time.sleep(3)
|
||||
|
||||
status = STANDBY
|
||||
print('Finished.')
|
||||
return ''
|
||||
|
||||
@app.route('/')
|
||||
|
|
Loading…
Reference in New Issue
Block a user