Corrected nonblocking messages

This commit is contained in:
Matthias Schiffer 2010-04-07 13:27:10 +02:00
parent 1b4d7204a8
commit 1bd17e6993

View file

@ -27,6 +27,8 @@ module HWiid ( BDAddr(..)
, hwiidButtonPlus , hwiidButtonPlus
, hwiidNunchukButtonZ , hwiidNunchukButtonZ
, hwiidNunchukButtonC , hwiidNunchukButtonC
, hwiidMesgTypeStatus
, hwiidMesgTypeButton
, hwiidOpen , hwiidOpen
, hwiidOpenTimeout , hwiidOpenTimeout
, hwiidClose , hwiidClose
@ -48,7 +50,6 @@ import Foreign.Ptr
import Foreign.Storable import Foreign.Storable
import System.Posix.Clock (TimeSpec) import System.Posix.Clock (TimeSpec)
#include <cwiid.h> #include <cwiid.h>
hwiidFlagMesgInterface :: CInt hwiidFlagMesgInterface :: CInt
@ -244,11 +245,12 @@ foreign import ccall unsafe "cwiid.h cwiid_get_mesg"
hwiidGetMesg :: Wiimote -> IO [WiimoteMesg] hwiidGetMesg :: Wiimote -> IO [WiimoteMesg]
hwiidGetMesg wiimote = alloca $ \countptr -> alloca $ \arrayptr -> alloca $ \timestamp -> do 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 count <- peek countptr
array <- peek arrayptr array <- peek arrayptr
ret <- peekArray (fromIntegral count) array if (ret == 0) then do
free array list <- peekArray (fromIntegral count) array
free array
return ret return list
else return []