diff options
author | next2w | 2022-10-03 19:44:50 -0400 |
---|---|---|
committer | next2w | 2022-10-03 19:45:38 -0400 |
commit | 9a9e7d15d91bc9f7325b4709ce3d041331713f10 (patch) | |
tree | 9464706892029fd71c6c35fa66c5c9b539aa2813 /backend | |
parent | 14e7fe85f0af25200ae29130f9e8355bee4ee62e (diff) |
Fix a crap ton of bugs
Diffstat (limited to 'backend')
-rw-r--r-- | backend/app.py | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/backend/app.py b/backend/app.py index 97f9491..b0c6ade 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6,42 +6,31 @@ import subprocess app = Flask(__name__) -threadFlag = True -def playFunction(freq): - global threadFlag - p = subprocess.Popen(["beep", "-f", freq, "-l", "100000"]) - while not threadFlag: - pass - #print("beep -f %f" % (freq)) - os.kill(p.pid, 15) - -thread2 = 0 +curf = 0 +p = 0 + tc = 0 @app.before_first_request def activate_job(): global tc tc = 0 -@app.route('/startfreq/<freq>') -def freq(freq): - global threadFlag - global thread2 - threadFlag = False - print(freq) - thread2 = Thread(target=playFunction, args=(freq,)) - thread2.start() +@app.route('/startfreq/<f>') +def startfreq(f): + global curf + global p + print(f) + curf = f + p = subprocess.Popen(["beep", "-f", f, "-l", "100000"]).pid return("200") -@app.route('/stopfreq/<freq2>') -def freq2(freq2): - global threadFlag - global thread2 - threadFlag = True +@app.route('/stopfreq/<f>') +def stopfreq(f): + print(f, curf) + if f == curf: + os.kill(p, 15) return("200") if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') - - - |