7 import mTask.Interpret.Device.TCP
8 import mTask.Interpret.Device.Serial
10 Start w = doTasks autoHome w
12 arduino = {TTYSettings | zero & devicePath="/dev/ttyACM0"}/*\label{lst:example:spec1}*/
13 nodeMCU = {TCPSettings | host="192.168.0.1", port=8123, pingTimeout= ?None}/*\label{lst:example:spec2}*/
15 autoHome :: Task ()/*\label{lst:example:task1}*/
16 autoHome = withDevice arduino \dev1-> /*\label{lst:example:conn1}*/
17 withDevice nodeMCU \dev2-> /*\label{lst:example:conn2}*/
18 parallel [(Embedded, chooseTask dev1 dev2)] [] <<@ ArrangeWithTabs True/*\label{lst:example:par1}*/
19 >>* [OnAction (Action "Shutdown") (always (shutDown 0))]/*\label{lst:example:task2}\label{lst:example:par2}*/
21 chooseTask :: MTDevice MTDevice (SharedTaskList ()) -> Task ()/*\label{lst:example:ct1}*/
22 chooseTask dev1 dev2 stl = tune (Title "Run a task") $
23 enterChoice [] (zip2 [0..] (map fst tasks)) <<@ Hint "Choose a task"
24 >>? \(i, n)->enterChoice [] ["arduino", "node"]/*\label{lst:example:selectdev}*/
25 <<@ Hint "Which device?"
26 >>? \device->appendTask Embedded (mkTask n i device) stl
27 >-| chooseTask dev1 dev2 stl
29 mkTask n i device stl = ((snd (tasks !! i) $ dev)
30 >>* [OnAction ActionClose $ always $ return ()]) <<@ Title n/*\label{lst:example:ct2}*/
31 where dev = if (device == "node") dev2 dev1
33 tasks :: [(String, MTDevice -> Task ())]/*\label{lst:example:tasks1}*/
36 liftmTask (DHT (DHT_DHT (DigitalPin D6) DHT22) \dht->
37 {main=temperature dht}
39 >&> \t->viewSharedInformation
40 [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t
41 <<@ Hint "Current Temperature" @! ())
42 , ("lightswitch", \dev-> /*\label{lst:example:ls1}*/
43 withShared False \sh->
44 liftmTask (lightswitch sh) dev
45 -|| updateSharedInformation [] sh <<@ Hint "Switch")/*\label{lst:example:ls2}*/
46 , ("remote computation", \dev->
47 updateInformation [] 5 <<@ Hint "Factorial of what?"
48 >>? \i->liftmTask (factorial i) dev
49 >>- \r->viewInformation [] r <<@ Hint "Result" @! ())
52 factorial :: Int -> Main (MTask v Int) | mtask v
54 fun \fac=(\i->If (i ==. lit 0) (lit 1) (i *. fac (i -. lit 1)))
55 In {main=rtrn (fac (lit i))}
56 blink :: Int -> Main (MTask v ()) | mtask v
58 declarePin D13 PMOutput \d13->
64 lightswitch :: (Shared sds Bool) -> Main (MTask v ()) | lowerSds, mtask v & RWShared sds & TC (sds () Bool Bool)
66 declarePin D13 PMOutput \d13->
70 >>*. [IfValue ((!=.)st) (\v->writeD d13 v)]