[show status, track volume Evan Martin **20060217055455] { hunk ./MPDMate.hs 15 - stConn :: MPD.ReconnectableConnection, - stVolume :: IORef Int + stConn :: MPD.ReconnectableConnection, + stVolume :: IORef Int, + stBrightness :: IORef Int hunk ./MPDMate.hs 28 - MPD.rcDo (stConn state) $ \conn -> MPD.runCommand_ conn ("volume " ++ show dir) + vol <- readIORef (stVolume state) + let newvol = max 0 $ min 100 $ vol + dir + putStrLn $ show newvol + MPD.rcDo (stConn state) $ \conn -> MPD.setVolume conn newvol + writeIORef (stVolume state) newvol hunk ./MPDMate.hs 34 -processEvent state PowerMate.Misc = do - putStrLn "misc" +processEvent state (PowerMate.StatusChange status) = do + putStrLn "New status:" + putStrLn $ " Brightness: " ++ show (PowerMate.brightness status) + putStrLn $ " Pulse Speed: " ++ show (PowerMate.pulse_speed status) + putStrLn $ " Pulse Mode: " ++ show (PowerMate.pulse_mode status) + putStrLn $ " Pulse Asleep: " ++ show (PowerMate.pulse_asleep status) + putStrLn $ " Pulse Awake: " ++ show (PowerMate.pulse_awake status) hunk ./MPDMate.hs 42 -mainLoop :: Handle -> IO () -mainLoop pm = do +readMPDStatus :: State -> IO () +readMPDStatus state = do + volume <- MPD.rcDo (stConn state) $ MPD.getVolume + writeIORef (stVolume state) volume + +mainLoop :: FilePath -> IO () +mainLoop devname = do + pm <- PowerMate.openDevice devname + PowerMate.writeStatus pm $ PowerMate.statusInit { PowerMate.brightness=100, PowerMate.pulse_asleep = True } + hunk ./MPDMate.hs 54 - let state = State { stConn=conn, stVolume=vol } + brightness <- newIORef 0 + let state = State { stConn=conn, stVolume=vol, stBrightness=brightness } + readMPDStatus state hunk ./MPDMate.hs 70 - handle_pm <- PowerMate.openDevice pmd - --PowerMate.writeStatus handle_pm $ PowerMate.statusInit { PowerMate.brightness=100, PowerMate.pulse_asleep = True } - mainLoop handle_pm + mainLoop pmd }