From 1bd17e699320099996a4ee7f31acf20c3bab135b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 7 Apr 2010 13:27:10 +0200 Subject: Corrected nonblocking messages --- src/HWiid.hsc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/HWiid.hsc b/src/HWiid.hsc index 994aca1..56d87c6 100644 --- a/src/HWiid.hsc +++ b/src/HWiid.hsc @@ -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 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 \ No newline at end of file + if (ret == 0) then do + list <- peekArray (fromIntegral count) array + free array + return list + else return [] -- cgit v1.2.3