Renamed most functions

This commit is contained in:
Matthias Schiffer 2010-04-10 15:43:20 +02:00
parent 1a31573eb8
commit 0dfe13e11f

View file

@ -11,45 +11,45 @@ module HWiid ( BDAddr(..)
, WiimoteAccCal(..) , WiimoteAccCal(..)
, nullWiimote , nullWiimote
, bdAddrAny , bdAddrAny
, hwiidFlagMesgInterface , flagMesgInterface
, hwiidFlagNonblock , flagNonblock
, hwiidReportStatus , reportStatus
, hwiidReportButtons , reportButtons
, hwiidReportAcc , reportAcc
, hwiidReportIR , reportIR
, hwiidReportNunchuk , reportNunchuk
, hwiidReportExt , reportExt
, hwiidLed1 , led1
, hwiidLed2 , led2
, hwiidLed3 , led3
, hwiidLed4 , led4
, hwiidButton2 , button2
, hwiidButton1 , button1
, hwiidButtonB , buttonB
, hwiidButtonA , buttonA
, hwiidButtonMinus , buttonMinus
, hwiidButtonHome , buttonHome
, hwiidButtonLeft , buttonLeft
, hwiidButtonRight , buttonRight
, hwiidButtonDown , buttonDown
, hwiidButtonUp , buttonUp
, hwiidButtonPlus , buttonPlus
, hwiidNunchukButtonZ , nunchukButtonZ
, hwiidNunchukButtonC , nunchukButtonC
, hwiidIRMaxX , irMaxX
, hwiidIRMaxY , irMaxY
, hwiidMesgTypeStatus , mesgTypeStatus
, hwiidMesgTypeButton , mesgTypeButton
, hwiidExtNone , extNone
, hwiidExtNunchuk , extNunchuk
, hwiidOpen , open
, hwiidOpenTimeout , openTimeout
, hwiidClose , close
, hwiidGetState , getState
, hwiidSetReportMode , setReportMode
, hwiidSetLed , setLed
, hwiidGetMesg , getMesg
, hwiidGetAccCal , getAccCal
) where ) where
@ -67,109 +67,109 @@ import System.Posix.Clock (TimeSpec)
#include <cwiid.h> #include <cwiid.h>
hwiidFlagMesgInterface :: CInt flagMesgInterface :: CInt
hwiidFlagMesgInterface = (#const CWIID_FLAG_MESG_IFC) flagMesgInterface = (#const CWIID_FLAG_MESG_IFC)
hwiidFlagNonblock :: CInt flagNonblock :: CInt
hwiidFlagNonblock = (#const CWIID_FLAG_NONBLOCK) flagNonblock = (#const CWIID_FLAG_NONBLOCK)
hwiidReportStatus :: Word8 reportStatus :: Word8
hwiidReportStatus = (#const CWIID_RPT_STATUS) reportStatus = (#const CWIID_RPT_STATUS)
hwiidReportButtons :: Word8 reportButtons :: Word8
hwiidReportButtons = (#const CWIID_RPT_BTN) reportButtons = (#const CWIID_RPT_BTN)
hwiidReportAcc :: Word8 reportAcc :: Word8
hwiidReportAcc = (#const CWIID_RPT_ACC) reportAcc = (#const CWIID_RPT_ACC)
hwiidReportIR :: Word8 reportIR :: Word8
hwiidReportIR = (#const CWIID_RPT_IR) reportIR = (#const CWIID_RPT_IR)
hwiidReportNunchuk :: Word8 reportNunchuk :: Word8
hwiidReportNunchuk = (#const CWIID_RPT_NUNCHUK) reportNunchuk = (#const CWIID_RPT_NUNCHUK)
hwiidReportExt :: Word8 reportExt :: Word8
hwiidReportExt = hwiidReportNunchuk reportExt = reportNunchuk
hwiidLed1 :: Word8 led1 :: Word8
hwiidLed1 = (#const CWIID_LED1_ON) led1 = (#const CWIID_LED1_ON)
hwiidLed2 :: Word8 led2 :: Word8
hwiidLed2 = (#const CWIID_LED2_ON) led2 = (#const CWIID_LED2_ON)
hwiidLed3 :: Word8 led3 :: Word8
hwiidLed3 = (#const CWIID_LED3_ON) led3 = (#const CWIID_LED3_ON)
hwiidLed4 :: Word8 led4 :: Word8
hwiidLed4 = (#const CWIID_LED4_ON) led4 = (#const CWIID_LED4_ON)
hwiidButton2 :: Word16 button2 :: Word16
hwiidButton2 = (#const CWIID_BTN_2) button2 = (#const CWIID_BTN_2)
hwiidButton1 :: Word16 button1 :: Word16
hwiidButton1 = (#const CWIID_BTN_1) button1 = (#const CWIID_BTN_1)
hwiidButtonB :: Word16 buttonB :: Word16
hwiidButtonB = (#const CWIID_BTN_B) buttonB = (#const CWIID_BTN_B)
hwiidButtonA :: Word16 buttonA :: Word16
hwiidButtonA = (#const CWIID_BTN_A) buttonA = (#const CWIID_BTN_A)
hwiidButtonMinus :: Word16 buttonMinus :: Word16
hwiidButtonMinus = (#const CWIID_BTN_MINUS) buttonMinus = (#const CWIID_BTN_MINUS)
hwiidButtonHome :: Word16 buttonHome :: Word16
hwiidButtonHome = (#const CWIID_BTN_HOME) buttonHome = (#const CWIID_BTN_HOME)
hwiidButtonLeft :: Word16 buttonLeft :: Word16
hwiidButtonLeft = (#const CWIID_BTN_LEFT) buttonLeft = (#const CWIID_BTN_LEFT)
hwiidButtonRight :: Word16 buttonRight :: Word16
hwiidButtonRight = (#const CWIID_BTN_RIGHT) buttonRight = (#const CWIID_BTN_RIGHT)
hwiidButtonDown :: Word16 buttonDown :: Word16
hwiidButtonDown = (#const CWIID_BTN_DOWN) buttonDown = (#const CWIID_BTN_DOWN)
hwiidButtonUp :: Word16 buttonUp :: Word16
hwiidButtonUp = (#const CWIID_BTN_UP) buttonUp = (#const CWIID_BTN_UP)
hwiidButtonPlus :: Word16 buttonPlus :: Word16
hwiidButtonPlus = (#const CWIID_BTN_PLUS) buttonPlus = (#const CWIID_BTN_PLUS)
hwiidNunchukButtonZ :: Word16 nunchukButtonZ :: Word16
hwiidNunchukButtonZ = (#const CWIID_NUNCHUK_BTN_Z) nunchukButtonZ = (#const CWIID_NUNCHUK_BTN_Z)
hwiidNunchukButtonC :: Word16 nunchukButtonC :: Word16
hwiidNunchukButtonC = (#const CWIID_NUNCHUK_BTN_C) nunchukButtonC = (#const CWIID_NUNCHUK_BTN_C)
hwiidIRMaxX :: CInt irMaxX :: CInt
hwiidIRMaxX = (#const CWIID_IR_X_MAX) irMaxX = (#const CWIID_IR_X_MAX)
hwiidIRMaxY :: CInt irMaxY :: CInt
hwiidIRMaxY = (#const CWIID_IR_Y_MAX) irMaxY = (#const CWIID_IR_Y_MAX)
type WiimoteMesgType = (#type enum cwiid_mesg_type) type WiimoteMesgType = (#type enum cwiid_mesg_type)
hwiidMesgTypeStatus :: WiimoteMesgType mesgTypeStatus :: WiimoteMesgType
hwiidMesgTypeStatus = (#const CWIID_MESG_STATUS) mesgTypeStatus = (#const CWIID_MESG_STATUS)
hwiidMesgTypeButton :: WiimoteMesgType mesgTypeButton :: WiimoteMesgType
hwiidMesgTypeButton = (#const CWIID_MESG_BTN) mesgTypeButton = (#const CWIID_MESG_BTN)
type WiimoteExtType = (#type enum cwiid_ext_type) type WiimoteExtType = (#type enum cwiid_ext_type)
hwiidExtNone :: WiimoteExtType extNone :: WiimoteExtType
hwiidExtNone = (#const CWIID_EXT_NONE) extNone = (#const CWIID_EXT_NONE)
hwiidExtNunchuk :: WiimoteExtType extNunchuk :: WiimoteExtType
hwiidExtNunchuk = (#const CWIID_EXT_NUNCHUK) extNunchuk = (#const CWIID_EXT_NUNCHUK)
data BDAddr = BDAddr (Word8, Word8, Word8, Word8, Word8, Word8) data BDAddr = BDAddr (Word8, Word8, Word8, Word8, Word8, Word8)
@ -272,10 +272,10 @@ instance Storable WiimoteMesg where
mesgtype <- (#peek union cwiid_mesg, type) mesg mesgtype <- (#peek union cwiid_mesg, type) mesg
case () of case () of
_ | mesgtype == hwiidMesgTypeStatus -> do _ | mesgtype == mesgTypeStatus -> do
battery <- (#peek struct cwiid_status_mesg, battery) mesg battery <- (#peek struct cwiid_status_mesg, battery) mesg
return $ WiimoteStatusMesg mesgtype battery return $ WiimoteStatusMesg mesgtype battery
| mesgtype == hwiidMesgTypeButton -> do | mesgtype == mesgTypeButton -> do
buttons <- (#peek struct cwiid_btn_mesg, buttons) mesg buttons <- (#peek struct cwiid_btn_mesg, buttons) mesg
return $ WiimoteButtonMesg mesgtype buttons return $ WiimoteButtonMesg mesgtype buttons
| otherwise -> return $ WiimoteMesgOther mesgtype | otherwise -> return $ WiimoteMesgOther mesgtype
@ -297,7 +297,7 @@ data WiimoteExtState = WiimoteNunchukState
peekExtState :: WiimoteExtType -> Ptr WiimoteExtState -> IO WiimoteExtState peekExtState :: WiimoteExtType -> Ptr WiimoteExtState -> IO WiimoteExtState
peekExtState exttype state peekExtState exttype state
| exttype == hwiidExtNunchuk = do | exttype == extNunchuk = do
posx <- (#peek struct nunchuk_state, stick[0]) state posx <- (#peek struct nunchuk_state, stick[0]) state
posy <- (#peek struct nunchuk_state, stick[1]) state posy <- (#peek struct nunchuk_state, stick[1]) state
buttons <- (#peek struct nunchuk_state, buttons) state buttons <- (#peek struct nunchuk_state, buttons) state
@ -341,50 +341,50 @@ nullWiimote = Wiimote nullPtr
foreign import ccall unsafe "cwiid.h cwiid_open_timeout" foreign import ccall unsafe "cwiid.h cwiid_open_timeout"
cwiid_open_timeout :: Ptr BDAddr -> CInt -> CInt -> IO Wiimote cwiid_open_timeout :: Ptr BDAddr -> CInt -> CInt -> IO Wiimote
hwiidOpenTimeout :: BDAddr -> CInt -> CInt -> IO Wiimote openTimeout :: BDAddr -> CInt -> CInt -> IO Wiimote
hwiidOpenTimeout addr flags timeout = with addr $ \addrptr -> cwiid_open_timeout addrptr flags timeout openTimeout addr flags timeout = with addr $ \addrptr -> cwiid_open_timeout addrptr flags timeout
defaultTimeout :: CInt defaultTimeout :: CInt
defaultTimeout = 5 defaultTimeout = 5
hwiidOpen :: BDAddr -> CInt -> IO Wiimote open :: BDAddr -> CInt -> IO Wiimote
hwiidOpen addr flags = hwiidOpenTimeout addr flags defaultTimeout open addr flags = openTimeout addr flags defaultTimeout
foreign import ccall unsafe "cwiid.h cwiid_close" foreign import ccall unsafe "cwiid.h cwiid_close"
hwiidClose :: Wiimote -> IO CInt close :: Wiimote -> IO CInt
foreign import ccall unsafe "cwiid.h cwiid_get_state" foreign import ccall unsafe "cwiid.h cwiid_get_state"
cwiid_get_state :: Wiimote -> Ptr WiimoteState -> IO CInt cwiid_get_state :: Wiimote -> Ptr WiimoteState -> IO CInt
hwiidGetState :: Wiimote -> IO WiimoteState getState :: Wiimote -> IO WiimoteState
hwiidGetState wiimote = alloca $ \state -> do getState wiimote = alloca $ \state -> do
cwiid_get_state wiimote state cwiid_get_state wiimote state
peek state peek state
foreign import ccall unsafe "cwiid.h cwiid_set_rpt_mode" foreign import ccall unsafe "cwiid.h cwiid_set_rpt_mode"
hwiidSetReportMode :: Wiimote -> Word8 -> IO CInt setReportMode :: Wiimote -> Word8 -> IO CInt
foreign import ccall unsafe "cwiid.h cwiid_set_led" foreign import ccall unsafe "cwiid.h cwiid_set_led"
hwiidSetLed :: Wiimote -> Word8 -> IO CInt setLed :: Wiimote -> Word8 -> IO CInt
foreign import ccall unsafe "cwiid.h cwiid_get_mesg" foreign import ccall unsafe "cwiid.h cwiid_get_mesg"
cwiid_get_mesg :: Wiimote -> Ptr CInt -> Ptr (Ptr WiimoteMesg) -> Ptr TimeSpec -> IO CInt cwiid_get_mesg :: Wiimote -> Ptr CInt -> Ptr (Ptr WiimoteMesg) -> Ptr TimeSpec -> IO CInt
hwiidGetMesg :: Wiimote -> IO [WiimoteMesg] getMesg :: Wiimote -> IO [WiimoteMesg]
hwiidGetMesg wiimote = alloca $ \countptr -> alloca $ \arrayptr -> alloca $ \timestamp -> do getMesg wiimote = alloca $ \countptr -> alloca $ \arrayptr -> alloca $ \timestamp -> do
ret <- cwiid_get_mesg wiimote countptr arrayptr timestamp ret <- cwiid_get_mesg wiimote countptr arrayptr timestamp
count <- peek countptr count <- peek countptr
array <- peek arrayptr array <- peek arrayptr
if (ret == 0) then do if (ret == 0) then do
list <- peekArray (fromIntegral count) array list <- peekArray (fromIntegral count) array
free array free array
return list return list
else return [] else return []
foreign import ccall unsafe "cwiid.h cwiid_get_acc_cal" foreign import ccall unsafe "cwiid.h cwiid_get_acc_cal"
cwiid_get_acc_cal :: Wiimote -> WiimoteExtType -> Ptr WiimoteAccCal -> IO CInt cwiid_get_acc_cal :: Wiimote -> WiimoteExtType -> Ptr WiimoteAccCal -> IO CInt
hwiidGetAccCal wiimote exttype = alloca $ \calptr -> do getAccCal wiimote exttype = alloca $ \calptr -> do
cwiid_get_acc_cal wiimote exttype calptr cwiid_get_acc_cal wiimote exttype calptr
cal <- peek calptr cal <- peek calptr
return cal return cal