June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
22
Task/Joystick-position/Haskell/joystick-position.hs
Normal file
22
Task/Joystick-position/Haskell/joystick-position.hs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import qualified Graphics.UI.GLFW as GLFW -- cabal install GLFW-b
|
||||
import Graphics.Win32.Key
|
||||
import Control.Monad.RWS.Strict (liftIO)
|
||||
|
||||
main = do
|
||||
liftIO $ do
|
||||
_ <- GLFW.init
|
||||
GLFW.pollEvents
|
||||
(jxrot, jyrot) <- liftIO $ getJoystickDirections GLFW.Joystick'1
|
||||
putStrLn $ (show jxrot) ++ " " ++ (show jyrot)
|
||||
w <- getAsyncKeyState 27 -- ESC pressed?
|
||||
if (w<1) then main else do
|
||||
GLFW.terminate
|
||||
return ()
|
||||
|
||||
getJoystickDirections :: GLFW.Joystick -> IO (Double, Double)
|
||||
|
||||
getJoystickDirections js = do
|
||||
maxes <- GLFW.getJoystickAxes js
|
||||
return $ case maxes of
|
||||
(Just (x:y:_)) -> (-y, x)
|
||||
_ -> ( 0, 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue