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