{-# LANGUAGE RecordWildCards #-}
module Network.UI.Kafka.SpaceNav.Interpretation (
spacenavLoop
) where
import Data.ByteString.Lazy.Char8 (hGet)
import Network.UI.Kafka (ExitAction, LoopAction)
import Network.UI.Kafka.Interpretation (Interpretation(..), interpretationLoop)
import System.Hardware.Linux.SpaceNav (SpaceNav(..), byteLength, interpretSpaceNav)
import System.IO (IOMode(ReadMode), hClose, openFile)
spacenavLoop :: Interpretation FilePath Double
-> IO (ExitAction, LoopAction)
spacenavLoop interpretation@TrackInterpretation{..} =
do
let
analogHandler SpaceNavAnalog{..} = Just (number, setting)
analogHandler _ = Nothing
buttonHandler SpaceNavButton{..} = Just (number, pressed)
buttonHandler _ = Nothing
spacenav <- openFile device ReadMode
(exit, loop) <-
interpretationLoop analogHandler buttonHandler interpretation
$ interpretSpaceNav <$> hGet spacenav byteLength
return
(
do
exit
hClose spacenav
, loop
)