From: Mart Lubbers Date: Sat, 28 Jan 2017 13:20:47 +0000 (+0100) Subject: add instant one-stop tasks, still working X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=5395787218cef80cc3c165ec24af2f367a3d0d16;p=mTask.git add instant one-stop tasks, still working --- diff --git a/int/interface.h b/int/interface.h index 5a506b9..d3361df 100644 --- a/int/interface.h +++ b/int/interface.h @@ -12,6 +12,7 @@ extern char **gargv; #define read16() 256*(uint8_t)read_byte() + (uint8_t)read_byte() #define from16(a, b) 256*a+b +#define write16(i) { write_byte((uint8_t)i/256); write_byte((uint8_t)i%256); } uint8_t read_byte(void); void write_byte(uint8_t b); diff --git a/int/main.c b/int/main.c index 00c9f82..3388f21 100644 --- a/int/main.c +++ b/int/main.c @@ -44,7 +44,7 @@ void read_message(void) debug("Receiving a task"); ct = task_register(); write_byte('t'); - write_byte(ct+'0'); + write16(ct); write_byte('\n'); break; case '\0': @@ -81,6 +81,13 @@ void loop(void) debug("Current task to run: %d", ct); run_task(curtask); curtask->lastrun = cyclestart; + if(curtask->interval == 0){ + curtask->used = false; + write_byte('m'); + write_byte('d'); + write_byte('\n'); + } + write_byte('\n'); } } diff --git a/int/sds.c b/int/sds.c index 90617b1..c5f69b6 100644 --- a/int/sds.c +++ b/int/sds.c @@ -65,10 +65,8 @@ void sds_publish(int id) if(sdss[cs].used && sdss[cs].id == id){ debug("Publish %d=%d", sdss[cs].id, sdss[cs].value); write_byte('u'); - write_byte(0); - write_byte(sdss[cs].id); - write_byte(sdss[cs].value/265); - write_byte(sdss[cs].value%265); + write16(sdss[cs].id); + write16(sdss[cs].value); write_byte('\n'); return; } diff --git a/int/task.c b/int/task.c index 3280b1e..4ac8ce5 100644 --- a/int/task.c +++ b/int/task.c @@ -46,10 +46,6 @@ int task_register(void) debug("Received a task of length %d", tasks[ct].tlen); tasks[ct].used = true; tasks[ct].lastrun = 0L; -// write_byte('t'); -// write_byte(0); -// write_byte(ct); -// write_byte('\n'); return ct; } diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index dca53d4..180939c 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -27,7 +27,6 @@ encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" -import StdDebug decode :: String -> MTaskMSGRecv decode x | size x == 0 = MTEmpty diff --git a/miTask.icl b/miTask.icl index 92fbff2..18c78c8 100644 --- a/miTask.icl +++ b/miTask.icl @@ -39,21 +39,22 @@ bc = sds \x=1 In sds \pinnetje=1 In {main = noOp ) :. IF (pinnetje ==. lit 1) ( - digitalWrite D0 (lit True) :. - digitalWrite D1 (lit False) :. - digitalWrite D2 (lit False) + digitalWrite D0 (lit True) ) ( IF (pinnetje ==. lit 2) ( - digitalWrite D0 (lit False) :. - digitalWrite D1 (lit True) :. - digitalWrite D2 (lit False) + digitalWrite D1 (lit True) ) ( - digitalWrite D0 (lit False) :. - digitalWrite D1 (lit False) :. digitalWrite D2 (lit True) ) )} +bc2 :: DigitalPin -> Main (ByteCode () Stmt) +bc2 d = {main = digitalWrite d (lit True) :. noOp} + +bc3 :: DigitalPin -> Main (ByteCode () Stmt) +bc3 d = {main = digitalWrite d (lit False) :. noOp} + + withDevice :: ((Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task a) -> Task a | iTask a withDevice t = withShared ([], [], False) \ch-> enterInformation "Type" [] @@ -74,14 +75,17 @@ withDevice t = withShared ([], [], False) \ch-> mTaskTask :: Task () mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in - withDevice (\ch-> + withDevice \ch-> sendMsg msgs ch ||- processMessages ch messageShare sdsShares + ||- forever (enterChoice "Choose led to enable" [] [D0, D1, D2] + >>= \p->sendMsg (fst (makeMsgs 0 (bc2 p))) ch) + ||- forever (enterChoice "Choose led to disable" [] [D0, D1, D2] + >>= \p->sendMsg (fst (makeMsgs 0 (bc3 p))) ch) ||- viewSharedInformation "channels" [ViewWith lens] ch ||- viewSharedInformation "messages" [] messageShare ||- viewSh sdsShares ch >>* [OnAction ActionFinish (always shutDown)] - ) where messageShare :: Shared [String] messageShare = sharedStore "mTaskMessagesRecv" [] @@ -103,11 +107,13 @@ mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in dd [x,y] = toInt x*265 + toInt y updateSDSs :: [(Int, Shared Int)] (Shared [String]) MTaskMSGRecv -> Task () - updateSDSs _ m (MTMessage s) = upd (\l->take 20 [s:l]) m @! () updateSDSs [(id, sh):xs] m n=:(MTPub i d) | id == i = set ((toInt d.[0])*265 + toInt d.[1]) sh @! () = updateSDSs xs m n - updateSDSs _ _ _ = return () + updateSDSs _ m mtm = case mtm of + MTMessage s = upd (\l->take 20 [s:l]) m @! () + mta=:(MTTaskAdded _) = upd (\l->take 20 [toString mta:l]) m @! () + _ = return () lens :: ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> ([String], [String]) lens (r,s,_) = (map toString r, map toString s)