1 \documentclass[../thesis.tex
]{subfiles
}
3 \input{subfilepreamble
}
8 \ifSubfilesClassLoaded{\appendix\setcounter{chapter
}{1}}{}
9 \chapter{Auxiliary
\texorpdfstring{\glsentrytext{MTASK
}}{mTask
} type classes
}%
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
}).
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
}.
24 \begin{lstClean
}[label=
{lst:mtask_aqs
},caption=
{Air quality sensor interface in
\gls{MTASK
}.
}]
25 :: AirQualitySensor // abstract
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 ()
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
}.
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
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
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
}.
57 \begin{lstClean
}[label=
{lst:mtask_light
},caption=
{Light intensity sensor interface in
\gls{MTASK
}.
}]
58 :: LightSensor // abstract
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
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
}).
71 \begin{lstClean
}[label=
{lst:mtask_pir
},caption=
{\Gls{PIR
} sensor interface in
\gls{MTASK
}.
}]
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
77 motion` :: (TimingInterval v) (v PIR) -> MTask v Bool
78 motion :: (v PIR) -> MTask v Bool | dio DPin v
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
}).
86 \begin{lstClean
}[label=
{lst:mtask_sound
},caption=
{Sound detection sensor interface in
\gls{MTASK
}.
}]
87 :: SoundDetector :== (DPin, APin)
89 class SoundDetector v | tupl, expr, pinMode v & dio DPin v
91 soundDetector :: DPin APin ((v SoundDetector) -> Main (v b)) -> Main (v b)
93 soundPresence` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
94 soundPresence :: (v SoundDetector) -> MTask v Bool | tupl v & dio DPin v
96 soundLevel` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
97 soundLevel :: (v SoundDetector) -> MTask v Bool | tupl, aio v
100 \subsection{\texorpdfstring{\gls{I2C
}}{I
\textsuperscript{2}C
} 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
}.
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
109 class i2cbutton v where
110 i2cbutton :: I2CAddr ((v I2CButton) -> Main (v b)) -> Main (v b) | type b
112 AButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
113 AButton :: (v I2CButton) -> MTask v ButtonStatus
115 BButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
116 BButton :: (v I2CButton) -> MTask v ButtonStatus
119 \subsection{\texorpdfstring{\gls{LED
}}{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
}.
125 \begin{lstClean
}[label=
{lst:mtask_ledmatrix
},caption=
{\Gls{LED
} matrix interface in
\gls{MTASK
}.
}]
126 :: LEDMatrix // abstract
127 :: LEDMatrixInfo =
{ dataPin :: Pin, clockPin :: Pin
}
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 ()
137 \subsection{Connection types
}\label{lst:connection_types
}
138 \begin{lstClean
}[caption=
{}]
142 , pingTimeout :: ?Int
152 devicePath :: String,
153 baudrate :: BaudRate,
154 bytesize :: ByteSize,
163 \lstset{basicstyle=
\tt}
164 \input{subfilepostamble
}