X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=top%2Flst%2Fexample.icl;h=4bdf9efecf4eaf132d9d96588d140d6149d4698d;hb=c07f3ee029e0cf99b058de8b9f6ccfdab49ee983;hp=4391c86ef8900ab17c1a3f7c67fe03878a82a299;hpb=a32d07a619a22edaf51648683eedef695d7fb28a;p=phd-thesis.git diff --git a/top/lst/example.icl b/top/lst/example.icl index 4391c86..4bdf9ef 100644 --- a/top/lst/example.icl +++ b/top/lst/example.icl @@ -7,7 +7,7 @@ import mTask.Interpret import mTask.Interpret.Device.TCP import mTask.Interpret.Device.Serial -Start w = doTasks autoHome w +//Start w = doTasks autoHome w arduino = {TTYSettings | zero & devicePath="/dev/ttyACM0"}/*\label{lst:example:spec1}*/ nodeMCU = {TCPSettings | host="192.168.0.1", port=8123, pingTimeout= ?None}/*\label{lst:example:spec2}*/ @@ -34,31 +34,44 @@ where tasks :: [(String, MTDevice -> Task ())]/*\label{lst:example:tasks1}*/ tasks = [ ("temp", \dev-> - liftmTask ( - DHT (DHT_DHT (DigitalPin D6) DHT22) \dht-> - {main=temperature dht} + liftmTask (DHT (DHT_DHT (DigitalPin D6) DHT22) \dht-> + {main=temperature dht} ) dev >&> \t->viewSharedInformation - [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t + [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t <<@ Hint "Current Temperature" @! ()) , ("lightswitch", \dev-> /*\label{lst:example:ls1}*/ withShared False \sh-> - liftmTask ( - declarePin D13 PMOutput \d13-> - liftsds \ls=sh - In fun \f=(\st-> - getSds ls - >>*. [IfValue ((!=.)st) (\v->writeD d13 v)] - >>|. f (Not st)) - In {main=f true} - ) dev + liftmTask (lightswitch sh) dev -|| updateSharedInformation [] sh <<@ Hint "Switch")/*\label{lst:example:ls2}*/ , ("factorial", \dev-> - updateInformation [] 5 <<@ Hint "Factorial of what?" + updateInformation [] 5 <<@ Hint "Factorial of what?" >>? \i->liftmTask (factorial i) dev >>- \r->viewInformation [] r <<@ Hint "Result" @! ()) ] -factorial i = {main=rtrn (lit i)} -blink d = {main=writeD (lit d) (lit True)} -lightswitch sh = {main=rtrn (lit ())} +factorial :: Int -> Main (MTask v Int) | mtask v +factorial i = + fun \fac=(\i->If (i ==. lit 0) (lit 1) (i *. fac (i -. lit 1))) + In {main=rtrn (fac (lit i))} +blink :: Int -> Main (MTask v ()) | mtask v +blink d = + declarePin D13 PMOutput \d13-> + fun \bl=(\st-> + writeD d13 st + >>|. delay (lit d) + >>|. bl (Not st)) + In {main=bl true} +lightswitch :: (Shared sds Bool) -> Main (MTask v ()) | liftsds, mtask v & RWShared sds & TC (sds () Bool Bool) +lightswitch sh = + declarePin D13 PMOutput \d13-> + liftsds \ls=sh + In fun \f=(\st-> + getSds ls + >>*. [IfValue ((!=.)st) (\v->writeD d13 v)] + >>|. f (Not st)) + In {main=f true} + +Start w = doTasks t w +t = withShared True \sh-> + updateSharedInformation [] sh <<@ Hint "Light switch"