summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoeyHess <>2018-08-22 22:26:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-08-22 22:26:00 (GMT)
commite25a5ac0bedfc8d1703870be5fde9d9390b47be2 (patch)
tree4bac047f90813d8031fb96e560f18062bb0ed88f
parent3f9db047dc95148d41462d4f928ac2b387134e1c (diff)
version 0.5.1HEAD0.5.1master
-rw-r--r--CHANGELOG7
-rw-r--r--Reactive/Banana/Automation.hs25
-rw-r--r--reactive-banana-automation.cabal2
3 files changed, 28 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e08bdf0..196e92c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+reactive-banana-automation (0.5.1) upstream; urgency=medium
+
+ * Added Eq and Ord instances for PowerChange.
+ * Added automationChanges and actuateFutureEvent.
+
+ -- Joey Hess <id@joeyh.name> Wed, 22 Aug 2018 18:26:15 -0400
+
reactive-banana-automation (0.5.0) upstream; urgency=medium
* Remove onEvent, which allowed arbitrary IO not connected with
diff --git a/Reactive/Banana/Automation.hs b/Reactive/Banana/Automation.hs
index fbc58eb..24e02b5 100644
--- a/Reactive/Banana/Automation.hs
+++ b/Reactive/Banana/Automation.hs
@@ -34,7 +34,9 @@ module Reactive.Banana.Automation (
(=:),
sensorUnavailable,
sensedEventBehavior,
+ -- * Combinators
automationStepper,
+ automationChanges,
-- * Time
Timestamped(..),
Timestamp(..),
@@ -48,6 +50,7 @@ module Reactive.Banana.Automation (
-- * Actuators
PowerChange(..),
actuateEvent,
+ actuateFutureEvent,
actuateBehavior,
actuateBehaviorMaybe,
-- * Ranges
@@ -254,6 +257,10 @@ sensedEventBehavior = automationStepper SensorUnavailable
automationStepper :: a -> Event a -> Automation sensors actuators (Behavior a)
automationStepper a e = Automation $ lift $ stepper a e
+-- | `changes` lifted into `Automation`
+automationChanges :: Behavior a -> Automation sensors actuators (Event (Future a))
+automationChanges = Automation . lift . changes
+
-- | Call when a sensor has sensed a value.
--
-- > getFridgeTemperature >>= sensed (fridgeTemperature sensors)
@@ -375,7 +382,7 @@ clockSignalBehavior getsensor = Automation $ do
-- | For controlling relays and other things that can have
-- their power turned on and off.
data PowerChange = PowerOff | PowerOn
- deriving (Show)
+ deriving (Show, Eq, Ord)
-- | Makes an Event drive an actuator.
actuateEvent :: Event a -> (a -> actuators) -> Automation sensors actuators ()
@@ -383,15 +390,23 @@ actuateEvent e getactuator = Automation $ do
actuators <- snd <$> ask
lift $ reactimate $ fmap (actuators . getactuator) e
+-- | Like `actuateEvent` but with a Future, as produced by
+-- `automationChanges`
+actuateFutureEvent :: Event (Future a) -> (a -> actuators) -> Automation sensors actuators ()
+actuateFutureEvent e getactuator = Automation $ actuateFutureEvent' e getactuator
+
+actuateFutureEvent' :: Event (Future a) -> (a -> actuators) -> ReaderT (sensors, actuators -> IO ()) MomentIO ()
+actuateFutureEvent' e getactuator = do
+ actuators <- snd <$> ask
+ lift $ reactimate' $ fmap (actuators . getactuator) <$> e
+
-- | Makes a Behavior drive an actuator. This will happen when the
-- Behavior's value changes, but possibly more often as well, depending on
-- how the Behavior is constructed.
actuateBehavior :: Behavior a -> (a -> actuators) -> Automation sensors actuators ()
actuateBehavior b getactuator = Automation $ do
- actuators <- snd <$> ask
- c <- lift $ changes b
- lift $ reactimate' $
- fmap (actuators . getactuator) <$> c
+ e <- lift $ changes b
+ actuateFutureEvent' e getactuator
-- | Variant of `actuateBehavior` that does nothing when a behavior
-- is Nothing.
diff --git a/reactive-banana-automation.cabal b/reactive-banana-automation.cabal
index 48b12fd..d730b2e 100644
--- a/reactive-banana-automation.cabal
+++ b/reactive-banana-automation.cabal
@@ -1,5 +1,5 @@
Name: reactive-banana-automation
-Version: 0.5.0
+Version: 0.5.1
Cabal-Version: >= 1.8
License: AGPL-3
Maintainer: Joey Hess <id@joeyh.name>