{-# LANGUAGE ScopedTypeVariables #-}
module Control.Debounce
(
DI.DebounceSettings
, defaultDebounceSettings
, DI.debounceFreq
, DI.debounceAction
, DI.debounceEdge
, DI.leadingEdge
, DI.trailingEdge
, mkDebounce
) where
import Control.Concurrent (newEmptyMVar, threadDelay)
import qualified Control.Debounce.Internal as DI
defaultDebounceSettings :: DI.DebounceSettings
defaultDebounceSettings :: DebounceSettings
defaultDebounceSettings = DebounceSettings :: Int -> IO () -> DebounceEdge -> DebounceSettings
DI.DebounceSettings
{ debounceFreq :: Int
DI.debounceFreq = Int
1000000
, debounceAction :: IO ()
DI.debounceAction = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, debounceEdge :: DebounceEdge
DI.debounceEdge = DebounceEdge
DI.leadingEdge
}
mkDebounce :: DI.DebounceSettings -> IO (IO ())
mkDebounce :: DebounceSettings -> IO (IO ())
mkDebounce DebounceSettings
settings = do
MVar ()
baton <- IO (MVar ())
forall a. IO (MVar a)
newEmptyMVar
MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ())
DI.mkDebounceInternal MVar ()
baton Int -> IO ()
threadDelay DebounceSettings
settings