a088aa017f785a8ada90327a697590cb741ca0af
[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 where
89 soundDetector :: DPin APin ((v SoundDetector) -> Main (v b)) -> Main (v b)
90
91 soundPresence` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
92 soundPresence :: (v SoundDetector) -> MTask v Bool | tupl v & dio DPin v
93
94 soundLevel` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
95 soundLevel :: (v SoundDetector) -> MTask v Bool | tupl, aio v
96 \end{lstClean}
97
98 \subsection{\IIC{} buttons}
99 The \gls{MTASK} language supports one type of \gls{I2C} buttons (the \gls{I2C} buttons from the \gls{WEMOS} D1 mini \gls{OLED} shield).
100 The buttons from this shield provide more information than just the status (see \cleaninline{ButtonStatus}).
101 The complete interface containing the constructor and the measurement tasks is shown in \cref{lst:mtask_i2cbutton}.
102
103 \begin{lstClean}[label={lst:mtask_i2cbutton},caption={\Gls{I2C} button interface in \gls{MTASK}.}]
104 :: I2CButton // abstract
105 :: ButtonStatus = ButtonNone | ButtonPress | ButtonLong | ButtonDouble | ButtonHold
106
107 class i2cbutton v where
108 i2cbutton :: I2CAddr ((v I2CButton) -> Main (v b)) -> Main (v b) | type b
109
110 AButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
111 AButton :: (v I2CButton) -> MTask v ButtonStatus
112
113 BButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
114 BButton :: (v I2CButton) -> MTask v ButtonStatus
115 \end{lstClean}
116
117 \subsection{LED matrix}
118 The \gls{MTASK} language supports one type of \gls{LED} matrix (the $8\times8$ \gls{LED} matrix shield for the \gls{WEMOS} D1 mini).
119 Instead of containing a \gls{TOP}-like interface, the \gls{ARDUINO} interface is directly translated to \gls{MTASK}.
120 As a result, every task immediately returns a stable value indicating the result.
121 The complete interface containing the constructor and the interaction tasks is shown in \cref{lst:mtask_ledmatrix}.
122
123 \begin{lstClean}[label={lst:mtask_ledmatrix},caption={\Gls{LED} matrix interface in \gls{MTASK}.}]
124 :: LEDMatrix // abstract
125 :: LEDMatrixInfo = { dataPin :: Pin, clockPin :: Pin }
126
127 class LEDMatrix v where
128 ledmatrix :: LEDMatrixInfo ((v LEDMatrix) -> Main (v b)) -> Main (v b) | type b
129 LMDot :: (v LEDMatrix) (v Int) (v Int) (v Bool) -> MTask v ()
130 LMIntensity :: (v LEDMatrix) (v Int) -> MTask v ()
131 LMClear :: (v LEDMatrix) -> MTask v ()
132 LMDisplay :: (v LEDMatrix) -> MTask v ()
133 \end{lstClean}
134
135 \subsection{Connection types}\label{lst:connection_types}
136 \begin{lstClean}[caption={}]
137 :: TCPSettings =
138 { host :: String
139 , port :: Int
140 , pingTimeout :: ?Int
141 }
142 :: MQTTSettings =
143 { host :: String
144 , port :: Int
145 , mcuId :: String
146 , serverId :: String
147 , auth :: MQTTAuth
148 }
149 :: TTYSettings =
150 { devicePath :: String
151 , baudrate :: BaudRate
152 , bytesize :: ByteSize
153 , parity :: Parity
154 , stop2bits :: Bool
155 , xonxoff :: Bool
156 , sleepTime :: Int
157 }
158 \end{lstClean}
159
160
161 \lstset{basicstyle=\tt}
162 \input{subfilepostamble}
163 \end{document}