Adjust capture and add logging

This commit is contained in:
Tanner Collin 2021-03-10 19:22:21 -07:00
parent 19352bf409
commit 738e688c51

View File

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