diff --git a/ueforth/arduino/arduino_server.fs b/ueforth/arduino/arduino_server.fs index dd4a530..6fa6a32 100644 --- a/ueforth/arduino/arduino_server.fs +++ b/ueforth/arduino/arduino_server.fs @@ -106,31 +106,30 @@ window.onload = function() { | constant index-html variable webserver +500 constant out-size +200 stream input-stream +out-size dup stream output-stream +create out-string out-size 1+ allot align : handle-index - ( ." Handling index.html content length" cr - index-html z>s nip webserver @ WebServer.setContentLength ) - ." Handling index.html content length" cr + index-html z>s nip webserver @ WebServer.setContentLength 200 z" text/html" index-html webserver @ WebServer.send - ." Done! Handling index.html" cr ; : handle-input - ." Handling input" cr z" cmd" webserver @ WebServer.hasArg if - ." hasarg" cr - z" cmd" webserver @ WebServer.arg - ." Got: " cr dup . - 2dup type cr - ['] evaluate catch drop - 200 z" text/plain" z" nop" webserver @ WebServer.send + z" cmd" webserver @ WebServer.arg input-stream >stream + out-string out-size output-stream stream> + 200 z" text/plain" out-string webserver @ WebServer.send else - ." not hasarg" cr 500 z" text/plain" z" Missing Input" webserver @ WebServer.send then ; -: serve +: serve-type ( a n -- ) output-stream >stream ; +: serve-key ( -- n ) input-stream stream>ch ; + +: do-serve 80 WebServer.new webserver ! z" /" ['] handle-index webserver @ WebServer.on z" /input" ['] handle-input webserver @ WebServer.on @@ -142,6 +141,14 @@ variable webserver again ; +' do-serve 10 10 task webserver-task + +: serve + ['] serve-type is type + ['] serve-key is key + webserver-task start-task +; + : wifi ( z z -- ) WIFI_MODE_STA Wifi.mode WiFi.begin 1000 ms WiFi.localIP ip. cr diff --git a/ueforth/common/streams.fs b/ueforth/common/streams.fs index 5b74c47..3bd862b 100644 --- a/ueforth/common/streams.fs +++ b/ueforth/common/streams.fs @@ -18,3 +18,7 @@ r@ >read @ 1+ r@ @ mod r> >read ! ; : >stream ( a n st -- ) swap 0 do over c@ over ch>stream swap 1+ swap loop 2drop ; +: stream> ( a n st -- ) + begin over 1 > over empty? 0= and while + ." ch " + dup stream>ch >r rot dup r> swap c! 1+ rot 1- rot repeat 2drop 0 swap c! ; diff --git a/ueforth/common/tasks.fs b/ueforth/common/tasks.fs index bcf72bd..0b39205 100644 --- a/ueforth/common/tasks.fs +++ b/ueforth/common/tasks.fs @@ -1,8 +1,14 @@ ( Cooperative Tasks ) +: task ( xt rsz dsz "name" ) + create here >r 0 , 0 , 0 , + here cell+ r@ cell+ ! cells allot + here r@ 2 cells + ! cells allot + dup 0= if drop else >:body r@ 2 cells + @ ! then rdrop ; + variable task-list -: add-task ( t -- ) +: start-task ( t -- ) task-list @ if task-list @ @ over ! task-list @ ! @@ -12,13 +18,6 @@ variable task-list then ; -: task ( xt rsz dsz "name" ) - create here >r 0 , 0 , 0 , - here cell+ r@ cell+ ! cells allot - here r@ 2 cells + ! cells allot - dup 0= if drop else >:body r@ 2 cells + @ ! then - r> add-task ; - : pause rp@ task-list @ 2 cells + ! sp@ task-list @ cell+ ! @@ -27,4 +26,4 @@ variable task-list task-list @ 2 cells + @ rp! ; -0 0 0 task main-task +0 0 0 task main-task main-task start-task