updates
[phd-thesis.git] / top / lst / example.icl
index 7d15baa..4391c86 100644 (file)
@@ -19,10 +19,9 @@ autoHome = withDevice arduino \dev1-> /*\label{lst:example:conn1}*/
        >>* [OnAction (Action "Shutdown") (always (shutDown 0))]/*\label{lst:example:task2}\label{lst:example:par2}*/
 
 chooseTask :: MTDevice MTDevice (SharedTaskList ()) -> Task ()/*\label{lst:example:ct1}*/
-chooseTask dev1 dev2 stl = tune (Title "Run a task")
-       $            enterChoice [] (zip2 [0..] (map fst tasks))
-                       <<@ Hint "Choose a task"
-       >>? \(i, n)->enterChoice [] ["arduino", "node"]
+chooseTask dev1 dev2 stl = tune (Title "Run a task") $
+       enterChoice [] (zip2 [0..] (map fst tasks)) <<@ Hint "Choose a task"
+       >>? \(i, n)->enterChoice [] ["arduino", "node"]/*\label{lst:example:selectdev}*/
                        <<@ Hint "Which device?"
        >>? \device->appendTask Embedded (mkTask n i device) stl
        >-| chooseTask dev1 dev2 stl
@@ -35,21 +34,29 @@ where
 tasks :: [(String, MTDevice -> Task ())]/*\label{lst:example:tasks1}*/
 tasks =
        [ ("temp", \dev->
-               liftmTask ( DHT (DHT_DHT (DigitalPin D6) DHT22) \dht->
-                           {main=temperature dht}) dev
+               liftmTask (
+                               DHT (DHT_DHT (DigitalPin D6) DHT22) \dht->
+                               {main=temperature dht}
+                       ) dev
                >&> \t->viewSharedInformation
                        [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t
-                       <<@ Hint "Current Temperature"
-               @! ())
-       , ("lightswitch", \dev->
+                       <<@ Hint "Current Temperature" @! ())
+       , ("lightswitch", \dev-> /*\label{lst:example:ls1}*/
                withShared False \sh->
-                           liftmTask (lightswitch sh) dev
-                       -|| updateSharedInformation [] sh <<@ Hint "Switch")
+                       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
+                       -|| 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"
-               @! ())
+               >>- \r->viewInformation [] r <<@ Hint "Result" @! ())
        ]
 
 factorial i = {main=rtrn (lit i)}