From 3fb01671f126462d18b9d29d78c09dd1851cbb39 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 9 Jul 2017 14:10:53 +0200 Subject: [PATCH] update blinking example' --- arch.example.tex | 36 ++++++++++++++++++++++++++---------- pres.system.tex | 17 +++++++---------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/arch.example.tex b/arch.example.tex index b8ef049..7b773ba 100644 --- a/arch.example.tex +++ b/arch.example.tex @@ -4,20 +4,36 @@ pattern. First the devices are created --- with or without the interaction of 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} diff --git a/pres.system.tex b/pres.system.tex index f45abbe..18dc8cf 100644 --- a/pres.system.tex +++ b/pres.system.tex @@ -428,21 +428,18 @@ sendTaskToDevice :: String (Main (ByteCode a Stmt)) (MTaskDevice, MTaskInterval) \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} -- 2.20.1