the user --- and they are then connected. When all devices are registered, the
\gls{mTask}-\glspl{Task} can be sent and \gls{iTasks}-\glspl{Task} can be
started to monitor the output. When everything is finished, the devices are
-removed and the system is shut down.
+removed and the system is shut down. To illustrate this, a demo blinking
+application is shown in Listing~\ref{lst:frameword}. The application is a
+complete \gls{iTasks} application.
\begin{lstlisting}[language=Clean,label={lst:framework},
caption={\gls{mTask} framework for building applications}]
-w :: Task ()
-w = makeDevice "dev1" (...) >>= connectDevice
- >>= \dev1->makeDevice "dev2" (...) >>= connectDevice
- >>= \dev2->...
- ...
- >>* [OnAction (Action "Shutdown") $ always
- $ deleteDevice dev1 >>| deleteDevice dev2
- >>| ...
- >>| shutDown 0
+module blinkdemo
+
+import iTasks
+import mTask
+import Devices.mTaskDevice
+
+from Data.Func import $
+
+Start world = startEngine blink world
+
+blink :: Task ()
+blink = addDevice
+ >>= connectDevice
+ >>= \stm->sendTaskToDevice "blink" blinkTask (stm, OnInterval 1000)
+ >>= \(st, [_,t])->forever (
+ updateSharedInformation "Which led to blink" [] (shareShare stm t)
+ ) >>* [OnAction (Action "Shutdown") $ always
+ $ deleteDevice stm >>| shutDown 0
]
+where
+ blinkTask = sds \led=LED1 In sds \x=True In {main =
+ ledOff led1 :. ledOff led2 :. ledOff led3 :.
+ IF x (ledOff led) (ledOn led) :.
+ x =. Not x}
\end{lstlisting}
\subsection{Thermostat}
\frametitle{Example, blink}
\begin{lstlisting}[language=Clean]
blink :: Task ()
-blink = makeDevice "stm32" stm32 >>= connectDevice
- >>= \stm-> sendTaskToDevice "blink" blinkTask (stm, OnInterval 1000)
- >>= \(st, [t:_])->forever (
+blink = addDevice
+ >>= connectDevice
+ >>= \stm->sendTaskToDevice "blink" blinkTask (stm, OnInterval 1000)
+ >>= \(st, [_,t])->forever (
updateSharedInformation "Which led to blink" [] (shareShare stm t)
) >>* [OnAction (Action "Shutdown") $ always
$ deleteDevice stm >>| shutDown 0
]
where
- stm32 = makeDevice "Stm32"
- (SerialDevice {devicePath="/dev/ttyUSB0", baudrate=B9600, ...}
blinkTask = sds \led=LED1 In sds \x=True In {main =
- ledOn LED1 :. ledOn LED2 :. ledOn LED3 :.
- IF x (ledOff led) (ledOn led) :.
- x =. Not x
- }
-
+ ledOff led1 :. ledOff led2 :. ledOff led3 :.
+ IF x (ledOff led) (ledOn led) :.
+ x =. Not x}
\end{lstlisting}
\end{frame}