module example import StdEnv import Data.Func import iTasks import mTask.Interpret import mTask.Interpret.Device.TCP import mTask.Interpret.Device.Serial 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}*/ autoHome :: Task ()/*\label{lst:example:task1}*/ autoHome = withDevice arduino \dev1-> /*\label{lst:example:conn1}*/ withDevice nodeMCU \dev2-> /*\label{lst:example:conn2}*/ parallel [(Embedded, chooseTask dev1 dev2)] [] <<@ ArrangeWithTabs True/*\label{lst:example:par1}*/ >>* [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"] <<@ Hint "Which device?" >>? \device->appendTask Embedded (mkTask n i device) stl >-| chooseTask dev1 dev2 stl where mkTask n i device stl # dev = if (device == "node") dev2 dev1 = ((snd (tasks !! i) $ dev) >>* [OnAction ActionClose $ always $ return ()]) <<@ Title n/*\label{lst:example:ct2}*/ tasks :: [(String, MTDevice -> Task ())]/*\label{lst:example:tasks1}*/ tasks = [ ("temp", \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-> withShared False \sh-> liftmTask (lightswitch sh) dev -|| updateSharedInformation [] sh <<@ Hint "Switch") , ("factorial", \dev-> 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 ())}