Compare commits

...

1 Commits
abgabe ... main

Author SHA1 Message Date
Maximilian Wagner
1bb6b75716 fixes some bugs, untested 2024-04-25 13:15:27 +02:00
3 changed files with 60 additions and 27 deletions

View File

@ -1,4 +1,5 @@
from machine import Pin from machine import Pin
import src.server as server
import src.slave as slave import src.slave as slave
import src.wireless as wireless import src.wireless as wireless
import src.data as data import src.data as data
@ -7,10 +8,8 @@ import src.data as data
wireless.espnow_setup() wireless.espnow_setup()
if data.master: if data.master:
# server has autostart in another _thread server.start()
import src.server as server
Pin(2, Pin.OUT).value(1) Pin(2, Pin.OUT).value(1)
else: else:
Pin(2, Pin.OUT).value(1) slave.loop(Pin(2, Pin.OUT).value(1))
slave.loop()

View File

@ -67,23 +67,33 @@ def docs(con, _):
@app.route("GET", "/definition") @app.route("GET", "/definition")
def definition(con, request: HTTPRequest): def definition(con, request: HTTPRequest):
# Get slave and tm definition from request and send off # Get slave and tm definition from request and send off
tm = "DEFINE:" + unescape(str(request.parameters.get("tm"))) para_tm = request.parameters.get("tm")
slave_num = int(str(request.parameters.get("select_slave"))[6:]) -1 para_slave = request.parameters.get("select_slave")
slave = data.slave_list[slave_num]
if para_tm != None and para_slave != None:
tm = "DEFINE:" + unescape(str(para_tm))
slave_num = int(str(para_slave)[6:]) -1
slave = data.slave_list[slave_num]
print(tm)
espnow_send(slave, tm)
print(tm)
espnow_send(slave, tm)
HTTPResponse(con, 302).redirect("/") HTTPResponse(con, 302).redirect("/")
@app.route("GET", "/input") @app.route("GET", "/input")
def input(con, request: HTTPRequest): def input(con, request: HTTPRequest):
# Get slave and input band from request and send off para_band = request.parameters.get("band")
band = "BAND:" + str(request.parameters.get("band")) para_ss = request.parameters.get("select_slave")
slave_num = int(str(request.parameters.get("select_slave"))[6:]) -1
slave = data.slave_list[slave_num] if para_band != None and para_ss != None:
# Get slave and input band from request and send off
band = "BAND:" + str(para_band)
slave_num = int(str(para_ss)[6:]) -1
slave = data.slave_list[slave_num]
espnow_send(slave, band)
espnow_send(slave, band)
HTTPResponse(con, 302).redirect("/") HTTPResponse(con, 302).redirect("/")
@ -92,14 +102,18 @@ def run(con, request: HTTPRequest):
# use builder to incorporate that into response # use builder to incorporate that into response
global status global status
select_slave = str(request.parameters.get("select_slave")) select_slave = request.parameters.get("select_slave")
if "Slave" in select_slave: if select_slave != None:
status["slave_selected"]["value"] = unescape(select_slave) select_slave = str(select_slave)
if "Slave" in select_slave:
status["slave_selected"]["value"] = unescape(select_slave)
# Go to simulator page where you can run all or step through # Go to simulator page where you can run all or step through
HTTPResponse(con, 200, "HTML").send_raw( HTTPResponse(con, 200, "HTML").send_raw(
HTMLBuilder(["html/head.html", "html/run.html"], status).build() HTMLBuilder(["html/head.html", "html/run.html"], status).build()
) )
HTTPResponse(con, 302).redirect("/")
@app.route("GET", "/run_all") @app.route("GET", "/run_all")
@ -129,9 +143,15 @@ def run_step(con, _):
@app.route("GET", "/pass") @app.route("GET", "/pass")
def pass_band(con, request: HTTPRequest): def pass_band(con, request: HTTPRequest):
para_sfrom = request.parameters.get("select_slave")
para_sto = request.parameters.get("to_slave")
if para_sfrom == None or para_sto == None:
HTTPResponse(con, 302).redirect("/")
try: try:
slave_from = int(str(request.parameters.get("select_slave"))[6:]) -1 slave_from = int(str(para_sfrom)[6:]) -1
slave_to = int(str(request.parameters.get("to_slave"))[6:]) -1 slave_to = int(str(para_sto)[6:]) -1
slave_from = data.slave_list[slave_from] slave_from = data.slave_list[slave_from]
slave_to = data.slave_list[slave_to] slave_to = data.slave_list[slave_to]
@ -152,7 +172,6 @@ def result(con, _):
# and also endresult of computation chain # and also endresult of computation chain
result_list = [] result_list = []
for i in range(0, len(data.slave_list)): for i in range(0, len(data.slave_list)):
print("test: ", i)
# todo: parse result_dict of src.data to display res # todo: parse result_dict of src.data to display res
while not espnow_send(data.slave_list[i], "RESULT"): while not espnow_send(data.slave_list[i], "RESULT"):
pass pass
@ -189,6 +208,6 @@ def reset(con, _):
HTTPResponse(con, 302).redirect("/run") HTTPResponse(con, 302).redirect("/run")
def start() -> None:
_thread.start_new_thread(app.start, ()) _thread.start_new_thread(app.start, ())

View File

@ -1,3 +1,5 @@
import _thread
from time import sleep
from src.wireless import espnow_send, espnow_recv, espnow_recv_raw from src.wireless import espnow_send, espnow_recv, espnow_recv_raw
from lib.tm_sim import TuringMachine as TM from lib.tm_sim import TuringMachine as TM
import src.data as data import src.data as data
@ -66,8 +68,17 @@ def __reset() -> None:
print(f"TM:CONFIG:RESET") print(f"TM:CONFIG:RESET")
def __blink(pin) -> None:
pin.value(0)
sleep(.3)
pin.value(1)
sleep(.3)
pin.value(0)
sleep(.3)
pin.value(1)
def loop():
def loop(pin):
display.setup() display.setup()
display.slave() display.slave()
display.draw() display.draw()
@ -75,6 +86,10 @@ def loop():
while True: while True:
msg = espnow_recv() msg = espnow_recv()
# blinking in new _thread for faster execution
# all below cant be done that way because of race conditions
_thread.start_new_thread(__blink, (pin))
if "DEFINE" in msg: if "DEFINE" in msg:
__define(msg.split(':')[1]) __define(msg.split(':')[1])