{-# LANGUAGE RecordWildCards #-}
module System.Hardware.Linux.Input (
InputEvent(..)
, byteLength
) where
import Data.Binary (Binary(..), encode)
import Data.Binary.Get (getWordhost, getWord16host, getWord32host)
import Data.Binary.Put (putWordhost, putWord16host, putWord32host)
import Data.Word (Word16, Word32)
import qualified Data.ByteString.Lazy as BS (length)
data InputEvent =
InputEvent
{
timeval :: (Word, Word)
, typ :: Word16
, code :: Word16
, value :: Word32
}
deriving (Eq, Ord, Read, Show)
instance Binary InputEvent where
get =
do
timeval <- (,) <$> getWordhost <*> getWordhost
typ <- getWord16host
code <- getWord16host
value <- getWord32host
return InputEvent{..}
put InputEvent{..} =
do
putWordhost $ fst timeval
putWordhost $ snd timeval
putWord16host typ
putWord16host code
putWord32host value
byteLength :: Integral a => a
byteLength =
fromIntegral
. BS.length
. encode
$ InputEvent (0, 0) 0 0 0