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