2018-01-09 17:40:54 +00:00
|
|
|
module Affection.MessageBus.Message.JoystickMessage
|
|
|
|
( JoystickMessage(..)
|
2018-09-25 05:02:33 +00:00
|
|
|
-- | Vector export
|
|
|
|
, Linear.V2
|
2018-01-09 17:40:54 +00:00
|
|
|
-- | SDL exports
|
|
|
|
, SDL.JoyHatPosition
|
|
|
|
, SDL.JoyButtonState
|
|
|
|
, SDL.JoyDeviceConnection
|
|
|
|
-- | Number exports
|
2018-09-25 14:10:36 +00:00
|
|
|
, Word8
|
|
|
|
, Int16
|
|
|
|
, Int32
|
2018-01-09 17:40:54 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Affection.MessageBus.Message.Class
|
|
|
|
|
2018-09-25 14:10:36 +00:00
|
|
|
import Data.Word (Word8)
|
|
|
|
import Data.Int (Int32, Int16)
|
2018-01-09 17:40:54 +00:00
|
|
|
|
|
|
|
import qualified SDL
|
|
|
|
|
|
|
|
import Linear (V2(..))
|
|
|
|
|
2018-09-25 14:10:36 +00:00
|
|
|
-- | Datatype for handling all possible joystick events handed over from sdl2
|
2018-01-09 17:40:54 +00:00
|
|
|
data JoystickMessage
|
2018-09-25 05:02:33 +00:00
|
|
|
= MsgJoystickAxis -- ^ Movement of a Joystick axis
|
|
|
|
{ msgJAWhen :: Double -- ^ Time of event
|
|
|
|
, msgJAWhich :: Int32 -- ^ Joystick identifier
|
|
|
|
, msgJAAxis :: Word8 -- ^ Axis identifier
|
|
|
|
, msgJAValue :: Int16 -- ^ Axis value
|
2018-01-09 17:40:54 +00:00
|
|
|
}
|
2018-09-25 05:02:33 +00:00
|
|
|
| MsgJoystickBall -- ^ Movement of a joystick ball controller
|
|
|
|
{ msgJBWhen :: Double -- ^ Time of event
|
|
|
|
, msgJBWhich :: Int32 -- ^ Joystick identifier
|
|
|
|
, msgJBBall :: Word8 -- ^ Ball identifier
|
|
|
|
, msgJBRelMotion :: V2 Int16 -- ^ Motion relative to previous position
|
2018-01-09 17:40:54 +00:00
|
|
|
}
|
2018-09-25 05:02:33 +00:00
|
|
|
| MsgJoystickHat -- ^ Movement of joystick hat controller
|
|
|
|
{ msgJHWhen :: Double -- Time of event
|
|
|
|
, msgJHWhich :: Int32 -- Joystick identifier
|
|
|
|
, msgJHHat :: Word8 -- Hat identifier
|
|
|
|
, msgJHPosition :: SDL.JoyHatPosition -- New hat position
|
2018-01-09 17:40:54 +00:00
|
|
|
}
|
2018-09-25 05:02:33 +00:00
|
|
|
| MsgJoystickButton -- ^ Joystick button event
|
|
|
|
{ msgJBWhen :: Double -- Time of event
|
|
|
|
, msgJBWhich :: Int32 -- Joystick identifier
|
|
|
|
, msgJBButton :: Word8 -- Button identifier
|
|
|
|
, msgJBState :: SDL.JoyButtonState -- New Button state
|
2018-01-09 17:40:54 +00:00
|
|
|
}
|
2018-09-25 05:02:33 +00:00
|
|
|
| MsgJoystickDevice -- ^ Joystick device event
|
|
|
|
{ msgJDWhen :: Double -- Time of event
|
|
|
|
, msgJDWhich :: Int32 -- Joystick identifier
|
|
|
|
, msgJDConnection :: SDL.JoyDeviceConnection -- Connection status
|
2018-01-09 17:40:54 +00:00
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
instance Message JoystickMessage where
|
2018-09-25 05:02:33 +00:00
|
|
|
msgTime (MsgJoystickAxis t _ _ _) = t
|
|
|
|
msgTime (MsgJoystickBall t _ _ _) = t
|
|
|
|
msgTime (MsgJoystickHat t _ _ _) = t
|
2018-01-09 17:40:54 +00:00
|
|
|
msgTime (MsgJoystickButton t _ _ _) = t
|
2018-09-25 05:02:33 +00:00
|
|
|
msgTime (MsgJoystickDevice t _ _) = t
|