WiimotePlayer: Adapted to HWiid name changes
This commit is contained in:
parent
f78f24af9b
commit
2ff529b0b1
1 changed files with 13 additions and 13 deletions
|
@ -27,17 +27,17 @@ data WiimotePlayer = WiimotePlayer Wiimote WiimoteAccCal [(Float, Float)]
|
||||||
|
|
||||||
instance Player WiimotePlayer where
|
instance Player WiimotePlayer where
|
||||||
playerUpdate (WiimotePlayer wiimote cal oldaims) tank = do
|
playerUpdate (WiimotePlayer wiimote cal oldaims) tank = do
|
||||||
state <- hwiidGetState wiimote
|
state <- getState wiimote
|
||||||
messages <- hwiidGetMesg wiimote
|
messages <- getMesg wiimote
|
||||||
|
|
||||||
let buttons = stateButtons state
|
let buttons = stateButtons state
|
||||||
shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages
|
shoot = any (\m -> (mesgType m == mesgTypeButton) && (test (mesgButtons m) buttonB)) $ messages
|
||||||
foo = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonA)) $ messages
|
foo = any (\m -> (mesgType m == mesgTypeButton) && (test (mesgButtons m) buttonA)) $ messages
|
||||||
x = (if (test buttons hwiidButtonLeft) then (-1) else 0) + (if (test buttons hwiidButtonRight) then 1 else 0)
|
x = (if (test buttons buttonLeft) then (-1) else 0) + (if (test buttons buttonRight) then 1 else 0)
|
||||||
y = (if (test buttons hwiidButtonDown) then (-1) else 0) + (if (test buttons hwiidButtonUp) then 1 else 0)
|
y = (if (test buttons buttonDown) then (-1) else 0) + (if (test buttons buttonUp) then 1 else 0)
|
||||||
ext = stateExt state
|
ext = stateExt state
|
||||||
|
|
||||||
(mx, my) = if (extType ext) /= hwiidExtNunchuk
|
(mx, my) = if (extType ext) /= extNunchuk
|
||||||
then (x, y)
|
then (x, y)
|
||||||
else
|
else
|
||||||
let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80
|
let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80
|
||||||
|
@ -58,7 +58,7 @@ instance Player WiimotePlayer where
|
||||||
move = (mx /= 0 || my /= 0)
|
move = (mx /= 0 || my /= 0)
|
||||||
angle = atan2 my mx
|
angle = atan2 my mx
|
||||||
moveangle = if move then Just $ fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000 else Nothing
|
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)
|
return (WiimotePlayer wiimote cal aims, moveangle, move, aangle, shoot)
|
||||||
|
|
||||||
renderPlayer (WiimotePlayer _ _ []) = return ()
|
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))
|
c = ((fi . stateAccZ $ state)-(fi . accCalZeroZ $ cal))/((fi . accCalOneZ $ cal)-(fi . accCalZeroZ $ cal))
|
||||||
in (c*x + s*y, -s*x + c*y)
|
in (c*x + s*y, -s*x + c*y)
|
||||||
|
|
||||||
hMaxX = (fromIntegral hwiidIRMaxX)/2
|
hMaxX = (fromIntegral irMaxX)/2
|
||||||
hMaxY = (fromIntegral hwiidIRMaxY)/2
|
hMaxY = (fromIntegral irMaxY)/2
|
||||||
|
|
||||||
sortIRSourcesBySize :: [WiimoteIRSource] -> [WiimoteIRSource]
|
sortIRSourcesBySize :: [WiimoteIRSource] -> [WiimoteIRSource]
|
||||||
sortIRSourcesBySize = sortBy (flip compare `on` irSize)
|
sortIRSourcesBySize = sortBy (flip compare `on` irSize)
|
||||||
|
@ -138,10 +138,10 @@ lengthV a = sqrt $ lengthSqV a
|
||||||
|
|
||||||
newWiimotePlayer :: IO WiimotePlayer
|
newWiimotePlayer :: IO WiimotePlayer
|
||||||
newWiimotePlayer = do
|
newWiimotePlayer = do
|
||||||
wiimote <- hwiidOpen bdAddrAny (hwiidFlagMesgInterface .|. hwiidFlagNonblock)
|
wiimote <- open bdAddrAny (flagMesgInterface .|. flagNonblock)
|
||||||
when (wiimote == nullWiimote) $ fail "Wiimote error"
|
when (wiimote == nullWiimote) $ fail "Wiimote error"
|
||||||
hwiidSetReportMode wiimote (hwiidReportButtons .|. hwiidReportAcc .|. hwiidReportIR .|. hwiidReportNunchuk)
|
setReportMode wiimote (reportButtons .|. reportAcc .|. reportIR .|. reportNunchuk)
|
||||||
cal <- hwiidGetAccCal wiimote hwiidExtNone
|
cal <- getAccCal wiimote extNone
|
||||||
return $ WiimotePlayer wiimote cal []
|
return $ WiimotePlayer wiimote cal []
|
||||||
|
|
||||||
test :: (Bits a) => a -> a -> Bool
|
test :: (Bits a) => a -> a -> Bool
|
||||||
|
|
Reference in a new issue