22363db67d0839d914edcd8c9a4cc20c86a9a19f
[phd-thesis.git] / appx / mtask_aux.tex
1 \documentclass[../thesis.tex]{subfiles}
2
3 \input{subfilepreamble}
4
5
6 \begin{document}
7 \input{subfileprefix}
8 \ifSubfilesClassLoaded{\appendix\setcounter{chapter}{1}}{}
9 \chapter{Auxiliary mTask type classes}%
10 \label{chp:mtask_aux}
11 \lstset{basicstyle=\tt\footnotesize}
12 \section{Peripherals}\label{sec:aux_peripherals}
13 This section shows the peripherals not mentioned in \cref{chp:top4iot}.
14 All constructors use \gls{HOAS} to create a type safe sensor object from a connection specification that can be used to interact with the sensor.
15 The measurement tasks all yield unstable values contaning the measured value.
16 The auxiliary functions such as calibration yield stable values indicating the result.
17 Tasks suffixed with the backtick (\cleaninline{'}) indicate variants for which the timing interval can be specified (see \cref{chp:green_computing_mtask}).
18
19 \subsection{Air quality sensor}
20 The \gls{MTASK} language supports one type (\emph{CCS811} connected via \gls{I2C}) of air quality sensors that measures \gls{TVOC} (\unit{ppm}) and \gls{ECO2} ($\%$).
21 Besides the constructor and tasks for the measurements there is also a calibration task that can be used to calibrate the sensor from temperature and humidity readings to increase the accuracy.
22 The complete interface is shown in \cref{lst:mtask_aqs}.
23
24 \begin{lstClean}[label={lst:mtask_aqs},caption={Air quality sensor interface in \gls{MTASK}.}]
25 :: AirQualitySensor // abstract
26
27 class AirQualitySensor v where
28 airqualitysensor :: I2CAddr ((v AirQualitySensor) -> Main (v a)) -> Main (v a)
29 tvoc` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
30 tvoc :: (v AirQualitySensor) -> MTask v Int
31 co2` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
32 co2 :: (v AirQualitySensor) -> MTask v Int
33 setEnvironmentalData :: (v AirQualitySensor) (v Real) (v Real) -> MTask v ()
34 setEnvFromDHT :: (v AirQualitySensor) (v DHT) -> MTask v ()
35 \end{lstClean}
36
37 \subsection{Gesture sensor}
38 The \gls{MTASK} language supports one type (\emph{PAJ7620} connected via \gls{I2C}) of gesture sensors.
39 The \emph{PAJ7620} contains an optical CMOS array that measures the reflection of the on-board \gls{IR} \gls{LED} to detect up to several different gestures.
40 The complete interface containing the constructor and the measurement task is shown in \cref{lst:mtask_gesture}.
41
42 \begin{lstClean}[label={lst:mtask_gesture},caption={Gesture sensor interface in \gls{MTASK}.}]
43 :: GestureSensor // abstract
44 :: Gesture = GNone | GRight | GLeft | GUp | GDown | GForward | GBackward
45 | GClockwise | GCountClockwise
46
47 class GestureSensor v where
48 gestureSensor :: I2CAddr ((v GestureSensor) -> Main (v a)) -> Main (v a)
49 gesture` :: (TimingInterval v) (v GestureSensor) -> MTask v Gesture
50 gesture :: (v GestureSensor) -> MTask v Gesture
51 \end{lstClean}
52
53 \subsection{Light intensity sensor}
54 The \gls{MTASK} language supports one type (\emph{BH1750} connected via \gls{I2C}) of light intensity sensors that measure the light intensity in \unit{lx}.
55 The complete interface containing the constructor and the measurement task is shown in \cref{lst:mtask_light}.
56
57 \begin{lstClean}[label={lst:mtask_light},caption={Light intensity sensor interface in \gls{MTASK}.}]
58 :: LightSensor // abstract
59
60 class LightSensor v where
61 lightsensor :: I2CAddr ((v LightSensor) -> Main (v b)) -> Main (v b)
62 light` :: (TimingInterval v) (v LightSensor) -> MTask v Real
63 light :: (v LightSensor) -> MTask v Real
64 \end{lstClean}
65
66 \subsection{Motion detection sensor}
67 The \gls{MTASK} language supports motion sensing using a \gls{PIR} sensor through a type class that only contains macros.
68 \gls{PIR} sensors detect motion by the \gls{IR} reflection through a number of fresnel lenses and communicates through a digital \gls{GPIO} pin.
69 Therefore, a \gls{PIR} is nothing more than a \cleaninline{DPIN} according to \gls{MTASK} but for uniformity, a type class is available (see \cref{lst:mtask_pir}).
70
71 \begin{lstClean}[label={lst:mtask_pir},caption={\Gls{PIR} sensor interface in \gls{MTASK}.}]
72 :: PIR :== DPin
73
74 class PIR v | step, expr, pinMode v & dio DPin v where
75 PIR :: DPin ((v PIR) -> Main (v b)) -> Main (v b) | expr, step, pinMode v
76
77 motion` :: (TimingInterval v) (v PIR) -> MTask v Bool
78 motion :: (v PIR) -> MTask v Bool | dio DPin v
79 \end{lstClean}
80
81 \subsection{Sound detection sensor}
82 The \gls{MTASK} language supports motion sensing using one type of sensor (\emph{SEN-12642}) that outputs either a gate value through a digital \gls{GPIO} pin, the envelope (amplitude) through an analog \gls{GPIO} pin and an audio output.
83 Only the sound level---i.e.\ the envelope---and the sound presence are available in \gls{MTASK} through a type class containing only macros.
84 Therefore, a sound detector is nothing more than a tuple of a \cleaninline{DPin} for the gate value and an \cleaninline{APin} for the envelope (see \cref{lst:mtask_sound}).
85
86 \begin{lstClean}[label={lst:mtask_sound},caption={Sound detection sensor interface in \gls{MTASK}.}]
87 :: SoundDetector :== (DPin, APin)
88
89 class SoundDetector v | tupl, expr, pinMode v & dio DPin v
90 where
91 soundDetector :: DPin APin ((v SoundDetector) -> Main (v b)) -> Main (v b)
92
93 soundPresence` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
94 soundPresence :: (v SoundDetector) -> MTask v Bool | tupl v & dio DPin v
95
96 soundLevel` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
97 soundLevel :: (v SoundDetector) -> MTask v Bool | tupl, aio v
98 \end{lstClean}
99
100 \subsection{\IIC{} buttons}
101 The \gls{MTASK} language supports one type of \gls{I2C} buttons (the \gls{I2C} buttons from the \gls{WEMOS} d1 mini \gls{OLED} shield).
102 The buttons from this shield provide more information than just the status (see \cleaninline{ButtonStatus}).
103 The complete interface containing the constructor and the measurement tasks is shown in \cref{lst:mtask_i2cbutton}.
104
105 \begin{lstClean}[label={lst:mtask_i2cbutton},caption={\Gls{I2C} button interface in \gls{MTASK}.}]
106 :: I2CButton // abstract
107 :: ButtonStatus = ButtonNone | ButtonPress | ButtonLong | ButtonDouble | ButtonHold
108
109 class i2cbutton v where
110 i2cbutton :: I2CAddr ((v I2CButton) -> Main (v b)) -> Main (v b) | type b
111
112 AButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
113 AButton :: (v I2CButton) -> MTask v ButtonStatus
114
115 BButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
116 BButton :: (v I2CButton) -> MTask v ButtonStatus
117 \end{lstClean}
118
119 \subsection{LED matrix}
120 The \gls{MTASK} language supports one type of \gls{LED} matrix (the $8\times8$ \gls{LED} matrix shield for the \gls{WEMOS} d1 mini).
121 Instead of containing a \gls{TOP}-like interface, the \gls{ARDUINO} interface is directly translated to \gls{MTASK}.
122 As a result, every task immediately returns a stable value indicating the result.
123 The complete interface containing the constructor and the interaction tasks is shown in \cref{lst:mtask_ledmatrix}.
124
125 \begin{lstClean}[label={lst:mtask_ledmatrix},caption={\Gls{LED} matrix interface in \gls{MTASK}.}]
126 :: LEDMatrix // abstract
127 :: LEDMatrixInfo = { dataPin :: Pin, clockPin :: Pin }
128
129 class LEDMatrix v where
130 ledmatrix :: LEDMatrixInfo ((v LEDMatrix) -> Main (v b)) -> Main (v b) | type b
131 LMDot :: (v LEDMatrix) (v Int) (v Int) (v Bool) -> MTask v ()
132 LMIntensity :: (v LEDMatrix) (v Int) -> MTask v ()
133 LMClear :: (v LEDMatrix) -> MTask v ()
134 LMDisplay :: (v LEDMatrix) -> MTask v ()
135 \end{lstClean}
136
137 \subsection{Connection types}\label{lst:connection_types}
138 \begin{lstClean}[caption={}]
139 :: TCPSettings =
140 { host :: String
141 , port :: Int
142 , pingTimeout :: ?Int
143 }
144 :: MQTTSettings =
145 { host :: String
146 , port :: Int
147 , mcuId :: String
148 , serverId :: String
149 , auth :: MQTTAuth
150 }
151 :: TTYSettings = {
152 devicePath :: String,
153 baudrate :: BaudRate,
154 bytesize :: ByteSize,
155 parity :: Parity,
156 stop2bits :: Bool,
157 xonxoff :: Bool,
158 sleepTime :: Int
159 }
160 \end{lstClean}
161
162
163 \lstset{basicstyle=\tt}
164 \input{subfilepostamble}
165 \end{document}