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