Commit f1fb4f46 authored by Mart Lubbers's avatar Mart Lubbers
Browse files

document all mTask classes

parent bc7e99fb
Pipeline #56500 passed with stage
in 1 minute and 27 seconds
definition module mTask.Language.AirQuality
/**
* Air Quality Sensors (AQSs)
*
* Currently supported:
* - CCS811 over I²C
*/
import mTask.Language
//** Datatype holding a reference to the AQS. May as well be abstract.
:: AirQualitySensor = AirQualitySensor Int
derive class iTask AirQualitySensor
/**
* The class representing all AQSs
*
* @var view
*/
class AirQualitySensor v where
/**
* Constructor for the AQS.
*
* @param I²C address
* @param function doing something with the AQS
* @result {{Main}} program
*/
airqualitysensor :: I2CAddr ((v AirQualitySensor) -> Main (v a)) -> Main (v a) | type a
/**
* Calibrate the air quality sensor with a temperature and humidity
*
* @param AQS
* @param temperature
* @param humidity
* @param task yielding () as a stable value after calibration
*/
setEnvironmentalData :: (v AirQualitySensor) (v Real) (v Real) -> MTask v ()
/**
* Measure the volatile organic components in the air with a specified polling rate in ppb.
*
* @param polling rate
* @param AQS
* @result task yielding readings as an unstable value
*/
tvoc` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
/**
* Measure the volatile organic components in the air in ppm.
*
* @param AQS
* @result task yielding readings as an unstable value
*/
tvoc :: (v AirQualitySensor) -> MTask v Int
tvoc s = tvoc` Default s
/**
* Measure the equivalent CO₂ levels in the air with a specified polling rate in ppm.
*
* @param polling rate
* @param AQS
* @result task yielding readings as an unstable value
*/
co2` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
/**
* Measure the equivalent CO₂ levels in the air in ppm.
*
* @param AQS
* @result task yielding readings as an unstable value
*/
co2 :: (v AirQualitySensor) -> MTask v Int
co2 s = co2` Default s
/**
* Utility macro to calibrate an AQS using a DHT sensor
*
* @param AQS
* @param {{DHT}}
* @result task immediately yielding unit after calibration
*/
setEnvFromDHT :: (v AirQualitySensor) (v DHT) -> MTask v () | tupl, .&&., dht, step, expr v
setEnvFromDHT aqs dht :== temperature dht .&&. humidity dht
>>~. \x->setEnvironmentalData aqs (first x) (second x)
definition module mTask.Language.DHT
/**
* Digital Humidity and Temperature Sensors (DHTs)
*
* Currently supported:
* - DHT (all types) over OneWire
* - SHT30x over I²C
*/
import mTask.Language
from Data.UInt import :: UInt8
//** Datatype holding a reference to the AQS. May as well be abstract.
:: DHT = Dht Int
//** DHT connection information
:: DHTInfo
= DHT_DHT Pin DHTtype
//** DHT (all types) via One-Wire
//**
//** @var communication pin
//** @var Type
| DHT_SHT I2CAddr
//** SHT30x via I²C
//**
//** @var I²C address
//** DHT Type
:: DHTtype = DHT11 | DHT21 | DHT22
instance toString DHTtype
derive class iTask DHTtype, DHT, DHTInfo
/**
* The class representing all DHTs
*
* @var view
*/
class dht v where
/**
* Constructor for the DHT.
*
* @param connection information
* @param function doing something with the DHT
* @result {{Main}} program
*/
DHT :: DHTInfo ((v DHT)->Main (v b)) -> Main (v b) | type b
/**
* Measure the temperature with a specific polling rate in °C.
*
* @param polling rate
* @param DHT
* @result task yielding readings as an unstable value
*/
temperature` :: (TimingInterval v) (v DHT) -> MTask v Real
/**
* Measure the temperature in °C.
*
* @param polling rate
* @param DHT
* @result task yielding readings as an unstable value
*/
temperature :: (v DHT) -> MTask v Real
temperature s = temperature` Default s
/**
* Measure the relative humidity with a specific polling rate in %.
*
* @param polling rate
* @param DHT
* @result task yielding readings as an unstable value
*/
humidity` :: (TimingInterval v) (v DHT) -> MTask v Real
/**
* Measure the relative humidity in %.
*
* @param DHT
* @result task yielding readings as an unstable value
*/
humidity :: (v DHT) -> MTask v Real
humidity s = humidity` Default s
definition module mTask.Language.Expressions
/**
* Expressions, functions, tuples and helper functions
*/
import mTask.Language
from StdOverloaded import class +, class -, class zero, class one, class *, class /, class <
from StdClass import class Ord, class Eq
/**
* The class representing all expressions.
*
* @var view
*/
class expr v where
/**
* lift a value to the mTask domain
*
* @param value
* @result lifted value
*/
lit :: t -> v t | type t
//** Addition
(+.) infixl 6 :: (v t) (v t) -> v t | basicType, +, zero t
//** Subtraction
(-.) infixl 6 :: (v t) (v t) -> v t | basicType, -, zero t
//** Multiplication
(*.) infixl 7 :: (v t) (v t) -> v t | basicType, *, zero, one t
//** Division
(/.) infixl 7 :: (v t) (v t) -> v t | basicType, /, zero t
//** Logical and
(&.) infixr 3 :: (v Bool) (v Bool) -> v Bool
//** Logical or
(|.) infixr 2 :: (v Bool) (v Bool) -> v Bool
//** Logical negation
Not :: (v Bool) -> v Bool
//** Equal
(==.) infix 4 :: (v a) (v a) -> v Bool | Eq, basicType a
//** Not equal
(!=.) infix 4 :: (v a) (v a) -> v Bool | Eq, basicType a
//** Lesser than
(<.) infix 4 :: (v a) (v a) -> v Bool | Ord, basicType a
//** Greater than
(>.) infix 4 :: (v a) (v a) -> v Bool | Ord, basicType a
//** Lesser than or equal to
(<=.) infix 4 :: (v a) (v a) -> v Bool | Ord, basicType a
//** Greater than or equal to
(>=.) infix 4 :: (v a) (v a) -> v Bool | Ord, basicType a
/**
* ternary conditional expression
*
* @param predicate
* @param then expression
* @param else expression
* @result result
*/
If :: (v Bool) (v t) (v t) -> v t | type t
/**
* The class representing all functions
*
* Usually, a single instance is given for every arity.
*
* ```
* instance () SomeView where ...
* instance (SomeView a) SomeView where ...
* instance (SomeView a, SomeView b) SomeView where ...
* ...
* ```
*
* @var argument type
* @var view
* @param the function specification
* @result the Main program
*/
class fun a v :: ((a->v s)->In (a->v s) (Main (MTask v u))) -> Main (MTask v u) | type s & type u
/**
* The class representing 2-tuples
*
* @var view
*/
class tupl v where
//** Constructor (lifted {{(,)}}/{{tuple}})
tupl :: (v a) (v b) -> v (a, b) | type a & type b
//** Selector for the first argument (lifted {{fst}})
first :: (v (a, b)) -> v a | type a & type b
//** Selector for the second argument (lifted {{snd}})
second :: (v (a, b)) -> v b | type a & type b
tupl :: (v a) (v b) -> v (a, b) | type a & type b
/*
* Transforms a function on a v of tuple to a tuple of v's
* Helper macro to transforms a function on v of tuple to a tuple of v's
*
* @param The function to transform
* @result The transformed function
* @type ((v a, v b) -> v c) -> ((v (a, b)) -> v c) | tupl v & type a & type b
*/
tupopen f :== \v->f (first v, second v)
/**
* Helper macro for lifted {{True}}
*
* @type (v Bool)
*/
true :== lit True
/**
* Helper macro for lifted {{False}}
*
* @type (v Bool)
*/
false :== lit False
definition module mTask.Language.Gesture
/**
* Gesture sensors
*
* Currently supported:
* - PAJ7620 over I²C
*/
import mTask.Language
//** Datatype holding a reference to the AQS. May as well be abstract.
:: GestureSensor = GestureSensor Int
//** Datatype holding all possible gestures
:: Gesture = GNone | GRight | GLeft | GUp | GDown | GForward | GBackward | GClockwise | GCountClockwise
derive class iTask GestureSensor, Gesture
......@@ -11,8 +21,36 @@ instance toString Gesture
instance == Gesture
instance basicType Gesture
/**
* The class representing all gesture sensors
*
* @var view
*/
class GestureSensor v where
/**
* Constructor for the gesture sensor.
*
* @param I²C address
* @param function doing something with the gesture sensor
* @result {{Main}} program
*/
gestureSensor :: !I2CAddr ((v GestureSensor) -> Main (v a)) -> Main (v a) | type a
/**
* Detect a gesture with a specified polling rate in {{Gesture}}.
*
* @param polling rate
* @param gesture sensor
* @result task yielding readings as an unstable value
*/
gesture` :: (TimingInterval v) (v GestureSensor) -> MTask v Gesture
/**
* Detect a gesture in {{Gesture}}.
*
* @param polling rate
* @param gesture sensor
* @result task yielding readings as an unstable value
*/
gesture :: (v GestureSensor) -> MTask v Gesture
gesture s = gesture` Default s
definition module mTask.Language.Interrupts
/**
* Hardware interrupts
*/
import mTask.Language
//** The type of interrupt
:: InterruptMode
= Change
| Rising
......@@ -9,12 +13,46 @@ import mTask.Language
| Low
| High
/**
* Helper macro for lifted {{Change}}
*
* @type (v InterruptMode)
*/
change :== lit Change
/**
* Helper macro for lifted {{Rising}}
*
* @type (v InterruptMode)
*/
rising :== lit Rising
/**
* Helper macro for lifted {{Falling}}
*
* @type (v InterruptMode)
*/
falling :== lit Falling
/**
* Helper macro for lifted {{Low}}
*
* @type (v InterruptMode)
*/
low :== lit Low
/**
* Helper macro for lifted {{High}}
*
* @type (v InterruptMode)
*/
high :== lit High
/**
* The class representing the interrupt tasks
*
* @var view
* @param interrupt mode
* @param pin to watch for the interrupt
* @result a task yielding no value until the interrupt fires, after which is yields a stable pin state
* @throws {{MTEUnsupportedInterrupt}} in the interpreter if the pin doesn't support that interrupt
*/
class interrupt v :: (v InterruptMode) (v p) -> MTask v Bool | pin p
instance toString InterruptMode
......
definition module mTask.Language.LCD
/**
* LCD shields
*
* Currently supported:
* - None (at least in the interpreter)
*/
import mTask.Language
//** Datatype holding a reference to the LCD screen. May as well be abstract.
:: LCD = LCDid Int
instance toString LCD
......@@ -11,23 +19,116 @@ derive gDefault Button
instance == Button
instance basicType Button
//** Button id
:: Button = RightButton | UpButton | DownButton | LeftButton | SelectButton | NoButton
/**
* Helper macro for lifted {{RightButton}}
*
* @type (v Button)
*/
rightButton :== lit RightButton
/**
* Helper macro for lifted {{UpButton}}
*
* @type (v Button)
*/
upButton :== lit UpButton
/**
* Helper macro for lifted {{NoButton}}
*
* @type (v Button)
*/
downButton :== lit DownButton
/**
* Helper macro for lifted {{LeftButton}}
*
* @type (v Button)
*/
leftButton :== lit LeftButton
/**
* Helper macro for lifted {{SelectButton}}
*
* @type (v Button)
*/
selectButton :== lit SelectButton
/**
* Helper macro for lifted {{NoButton}}
*
* @type (v Button)
*/
noButton :== lit NoButton
/**
* The class representing all LDCs
*
* @var view
*/
class lcd v where
LCD :: Int Int [DPin] ((v LCD)->Main (v b)) -> Main (v b) | type b
print :: (v LCD) (v t) -> MTask v Int | type t // returns bytes written
setCursor :: (v LCD) (v Int) (v Int) -> MTask v ()
scrollLeft :: (v LCD) -> MTask v ()
scrollRight :: (v LCD) -> MTask v ()
pressed :: (v Button) -> MTask v Bool
/**
* Constructor for the LCD.
*
* @param Register select pin
* @param Read/Write pin
* @param Data pins
* @param function doing something with the AQS
* @result {{Main}} program
*/
LCD :: Int Int [DPin] ((v LCD)->Main (v b)) -> Main (v b) | type b
/**
* Print something to the LCD
*
* @param LCD
* @param thing to print
* @result Task yielding the bytes written as a stable value
*/
print :: (v LCD) (v t) -> MTask v Int | type t // returns bytes written
/**
* Set the cursor to a specific coordinate
*
* @param LCD
* @param x coordinate
* @param y coordinate
* @result Task yielding unit after setting the cursor
*/
setCursor :: (v LCD) (v Int) (v Int) -> MTask v ()
/**
* Scroll the screen one position to the left
*
* @param LCD
* @result Task yielding unit after scrolling
*/
scrollLeft :: (v LCD) -> MTask v ()
/**
* Scroll the screen one position to the right
*
* @param LCD
* @result Task yielding unit after scrolling
*/
scrollRight :: (v LCD) -> MTask v ()
/**
* Query the status of a button
*
* @param Button
* @result Task yielding the status as an unstable value
*/
pressed :: (v Button) -> MTask v Bool
/**
* The class representing an LDC button? Deprecated
*
* @var view
* @result Task yielding which button is pressed
*/
class buttonPressed v :: MTask v Button
/**
* Helper macro to print text at a specific position
*
* @param LCD
* @param x coordinate
* @param y coordinate
* @param thing to print
* @type (v LCD) (v Int) (v Int) (v t) -> MTask v Int
*/
printAt lcd x y z :== setCursor lcd x y >>|. print lcd z
definition module mTask.Language.LEDMatrix
/**
* Led matrices
*
* Currently supported:
* - Wemos matrix LED shield 8x8 over I²C
*/
import mTask.Language
//** Datatype holding a reference to the LED matrix. May as well be abstract.
:: LEDMatrix = LEDMatrix Int
//** Connection information %TODO change to I²C address
:: LEDMatrixInfo =
{ dataPin :: Pin
, clockPin :: Pin
......@@ -11,9 +20,52 @@ import mTask.Language
derive class iTask LEDMatrix, LEDMatrixInfo
/**
* The class representing all LED matrices
*
* @var view
*/
class LEDMatrix v where
/**
* Constructor for the LED matrix.
*
* @param connection information
* @param function doing something with the LED matrix
* @result {{Main}} program
*/
ledmatrix :: LEDMatrixInfo ((v LEDMatrix) -> Main (v b)) -> Main (v b) | type b
/**
* Set the state of a single LED.
* Remember to call {{LMDisplay}} after this to flush the changes.
*
* @param LED matrix
* @param x coordinate
* @param y coordinate
* @param state
* @result Task yielding unit as a stable value after setting the state
*/
LMDot :: (v LEDMatrix) (v Int) (v Int) (v Bool) -> MTask v ()
/**
* Change the intensity of the LEDs
* Remember to call {{LMDisplay}} after this to flush the changes.
*
* @param LED matrix
* @param intensity
* @result Task yielding unit as a stable value after setting the intensity
*/
LMIntensity :: (v LEDMatrix) (v Int) -> MTask v ()
/**
* Clear the entire LED matrix
* Remember to call {{LMDisplay}} after this to flush the changes.
*
* @param LED matrix
* @result Task yielding unit as a stable value after clearing
*/