From: Dylan Lloyd Date: Sun, 26 Feb 2012 18:15:44 +0000 (-0500) Subject: init X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=58b20da5d6cbf502cef3c31f0c6491e81a0772e6;p=powermate.git init --- 58b20da5d6cbf502cef3c31f0c6491e81a0772e6 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6e23d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +powermate +*.o +*.hi diff --git a/powermate.hs b/powermate.hs new file mode 100755 index 0000000..16a783f --- /dev/null +++ b/powermate.hs @@ -0,0 +1,55 @@ +module Main where + +import PowerMate +import System.IO +import System.Process + +data State = State { + stPowerMate :: Handle, + stVolume :: Int +} + +processEvent :: State -> Event -> IO State +processEvent state (Button True) = do + createProcess (proc "music-toggle" []) + return state +processEvent state (Button False) = return state + +processEvent state (Rotate dir) = do + if dir < 2 then createProcess (proc "volume-up" []) + else createProcess (proc "volume-down" []) + return state + +processEvent state (StatusChange status) = do + return state + +readState :: State -> IO State +readState state = do + return state + +next :: a -> (a -> IO a) -> IO () +next state func = do + newstate <- func state + next newstate func + return () + + +loop :: FilePath -> IO () +loop devname = do + powermate <- openDevice devname + + state <- readState $ State { stPowerMate=powermate, stVolume=0 } + + next state $ \call -> do + event <- readEventWithSkip powermate Nothing + case event of + Nothing -> return call + Just event -> processEvent call event + +main :: IO () +main = do + powermate <- searchForDevice + case powermate of + Nothing -> return () + Just work -> do + loop work