Fixed python variables

This commit is contained in:
Jake Hillion 2020-04-28 13:58:16 +01:00
parent 34286c4877
commit 53bbff3217

View File

@ -6,16 +6,16 @@ import serial
app = Flask(__name__)
data = ""
lock = threading.Lock()
globals()['data'] = ""
globals()['lock'] = threading.Lock()
@app.route('/update', methods=['PUT'])
def update():
grid = request.json['data']
grid_string = prepare_grid(grid)
with lock:
data = grid_string
with globals()['lock']:
globals()['data'] = grid_string
return grid_string
@ -35,10 +35,10 @@ def prepare_grid(grid):
def serial_func():
with serial.Serial('/dev/ttyACM0', 9600, timeout=1) as ser:
with lock:
if data != '':
serial.write(bytes(data, 'ascii'))
data = ''
with globals()['lock']:
if globals()['data'] != '':
serial.write(bytes(globals()['data'], 'ascii'))
globals()['data'] = ''
serial_thread = threading.Thread(target=serial_func)
serial_thread.start()