diff options
Diffstat (limited to 'hsm-pwm/Hsm/PWM.hs')
-rw-r--r-- | hsm-pwm/Hsm/PWM.hs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/hsm-pwm/Hsm/PWM.hs b/hsm-pwm/Hsm/PWM.hs index 400e704..9a4fe5c 100644 --- a/hsm-pwm/Hsm/PWM.hs +++ b/hsm-pwm/Hsm/PWM.hs @@ -20,7 +20,7 @@ module Hsm.PWM where import Control.Concurrent (threadDelay) -import Control.Monad (forM_, void) +import Control.Monad (forM_) import Control.Monad.Loops (untilM_) import Effectful (Dispatch (Static), DispatchOf, Eff, IOE, liftIO, (:>)) import Effectful.Dispatch.Static @@ -29,7 +29,7 @@ import Effectful.Dispatch.Static , evalStaticRep , unsafeEff_ ) -import Effectful.Resource (Resource, allocateEff_) +import Effectful.Exception (bracket_) import Hsm.Core.Serial (makeSerial) import Hsm.Log (Log, Severity (Info, Trace), logMsg) import System.FilePath ((</>)) @@ -100,12 +100,8 @@ setCycleDuration channel cycleDuration = do setDutyCycle channel $ cycleDuration `div` 2 setEnable channel True -runPWM - :: (IOE :> es, Log "pwm" :> es, Resource :> es) => Eff (PWM : es) a -> Eff es a -runPWM action = - evalStaticRep (PWM ()) $ do - void $ allocateEff_ pwmAlloc pwmDealloc - action +runPWM :: (IOE :> es, Log "pwm" :> es) => Eff (PWM : es) a -> Eff es a +runPWM = evalStaticRep (PWM ()) . bracket_ pwmAlloc pwmDealloc where exportPath = chipPath </> "export" unexportPath = chipPath </> "unexport" |