Added support for calibration
This commit is contained in:
parent
2ce242f608
commit
1a31573eb8
1 changed files with 52 additions and 10 deletions
|
@ -4,8 +4,11 @@ module HWiid ( BDAddr(..)
|
||||||
, Wiimote
|
, Wiimote
|
||||||
, WiimoteIRSource(..)
|
, WiimoteIRSource(..)
|
||||||
, WiimoteState(..)
|
, WiimoteState(..)
|
||||||
|
, WiimoteExtType
|
||||||
, WiimoteExtState(..)
|
, WiimoteExtState(..)
|
||||||
|
, WiimoteMesgType
|
||||||
, WiimoteMesg(..)
|
, WiimoteMesg(..)
|
||||||
|
, WiimoteAccCal(..)
|
||||||
, nullWiimote
|
, nullWiimote
|
||||||
, bdAddrAny
|
, bdAddrAny
|
||||||
, hwiidFlagMesgInterface
|
, hwiidFlagMesgInterface
|
||||||
|
@ -46,6 +49,7 @@ module HWiid ( BDAddr(..)
|
||||||
, hwiidSetReportMode
|
, hwiidSetReportMode
|
||||||
, hwiidSetLed
|
, hwiidSetLed
|
||||||
, hwiidGetMesg
|
, hwiidGetMesg
|
||||||
|
, hwiidGetAccCal
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,17 +154,21 @@ hwiidIRMaxY :: CInt
|
||||||
hwiidIRMaxY = (#const CWIID_IR_Y_MAX)
|
hwiidIRMaxY = (#const CWIID_IR_Y_MAX)
|
||||||
|
|
||||||
|
|
||||||
hwiidMesgTypeStatus :: (#type enum cwiid_mesg_type)
|
type WiimoteMesgType = (#type enum cwiid_mesg_type)
|
||||||
|
|
||||||
|
hwiidMesgTypeStatus :: WiimoteMesgType
|
||||||
hwiidMesgTypeStatus = (#const CWIID_MESG_STATUS)
|
hwiidMesgTypeStatus = (#const CWIID_MESG_STATUS)
|
||||||
|
|
||||||
hwiidMesgTypeButton :: (#type enum cwiid_mesg_type)
|
hwiidMesgTypeButton :: WiimoteMesgType
|
||||||
hwiidMesgTypeButton = (#const CWIID_MESG_BTN)
|
hwiidMesgTypeButton = (#const CWIID_MESG_BTN)
|
||||||
|
|
||||||
|
|
||||||
hwiidExtNone :: (#type enum cwiid_ext_type)
|
type WiimoteExtType = (#type enum cwiid_ext_type)
|
||||||
|
|
||||||
|
hwiidExtNone :: WiimoteExtType
|
||||||
hwiidExtNone = (#const CWIID_EXT_NONE)
|
hwiidExtNone = (#const CWIID_EXT_NONE)
|
||||||
|
|
||||||
hwiidExtNunchuk :: (#type enum cwiid_ext_type)
|
hwiidExtNunchuk :: WiimoteExtType
|
||||||
hwiidExtNunchuk = (#const CWIID_EXT_NUNCHUK)
|
hwiidExtNunchuk = (#const CWIID_EXT_NUNCHUK)
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,15 +252,15 @@ instance Storable WiimoteState where
|
||||||
poke _ _ = fail "Can't write WiimoteState"
|
poke _ _ = fail "Can't write WiimoteState"
|
||||||
|
|
||||||
data WiimoteMesg = WiimoteStatusMesg
|
data WiimoteMesg = WiimoteStatusMesg
|
||||||
{ mesgType :: (#type enum cwiid_mesg_type)
|
{ mesgType :: WiimoteMesgType
|
||||||
, mesgBattery :: Word8
|
, mesgBattery :: Word8
|
||||||
}
|
}
|
||||||
| WiimoteButtonMesg
|
| WiimoteButtonMesg
|
||||||
{ mesgType :: (#type enum cwiid_mesg_type)
|
{ mesgType :: WiimoteMesgType
|
||||||
, mesgButtons :: Word16
|
, mesgButtons :: Word16
|
||||||
}
|
}
|
||||||
| WiimoteMesgOther
|
| WiimoteMesgOther
|
||||||
{ mesgType :: (#type enum cwiid_mesg_type)
|
{ mesgType :: WiimoteMesgType
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
@ -277,17 +285,17 @@ instance Storable WiimoteMesg where
|
||||||
|
|
||||||
|
|
||||||
data WiimoteExtState = WiimoteNunchukState
|
data WiimoteExtState = WiimoteNunchukState
|
||||||
{ extType :: (#type enum cwiid_ext_type)
|
{ extType :: WiimoteExtType
|
||||||
, extNunchukStickX :: Word8
|
, extNunchukStickX :: Word8
|
||||||
, extNunchukStickY :: Word8
|
, extNunchukStickY :: Word8
|
||||||
, extNunchukButtons :: Word8
|
, extNunchukButtons :: Word8
|
||||||
}
|
}
|
||||||
| WiimoteOtherState
|
| WiimoteOtherState
|
||||||
{ extType :: (#type enum cwiid_ext_type)
|
{ extType :: WiimoteExtType
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
peekExtState :: (#type enum cwiid_ext_type) -> Ptr WiimoteExtState -> IO WiimoteExtState
|
peekExtState :: WiimoteExtType -> Ptr WiimoteExtState -> IO WiimoteExtState
|
||||||
peekExtState exttype state
|
peekExtState exttype state
|
||||||
| exttype == hwiidExtNunchuk = do
|
| exttype == hwiidExtNunchuk = do
|
||||||
posx <- (#peek struct nunchuk_state, stick[0]) state
|
posx <- (#peek struct nunchuk_state, stick[0]) state
|
||||||
|
@ -295,6 +303,33 @@ peekExtState exttype state
|
||||||
buttons <- (#peek struct nunchuk_state, buttons) state
|
buttons <- (#peek struct nunchuk_state, buttons) state
|
||||||
return $ WiimoteNunchukState exttype posx posy buttons
|
return $ WiimoteNunchukState exttype posx posy buttons
|
||||||
| otherwise = return $ WiimoteOtherState exttype
|
| otherwise = return $ WiimoteOtherState exttype
|
||||||
|
|
||||||
|
|
||||||
|
data WiimoteAccCal = WiimoteAccCal
|
||||||
|
{ accCalZeroX :: Word8
|
||||||
|
, accCalZeroY :: Word8
|
||||||
|
, accCalZeroZ :: Word8
|
||||||
|
, accCalOneX :: Word8
|
||||||
|
, accCalOneY :: Word8
|
||||||
|
, accCalOneZ :: Word8
|
||||||
|
}
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
instance Storable WiimoteAccCal where
|
||||||
|
sizeOf _ = (#size struct acc_cal)
|
||||||
|
alignment _ = alignment (undefined :: CInt)
|
||||||
|
|
||||||
|
peek cal = do
|
||||||
|
zerox <- (#peek struct acc_cal, zero[0]) cal
|
||||||
|
zeroy <- (#peek struct acc_cal, zero[1]) cal
|
||||||
|
zeroz <- (#peek struct acc_cal, zero[2]) cal
|
||||||
|
onex <- (#peek struct acc_cal, one[0]) cal
|
||||||
|
oney <- (#peek struct acc_cal, one[1]) cal
|
||||||
|
onez <- (#peek struct acc_cal, one[2]) cal
|
||||||
|
|
||||||
|
return $ WiimoteAccCal zerox zeroy zeroz onex oney onez
|
||||||
|
|
||||||
|
poke _ _ = fail "Can't write WiimoteAccCal"
|
||||||
|
|
||||||
|
|
||||||
newtype Wiimote = Wiimote (Ptr Wiimote) deriving (Eq, Ord, Show, Storable)
|
newtype Wiimote = Wiimote (Ptr Wiimote) deriving (Eq, Ord, Show, Storable)
|
||||||
|
@ -346,3 +381,10 @@ hwiidGetMesg wiimote = alloca $ \countptr -> alloca $ \arrayptr -> alloca $ \tim
|
||||||
free array
|
free array
|
||||||
return list
|
return list
|
||||||
else return []
|
else return []
|
||||||
|
foreign import ccall unsafe "cwiid.h cwiid_get_acc_cal"
|
||||||
|
cwiid_get_acc_cal :: Wiimote -> WiimoteExtType -> Ptr WiimoteAccCal -> IO CInt
|
||||||
|
|
||||||
|
hwiidGetAccCal wiimote exttype = alloca $ \calptr -> do
|
||||||
|
cwiid_get_acc_cal wiimote exttype calptr
|
||||||
|
cal <- peek calptr
|
||||||
|
return cal
|
||||||
|
|
Reference in a new issue