on master help sign in
Tweaks and doc cleanups
commitc44307f8a889019b8b6352d86e4cd5cbf8abe288 authorTom McLaughlin <pyro777@gmail.com> dateFri 5 Jul 2019, 15:20 (7 years ago) parent562a22e
2 files changed+24−18
auto-update/Control/Debounce.hs+4−15 auto-update/Control/Debounce/Internal.hs+20−3
auto-update/Control/Debounce.hs+4−15
@@ -11,7 +11,7 @@
1111-- printString <- 'mkDebounce' 'defaultDebounceSettings'
1212-- { 'debounceAction' = putStrLn "Running action"
1313-- , 'debounceFreq' = 5000000 -- 5 seconds
14−-- , 'debounceEdge' = 'trailingEdge' -- Trigger on the trailing edge
14+-- , 'debounceEdge' = 'DI.trailingEdge' -- Trigger on the trailing edge
1515-- }
1616-- @
1717--
@@ -32,8 +32,8 @@ module Control.Debounce
3232 , DI.debounceFreq
3333 , DI.debounceAction
3434 , DI.debounceEdge
35− , leadingEdge
36− , trailingEdge
35+ , DI.leadingEdge
36+ , DI.trailingEdge
3737 -- * Creation
3838 , mkDebounce
3939 ) where
@@ -48,7 +48,7 @@ defaultDebounceSettings :: DI.DebounceSettings
4848defaultDebounceSettings = DI.DebounceSettings
4949 { DI.debounceFreq = 1000000
5050 , DI.debounceAction = return ()
51− , DI.debounceEdge = leadingEdge
51+ , DI.debounceEdge = DI.leadingEdge
5252 }
5353
5454-- | Generate an action which will trigger the debounced action to be performed.
@@ -58,14 +58,3 @@ mkDebounce :: DI.DebounceSettings -> IO (IO ())
5858mkDebounce settings = do
5959 baton <- newEmptyMVar
6060 DI.mkDebounceInternal baton threadDelay settings
61−
62−-- | Perform the action immediately, and then begin a cooldown period.
63−-- If the trigger happens again during the cooldown, wait until the end of the cooldown
64−-- and then perform the action again, then enter a new cooldown period.
65−leadingEdge :: DI.DebounceEdge
66−leadingEdge = DI.Leading
67−
68−-- | Start a cooldown period and perform the action when the period ends. If another trigger
69−-- happens during the cooldown, it has no effect.
70−trailingEdge :: DI.DebounceEdge
71−trailingEdge = DI.Trailing
auto-update/Control/Debounce/Internal.hs+20−3
@@ -4,14 +4,15 @@
44module Control.Debounce.Internal (
55 DebounceSettings(..)
66 , DebounceEdge(..)
7+ , leadingEdge
8+ , trailingEdge
79 , mkDebounceInternal
810 ) where
911
1012import Control.Concurrent (forkIO)
1113import Control.Concurrent.MVar (takeMVar, tryPutMVar, tryTakeMVar, MVar)
1214import Control.Exception (SomeException, handle, mask_)
13−import Control.Monad (forever, void, when)
14−import Data.Maybe (isJust)
15+import Control.Monad (forever, void)
1516
1617-- | Settings to control how debouncing should work.
1718--
@@ -42,7 +43,7 @@ data DebounceSettings = DebounceSettings
4243 -- ^ Whether to perform the action on the leading edge or trailing edge of
4344 -- the timeout.
4445 --
45− -- Default: trailingEdge.
46+ -- Default: 'trailingEdge'.
4647 --
4748 -- @since 0.1.6
4849 }
@@ -61,6 +62,22 @@ data DebounceEdge =
6162 -- happens during the cooldown, it has no effect.
6263 deriving (Show, Eq)
6364
65+
66+-- | Perform the action immediately, and then begin a cooldown period.
67+-- If the trigger happens again during the cooldown, wait until the end of the cooldown
68+-- and then perform the action again, then enter a new cooldown period.
69+--
70+-- @since 0.1.6
71+leadingEdge :: DebounceEdge
72+leadingEdge = Leading
73+
74+-- | Start a cooldown period and perform the action when the period ends. If another trigger
75+-- happens during the cooldown, it has no effect.
76+--
77+-- @since 0.1.6
78+trailingEdge :: DebounceEdge
79+trailingEdge = Trailing
80+
6481mkDebounceInternal :: MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ())
6582mkDebounceInternal baton delayFn (DebounceSettings freq action edge) = do
6683 mask_ $ void $ forkIO $ forever $ do