Corrected nonblocking messages
This commit is contained in:
parent
1b4d7204a8
commit
1bd17e6993
1 changed files with 8 additions and 6 deletions
|
@ -27,6 +27,8 @@ module HWiid ( BDAddr(..)
|
|||
, hwiidButtonPlus
|
||||
, hwiidNunchukButtonZ
|
||||
, hwiidNunchukButtonC
|
||||
, hwiidMesgTypeStatus
|
||||
, hwiidMesgTypeButton
|
||||
, hwiidOpen
|
||||
, hwiidOpenTimeout
|
||||
, hwiidClose
|
||||
|
@ -48,7 +50,6 @@ import Foreign.Ptr
|
|||
import Foreign.Storable
|
||||
import System.Posix.Clock (TimeSpec)
|
||||
|
||||
|
||||
#include <cwiid.h>
|
||||
|
||||
hwiidFlagMesgInterface :: CInt
|
||||
|
@ -244,11 +245,12 @@ foreign import ccall unsafe "cwiid.h cwiid_get_mesg"
|
|||
|
||||
hwiidGetMesg :: Wiimote -> IO [WiimoteMesg]
|
||||
hwiidGetMesg wiimote = alloca $ \countptr -> alloca $ \arrayptr -> alloca $ \timestamp -> do
|
||||
cwiid_get_mesg wiimote countptr arrayptr timestamp
|
||||
ret <- cwiid_get_mesg wiimote countptr arrayptr timestamp
|
||||
count <- peek countptr
|
||||
array <- peek arrayptr
|
||||
|
||||
ret <- peekArray (fromIntegral count) array
|
||||
free array
|
||||
|
||||
return ret
|
||||
if (ret == 0) then do
|
||||
list <- peekArray (fromIntegral count) array
|
||||
free array
|
||||
return list
|
||||
else return []
|
||||
|
|
Reference in a new issue