forked from pvx/litsimaja
Add tempo, live status
This commit is contained in:
@@ -4,7 +4,8 @@ import sys
|
||||
|
||||
import lib.ProgramLoading as Pl
|
||||
from lib.Litsimaja import Litsimaja
|
||||
from flask import Flask, request, Response, render_template
|
||||
from flask import Flask, request, Response, render_template, json
|
||||
from flask_accept import accept
|
||||
|
||||
# logging
|
||||
logger = logging.getLogger('litsimaja')
|
||||
@@ -20,27 +21,35 @@ logger.addHandler(stdout_handler)
|
||||
# start litsimaja
|
||||
lm = Litsimaja()
|
||||
app = Flask(__name__, static_url_path='', static_folder='templates')
|
||||
Pl.run('siinus', 'Wipes', lm, logger, {'color': [0, 0, 0]})
|
||||
Pl.run('peter', 'DiskoPidu', lm, logger, {})
|
||||
|
||||
|
||||
def lm_standard_xhr_response() -> Response:
|
||||
return Response(response=json.dumps(lm.build_status_array()), status=200, mimetype='application/json')
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def respondroot():
|
||||
@accept('text/html')
|
||||
def respond_root():
|
||||
return render_template(
|
||||
'index.html',
|
||||
programs=Pl.list_all(True),
|
||||
regions=lm.get_region_ids(),
|
||||
status=lm.build_status_array()
|
||||
)
|
||||
|
||||
|
||||
@app.route('/run')
|
||||
def run():
|
||||
Pl.run('siinus', 'MyProgram', lm, logger, {'color': [50, 50, 50]})
|
||||
return Response(status=200)
|
||||
@app.route('/status', methods=['GET'])
|
||||
@accept('application/json')
|
||||
def respond_status():
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
@app.route('/crash', methods=['GET'])
|
||||
def crash():
|
||||
lm.clear_loops()
|
||||
return Response(status=200)
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
@app.route('/program/<program>', methods=['POST'])
|
||||
@@ -48,13 +57,26 @@ def run_program(program):
|
||||
args = request.get_json(force=True)
|
||||
prg = program.split('.')
|
||||
Pl.run(prg[0], prg[1], lm, logger, args)
|
||||
return Response(status=200)
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
@app.route('/region/<region>', methods=['GET'])
|
||||
def switch_region(region):
|
||||
lm.switch_region(int(region))
|
||||
return Response(status=200)
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
@app.route('/tempo/set/<float:bpm>', methods=['GET'])
|
||||
def set_tempo(bpm: float):
|
||||
tempo = lm.get_tempo()
|
||||
tempo.set_bpm(bpm)
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
@app.route('/tempo/sync', methods=['GET'])
|
||||
def sync_beat():
|
||||
lm.get_tempo().sync_beat()
|
||||
return lm_standard_xhr_response()
|
||||
|
||||
|
||||
app.run('0.0.0.0', 8080)
|
||||
|
||||
Reference in New Issue
Block a user