Commit 6d9fac3d authored by Mart Lubbers's avatar Mart Lubbers
Browse files

Merge branch 'master' of gitlab.science.ru.nl:mlubbers/mTask

parents d3e42838 2847f84d
Pipeline #50359 passed with stages
in 20 minutes and 27 seconds
......@@ -22,6 +22,7 @@ MT_REMOVE :== UInt8 ((2^8) - 1)
:: BCInterpret a :== StateT BCState (WriterT [BCInstr] Identity) a
tell` :: [BCInstr] -> BCInterpret a
setRate :: Bool (TimingInterval (StateT BCState (WriterT [BCInstr] Identity))) -> BCInterpret a
:: BCState =
{ bcs_mainexpr :: [BCInstr]
......
......@@ -74,9 +74,18 @@ freshlabel = getState >>= \s=:{bcs_freshlabel=(JL i)}->
freshsds :: BCInterpret Int
freshsds = gets \s->length s.bcs_sdses
setRate :: Bool (TimingInterval (StateT BCState (WriterT [BCInstr] Identity))) -> BCInterpret a
setRate rl Default = pure undef
setRate rl (BeforeMs u) = tell` [BCPush $ fromString $ toByteCode{|*|} 0] >>| u >>| tell` [BCTuneRateMs]
setRate rl (BeforeSec u) = tell` [BCPush $ fromString $ toByteCode{|*|} 0] >>| u >>| tell` [BCTuneRateSec]
setRate rl (ExactMs t) = tell` if rl [BCMkTask BCRateLimit] [] >>| t >>| t >>| tell` [BCTuneRateMs]
setRate rl (ExactSec t) = tell` if rl [BCMkTask BCRateLimit] [] >>| t >>| t >>| tell` [BCTuneRateSec]
setRate rl (RangeMs u l) = tell` if rl [BCMkTask BCRateLimit] [] >>| u >>| l >>| tell` [BCTuneRateMs]
setRate rl (RangeSec u l) = tell` if rl [BCMkTask BCRateLimit] [] >>| u >>| l >>| tell` [BCTuneRateSec]
instance aio (StateT BCState (WriterT [BCInstr] Identity))
where
readA p = p >>| tell` [BCMkTask BCReadA]
readA` i p = p >>| tell` [BCMkTask BCReadA] >>| setRate True i
writeA p v = p >>| v >>| tell` [BCMkTask BCWriteA]
instance expr (StateT BCState (WriterT [BCInstr] Identity))
......@@ -113,6 +122,7 @@ where
instance dio v (StateT BCState (WriterT [BCInstr] Identity))
where
readD` i p = p >>| tell` [BCMkTask BCReadD] >>| setRate True i
readD p = p >>| tell` [BCMkTask BCReadD]
writeD p v = p >>| v >>| tell` [BCMkTask BCWriteD]
......@@ -126,7 +136,7 @@ where
instance rpeat (StateT BCState (WriterT [BCInstr] Identity))
where
rpeat m = m >>| tell` [BCMkTask BCRepeat]
rpeatEvery i m = m >>| tell` [BCMkTask BCRepeat] >>| setRate False i
instance rtrn (StateT BCState (WriterT [BCInstr] Identity))
where
......@@ -141,7 +151,10 @@ where
(t In e) = def sds
in e.main
}
getSds f = f >>= \(Sds i)-> tell` [BCMkTask (BCSdsGet (fromInt i))]
getSds` ti f
= f
>>= \(Sds i)-> tell` [BCMkTask (BCSdsGet (fromInt i))]
>>| setRate True ti
setSds f v = f >>= \(Sds i)->v >>| tell`
( map BCMkTask (bcstable $ toByteWidth $ unpack v)
++ [BCMkTask (BCSdsSet (fromInt i))])
......
......@@ -10,6 +10,7 @@ import Data.List => qualified group
import Data.Map => qualified union, difference, find, updateAt, get
import Data.Map.GenJSON
import Data.Tuple
import Data.UInt
import iTasks
import mTask.Interpret.ByteCodeEncoding
......@@ -163,13 +164,17 @@ liftmTaskWithOptions opts task (MTDevice dev sdsupdates channels)
>>- \_->watch taskView
>>* [OnValue $ ifValue (\t->t=:MTSPrepack || t =: MTSAcked || t =: (MTSValue _) || t =: (MTSException _))
\_->sendMessage (MTTTask
{ taskid = sid
, tree = VoidPointer ()
, stability = MTNoValue
, value = returnvalue
, peripherals = hardware
, shares = {i\\i<-shares}
, instructions = BCIs {i\\i<-instructions}
{ taskid = sid
, tree = VoidPointer ()
, stability = MTNoValue
, value = returnvalue
, peripherals = hardware
, shares = {i\\i<-shares}
, instructions = BCIs {i\\i<-instructions}
, status = MTUnevaluated
, execution_min = UInt32 0
, execution_max = UInt32 0
, lastrun = UInt32 0
}) channels]
//Wait for task ack
>>- \_->watch taskView
......
......@@ -59,6 +59,8 @@ instance toString JumpLabel
| BCStepArg UInt16 UInt8
//Task node creation
| BCMkTask BCTaskType
//Task node refinement
| BCTuneRateMs | BCTuneRateSec
//Task value ops
| BCIsStable | BCIsUnstable | BCIsNoValue | BCIsValue
//Stack ops
......@@ -101,6 +103,8 @@ instance toString JumpLabel
| BCSeqStable ArgWidth | BCSeqUnstable ArgWidth
//Sds ops
| BCSdsGet SdsId | BCSdsSet SdsId | BCSdsUpd SdsId JumpLabel
// Rate limiter
| BCRateLimit
////Peripherals
//DHT
| BCDHTTemp UInt8 | BCDHTHumid UInt8
......
......@@ -9,7 +9,7 @@ from iTasks.Internal.Generic.Visualization import generic gText, :: TextFormat
from Data.GenEq import generic gEq
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Data.UInt import :: UInt8, :: UInt16
from Data.UInt import :: UInt8, :: UInt16, :: UInt32
from iTasks.WF.Definition import :: TaskValue
from mTask.Interpret.Instructions import :: BCInstr, :: BCInstrs
from mTask.Interpret.Specification import :: MTDeviceSpec
......@@ -33,16 +33,25 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
| MTTSdsUpdate UInt8 UInt8 String255
:: MTask =
{ taskid :: UInt8
, tree :: VoidPointer
, stability :: MTaskValueState
, value :: String255
, shares :: {BCShareSpec}
, peripherals :: {BCPeripheral}
, instructions :: BCInstrs
{ taskid :: UInt8
, tree :: VoidPointer
, stability :: MTaskValueState
, value :: String255
, shares :: {BCShareSpec}
, peripherals :: {BCPeripheral}
, instructions :: BCInstrs
, status :: MTaskEvalStatus
, execution_min :: UInt32
, execution_max :: UInt32
, lastrun :: UInt32
}
:: MTaskValueState = MTNoValue | MTUnstable | MTStable | MTRemoved
// MTEvaluated: task tree is evaluated and the previously calculated execution interval is still correct
// MTPurged: task tree is evaluated, but the execution interval needs to be recalculated
// MTUnevaluated: task tree contains unevaluated parts, the execution interval is [0,0]
:: MTaskEvalStatus = MTEvaluated | MTPurged | MTUnevaluated
:: MTMessageFro
//* taskid
= MTFTaskAck UInt8
......@@ -75,8 +84,8 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
| MTERTSError
| MTEUnexpectedDisconnect
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskValueState
derive gCSerialise MTMessageFro, MTMessageTo, MTException, TaskValue, MTaskValueState
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, TaskValue, MTaskValueState
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskValueState, MTaskEvalStatus
derive gCSerialise MTMessageFro, MTMessageTo, MTException, TaskValue, MTaskValueState, MTaskEvalStatus
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, TaskValue, MTaskValueState, MTaskEvalStatus
instance toString MTException
......@@ -9,7 +9,7 @@ import mTask.Interpret.Instructions
import mTask.Interpret.Compile
import mTask.Interpret.VoidPointer
derive class iTask MTMessageFro, MTMessageTo, MTException, MTask, MTaskValueState
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTask, TaskValue, MTaskValueState
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTask, TaskValue, MTaskValueState
derive class iTask MTMessageFro, MTMessageTo, MTException, MTask, MTaskValueState, MTaskEvalStatus
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTask, TaskValue, MTaskValueState, MTaskEvalStatus
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTask, TaskValue, MTaskValueState, MTaskEvalStatus
instance toString MTException where toString e = toSingleLineText e
......@@ -34,8 +34,14 @@ instance dht (StateT BCState (WriterT [BCInstr] Identity)) where
<* modify (\s->{s & bcs_hardware=s.bcs_hardware ++ [BCDHT dhtinfo]})
>>= unmain o def o pure
}
temperature dht = dht >>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
humidity dht = dht >>= \(Dht i)->tell` [BCMkTask $ BCDHTHumid $ fromInt i]
temperature` ti dht
= dht
>>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
>>| setRate True ti
humidity` ti dht
= dht
>>= \(Dht i)->tell` [BCMkTask $ BCDHTHumid $ fromInt i]
>>| setRate True ti
instance LEDMatrix (StateT BCState (WriterT [BCInstr] Identity)) where
ledmatrix i def = {main
......@@ -54,8 +60,14 @@ instance i2cbutton (StateT BCState (WriterT [BCInstr] Identity)) where
<* modify (\s->{s & bcs_hardware=s.bcs_hardware ++ [BCI2CButton addr]})
>>= unmain o def o pure
}
AButton m = m >>= \(I2CButton i)->tell` [BCMkTask (BCAButton (fromInt i))]
BButton m = m >>= \(I2CButton i)->tell` [BCMkTask (BCBButton (fromInt i))]
AButton` ti m
= m
>>= \(I2CButton i)->tell` [BCMkTask (BCAButton (fromInt i))]
>>| setRate True ti
BButton` ti m
= m
>>= \(I2CButton i)->tell` [BCMkTask (BCBButton (fromInt i))]
>>| setRate True ti
instance LightSensor (StateT BCState (WriterT [BCInstr] Identity))
where
......@@ -64,7 +76,10 @@ where
<* modify (\s -> {s & bcs_hardware=s.bcs_hardware ++ [BCLightSensor addr]})
>>= unmain o def o pure
}
light ls = ls >>= \(LightSensor i) -> tell` [BCMkTask (BCGetLight (fromInt i))]
light` ti ls
= ls
>>= \(LightSensor i) -> tell` [BCMkTask (BCGetLight (fromInt i))]
>>| setRate True ti
instance AirQualitySensor (StateT BCState (WriterT [BCInstr] Identity))
where
......@@ -74,8 +89,14 @@ where
>>= unmain o def o pure
}
setEnvironmentalData aqs humid temp = humid >>| temp >>| aqs >>= \(AirQualitySensor i)->tell` [BCMkTask (BCSetEnvironmentalData (fromInt i))]
tvoc aqs = aqs >>= \(AirQualitySensor s) -> tell` [BCMkTask (BCTVOC (fromInt s))]
co2 aqs = aqs >>= \(AirQualitySensor s) -> tell` [BCMkTask (BCCO2 (fromInt s))]
tvoc` i aqs
= aqs
>>= \(AirQualitySensor s) -> tell` [BCMkTask (BCTVOC (fromInt s))]
>>| setRate True i
co2` i aqs
= aqs
>>= \(AirQualitySensor s) -> tell` [BCMkTask (BCCO2 (fromInt s))]
>>| setRate True i
instance GestureSensor (StateT BCState (WriterT [BCInstr] Identity))
where
......@@ -84,4 +105,7 @@ where
<* modify (\s -> {s & bcs_hardware=s.bcs_hardware ++ [BCGestureSensor addr]})
>>= unmain o def o pure
}
gesture ges = ges >>= \(GestureSensor s) -> tell` [BCMkTask (BCGesture (fromInt s))]
gesture` i ges
= ges
>>= \(GestureSensor s) -> tell` [BCMkTask (BCGesture (fromInt s))]
>>| setRate True i
......@@ -23,8 +23,14 @@ where
<* modify (\s->{s & bcs_hardware=s.bcs_hardware ++ [BCDHT pin type]})
>>= unmain o def o pure
}
temperature dht = dht >>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
humidity dht = dht >>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
temperature` ti dht
= dht
>>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
>>| setRate True ti
humidity` ti dht
= dht
>>= \(Dht i)->tell` [BCMkTask $ BCDHTTemp $ fromInt i]
>>| setRate True ti
nextDHT :: BCState -> DHT
nextDHT st=:{bcs_hardware=p} = Dht $ fromInt $ length [()\\(BCDHT _)<-p]
......@@ -8,9 +8,16 @@ derive class iTask AirQualitySensor
class AirQualitySensor v where
airqualitysensor :: I2CAddr ((v AirQualitySensor) -> Main (v a)) -> Main (v a) | type a
setEnvironmentalData :: (v AirQualitySensor) (v Real) (v Real) -> MTask v ()
tvoc` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
tvoc :: (v AirQualitySensor) -> MTask v Int
tvoc s = tvoc` Default s
co2` :: (TimingInterval v) (v AirQualitySensor) -> MTask v Int
co2 :: (v AirQualitySensor) -> MTask v Int
co2 s = co2` Default s
setEnvFromDHT :: (v AirQualitySensor) (v DHT) -> MTask v () | tupl, .&&., dht, step, expr v
setEnvFromDHT aqs dht :== temperature dht .&&. humidity dht
......
......@@ -13,6 +13,12 @@ instance toString DHTtype
derive class iTask DHTtype, DHT, DHTInfo
class dht v where
DHT :: DHTInfo ((v DHT)->Main (v b)) -> Main (v b) | type b
temperature :: (v DHT) -> MTask v Real
humidity :: (v DHT) -> MTask v Real
DHT :: DHTInfo ((v DHT)->Main (v b)) -> Main (v b) | type b
temperature` :: (TimingInterval v) (v DHT) -> MTask v Real
temperature :: (v DHT) -> MTask v Real
temperature s = temperature` Default s
humidity` :: (TimingInterval v) (v DHT) -> MTask v Real
humidity :: (v DHT) -> MTask v Real
humidity s = humidity` Default s
......@@ -13,4 +13,6 @@ instance basicType Gesture
class GestureSensor v where
gestureSensor :: !I2CAddr ((v GestureSensor) -> Main (v a)) -> Main (v a) | type a
gesture :: (v GestureSensor) -> MTask v Gesture
gesture` :: (TimingInterval v) (v GestureSensor) -> MTask v Gesture
gesture :: (v GestureSensor) -> MTask v Gesture
gesture s = gesture` Default s
......@@ -8,4 +8,6 @@ derive class iTask LightSensor
class LightSensor v where
lightsensor :: I2CAddr ((v LightSensor) -> Main (v b)) -> Main (v b) | type b
light` :: (TimingInterval v) (v LightSensor) -> MTask v Real
light :: (v LightSensor) -> MTask v Real
light s = light` Default s
......@@ -8,5 +8,8 @@ class PIR v | step, expr, pinMode v & dio DPin v where
PIR :: DPin ((v PIR) -> Main (v b)) -> Main (v b) | type b & expr, step, pinMode v
PIR dp def :== {main=pinMode PMInput (lit dp) >>|. unmain (def (lit dp))}
motion` :: (TimingInterval v) (v PIR) -> MTask v Bool
motion` i p :== readD` i p
motion :: (v PIR) -> MTask v Bool | dio DPin v
motion p :== readD p
......@@ -6,10 +6,12 @@ import mTask.Language
:: Sds a = Sds Int
class sds v where
sds :: ((v (Sds t))->In t (Main (MTask v u))) -> Main (MTask v u) | type t & type u
getSds :: (v (Sds t)) -> MTask v t | type t
setSds :: (v (Sds t)) (v t) -> MTask v t | type t
updSds :: (v (Sds t)) ((v t) -> v t) -> MTask v t | type t
sds :: ((v (Sds t))->In t (Main (MTask v u))) -> Main (MTask v u) | type t & type u
setSds :: (v (Sds t)) (v t) -> MTask v t | type t
updSds :: (v (Sds t)) ((v t) -> v t) -> MTask v t | type t
getSds` :: (TimingInterval v) (v (Sds t)) -> MTask v t | type t
getSds :: (v (Sds t)) -> MTask v t | type t
getSds sds = getSds` Default sds
class liftsds v where
liftsds :: ((v (Sds t))->In (Shared sds t) (Main (MTask v u))) -> Main (MTask v u) | type t & type u & RWShared sds & TC (sds () t t)
......@@ -9,8 +9,14 @@ where
soundDetector :: DPin APin ((v SoundDetector) -> Main (v b)) -> Main (v b) | type b & expr, step, pinMode v
soundDetector dp ap def :== {main=pinMode PMInput (lit dp) >>|. unmain (def (lit (dp, ap)))}
soundPresence` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool
soundPresence` i p :== readD` i (first p)
soundPresence :: (v SoundDetector) -> MTask v Bool | tupl v & dio DPin v
soundPresence p :== readD (first p)
soundLevel` :: (TimingInterval v) (v SoundDetector) -> MTask v Bool | aio, tupl v
soundLevel` i p :== readA` i (second p)
soundLevel :: (v SoundDetector) -> MTask v Bool | tupl, aio v
soundLevel p :== readA (second p)
......@@ -27,7 +27,10 @@ class step v | expr v where
| IfNoValue (MTask v u)
| Always (MTask v u)
class rpeat v :: (MTask v a) -> MTask v a | type a
class rpeat v where
rpeat :: (MTask v a) -> MTask v a | type a
rpeat t :== rpeatEvery Default t
rpeatEvery :: (TimingInterval v) (MTask v a) -> MTask v a | type a
class (.&&.) infixr 4 v :: (MTask v a) (MTask v b) -> MTask v (a, b) | type a & type b
class (.||.) infixr 3 v :: (MTask v a) (MTask v a) -> MTask v a | type a
......
......@@ -30,6 +30,16 @@ type2string :: a -> String | TC a
:: I2CAddr =: I2C UInt8
i2c x :== I2C (fromInt x)
:: TimingInterval v
= Default
| BeforeMs (v Int)
| BeforeSec (v Int)
| ExactMs (v Int)
| ExactSec (v Int)
| RangeMs (v Int) (v Int)
| RangeSec (v Int) (v Int)
instance toInt I2CAddr
instance toString I2CAddr
derive class iTask \ gEditor, gText I2CAddr
......
......@@ -11,5 +11,11 @@ instance == ButtonStatus
class i2cbutton v where
i2cbutton :: !I2CAddr ((v I2CButton) -> Main (v b)) -> Main (v b) | type b
AButton :: !(v I2CButton) -> MTask v ButtonStatus
BButton :: !(v I2CButton) -> MTask v ButtonStatus
AButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
AButton :: (v I2CButton) -> MTask v ButtonStatus
AButton b = AButton` Default b
BButton` :: (TimingInterval v) (v I2CButton) -> MTask v ButtonStatus
BButton :: (v I2CButton) -> MTask v ButtonStatus
BButton b = BButton` Default b
......@@ -3,12 +3,16 @@ definition module mTask.Language.pinIO
import mTask.Language
class aio v where
readA :: (v APin) -> MTask v Int
writeA :: (v APin) (v Int) -> MTask v Int
readA` :: (TimingInterval v) (v APin) -> MTask v Int
readA :: (v APin) -> MTask v Int
readA p = readA` Default p
class dio p v | pin p where
readD :: (v p) -> MTask v Bool
writeD :: (v p) (v Bool) -> MTask v Bool
readD` :: (TimingInterval v) (v p) -> MTask v Bool | pin p
readD :: (v p) -> MTask v Bool | pin p
readD p = readD` Default p
class pinMode v where
pinMode :: PinMode (v p) -> MTask v () | pin p
......
......@@ -43,17 +43,30 @@ instance tupl Show where
binop x o y = par (x >>| show o >>| y) >>| return undef
twoArg x y = binop x ", " y
intervalArg i a = par (showTimingInterval i >>| show ", " >>| a)
showTimingInterval :: (TimingInterval Show) -> Show a
showTimingInterval Default = show "Default"
showTimingInterval (BeforeMs t) = show "BeforeMs " >>| t >>| return undef
showTimingInterval (BeforeSec t) = show "BeforeSec " >>| t >>| return undef
showTimingInterval (ExactMs t) = show "ExactMs " >>| t >>| return undef
showTimingInterval (ExactSec t) = show "ExactSec " >>| t >>| return undef
showTimingInterval (RangeMs l u) = show "RangeMs " >>| l >>| show " " >>| u >>| return undef
showTimingInterval (RangeSec l u) = show "RangeSec " >>| l >>| show " " >>| u >>| return undef
instance aio Show where
readA p = show "readAnalog" >>| par p >>| return NoValue
readA` i p = show "readAnalog" >>| intervalArg i p >>| return NoValue
readA p = show "readAnalog" >>| return NoValue
writeA p v = show "writeAnalog" >>| twoArg p v >>| return NoValue
instance dio APin Show where
readD p = show "readDigital" >>| par p >>| return NoValue
readD` i p = show "readDigital" >>| intervalArg i p >>| return NoValue
readD p = show "readDigital" >>| return NoValue
writeD p v = show "writeDigital" >>| twoArg p v >>| return NoValue
instance dio DPin Show where
readD p = show "readDigital" >>| par p >>| return NoValue
readD` i p = show "readDigital" >>| intervalArg i p >>| return NoValue
readD p = show "readDigital" >>| return NoValue
writeD p v = show "writeDigital" >>| twoArg p v >>| return NoValue
instance pinMode Show where
......@@ -89,7 +102,7 @@ showSteps [s:x]
showSteps [] = nl
instance rpeat Show where
rpeat t = par (show "rpeat" >>>| t >>| return undef)
rpeatEvery i t = par (show "rpeat" >>>| showTimingInterval i >>>| t >>| return undef)
instance delay Show where
delay d = par (show "delay" >>>| d >>| return undef)
......@@ -139,6 +152,7 @@ instance sds Show where
show ("sds " + s + "=" + toString v) >>| nl >>|
show "in" >>>| m >>| nl
}
getSds` i sds = show "getSDS" >>>| showTimingInterval i >>>| sds >>| return undef
getSds sds = show "getSDS" >>>| sds >>| return undef
setSds sds v = show "setSDS" >>>| sds >>>| v >>| return undef
updSds sds v = fresh "v" >>= \s->show "updSDS" >>>| sds >>>| show ("(\\" + s + "->") >>>| v (show s) >>>| show ")" >>>| return undef
......@@ -155,7 +169,9 @@ instance dht Show where
DHT i def =
{main = fresh "d" >>= \dht. let {main = m} = def (show dht) in
show (toSingleLineText i +++ ";\n") >>| m}
temperature` i dht = dht >>| show ".temperature(" >>| showTimingInterval i >>| show ")"
temperature dht = dht >>| show ".temperature()"
humidity` i dht = dht >>| show ".humidity(" >>| showTimingInterval i >>| show ")"
humidity dht = dht >>| show ".humidity()"
instance LEDMatrix Show where
......@@ -170,21 +186,25 @@ instance LightSensor Show where
lightsensor addr def = {main = fresh "ls" >>= \sensor ->
let {main = m} = def (show sensor) in
show ("LightSensor " + sensor + " (" + toString addr + ")\n") >>| m}
light ls = ls >>| show "light"
light` i ls = ls >>| show ".light(" >>| showTimingInterval i >>| show ")"
light ls = ls >>| show ".light()"
instance AirQualitySensor Show where
airqualitysensor addr def = {main = fresh "aqs" >>= \sensor ->
let {main = m} = def (show sensor) in
show ("AirQualitySensor " + sensor + " (" + toString addr + ")\n") >>| m}
setEnvironmentalData s humid temp = s >>| show ".setEnvironmentalData(" >>| humid >>| show ", " >>| temp >>| return undef
tvoc s = s >>| show ".TVOC"
co2 s = s >>| show ".CO2"
tvoc` i s = s >>| show ".TVOC(" >>| showTimingInterval i >>| show ")"
tvoc s = s >>| show ".TVOC()"
co2` i s = s >>| show ".CO2(" >>| showTimingInterval i >>| show ")"
co2 s = s >>| show ".CO2()"
instance GestureSensor Show where
gestureSensor addr def = {main = fresh "ges" >>= \sensor ->
let {main = m} = def (show sensor) in
show ("GestureSensor " + sensor + " (" + toString addr + ")\n") >>| m}
gesture s = s >>| show ".gesture"
gesture` i s = s >>| show ".gesture(" >>| showTimingInterval i >>| show ")"
gesture s = s >>| show ".gesture()"
instance lcd Show where
print lcd v = lcd >>| show ".print" >>>| v >>| return undef
......@@ -200,8 +220,10 @@ instance i2cbutton Show where
i2cbutton addr def = {main = fresh "b" >>= \but.
let {main = m} = def (show but) in
show ("I2CButton " + but + " (" + toString addr + ");\n") >>| m}
AButton but = but >>| show "AButton"
BButton but = but >>| show "BButton"
AButton` i but = but >>| show ".AButton(" >>| showTimingInterval i >>| show ")"
AButton but = but >>| show ".AButton()"
BButton` i but = but >>| show ".BButton(" >>| showTimingInterval i >>| show ")"
BButton but = but >>| show ".BButton()"
instance buttonPressed