diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/WiimotePlayer.hs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/WiimotePlayer.hs b/src/WiimotePlayer.hs index 6a93f22..697cdb0 100644 --- a/src/WiimotePlayer.hs +++ b/src/WiimotePlayer.hs @@ -27,17 +27,17 @@ data WiimotePlayer = WiimotePlayer Wiimote WiimoteAccCal [(Float, Float)] instance Player WiimotePlayer where playerUpdate (WiimotePlayer wiimote cal oldaims) tank = do - state <- hwiidGetState wiimote - messages <- hwiidGetMesg wiimote + state <- getState wiimote + messages <- getMesg wiimote let buttons = stateButtons state - shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages - foo = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonA)) $ messages - x = (if (test buttons hwiidButtonLeft) then (-1) else 0) + (if (test buttons hwiidButtonRight) then 1 else 0) - y = (if (test buttons hwiidButtonDown) then (-1) else 0) + (if (test buttons hwiidButtonUp) then 1 else 0) + shoot = any (\m -> (mesgType m == mesgTypeButton) && (test (mesgButtons m) buttonB)) $ messages + foo = any (\m -> (mesgType m == mesgTypeButton) && (test (mesgButtons m) buttonA)) $ messages + x = (if (test buttons buttonLeft) then (-1) else 0) + (if (test buttons buttonRight) then 1 else 0) + y = (if (test buttons buttonDown) then (-1) else 0) + (if (test buttons buttonUp) then 1 else 0) ext = stateExt state - (mx, my) = if (extType ext) /= hwiidExtNunchuk + (mx, my) = if (extType ext) /= extNunchuk then (x, y) else let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80 @@ -58,7 +58,7 @@ instance Player WiimotePlayer where move = (mx /= 0 || my /= 0) angle = atan2 my mx moveangle = if move then Just $ fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000 else Nothing - when foo $ print $ state + when foo $ print state return (WiimotePlayer wiimote cal aims, moveangle, move, aangle, shoot) renderPlayer (WiimotePlayer _ _ []) = return () @@ -117,8 +117,8 @@ handleIR state cal = handle $ sortIRSourcesByPos $ take 2 $ sortIRSourcesBySize c = ((fi . stateAccZ $ state)-(fi . accCalZeroZ $ cal))/((fi . accCalOneZ $ cal)-(fi . accCalZeroZ $ cal)) in (c*x + s*y, -s*x + c*y) - hMaxX = (fromIntegral hwiidIRMaxX)/2 - hMaxY = (fromIntegral hwiidIRMaxY)/2 + hMaxX = (fromIntegral irMaxX)/2 + hMaxY = (fromIntegral irMaxY)/2 sortIRSourcesBySize :: [WiimoteIRSource] -> [WiimoteIRSource] sortIRSourcesBySize = sortBy (flip compare `on` irSize) @@ -138,10 +138,10 @@ lengthV a = sqrt $ lengthSqV a newWiimotePlayer :: IO WiimotePlayer newWiimotePlayer = do - wiimote <- hwiidOpen bdAddrAny (hwiidFlagMesgInterface .|. hwiidFlagNonblock) + wiimote <- open bdAddrAny (flagMesgInterface .|. flagNonblock) when (wiimote == nullWiimote) $ fail "Wiimote error" - hwiidSetReportMode wiimote (hwiidReportButtons .|. hwiidReportAcc .|. hwiidReportIR .|. hwiidReportNunchuk) - cal <- hwiidGetAccCal wiimote hwiidExtNone + setReportMode wiimote (reportButtons .|. reportAcc .|. reportIR .|. reportNunchuk) + cal <- getAccCal wiimote extNone return $ WiimotePlayer wiimote cal [] test :: (Bits a) => a -> a -> Bool |