hcwiid-0.0.6.1: Library to interface with the wiimote

Copyright | Kiwamu Okabe Ivan Perez and the cwiid team
License | GPL-2
Maintainer | ivan.perez@keera.co.uk
Stability | experimental
Portability | unknown
Safe Haskell | Safe
Language | Haskell98

System.CWiid

Contents

- Initialization
- State
- Reception mode
- Leds
  - Led operations
- Rumble
- Buttons
- Accelerometers
- Infra-red

Description

Bindings for the cwiid library, a working userspace driver along with various applications implementing event drivers, multiple Wiimote connectivity, gesture recognition, and other Wiimote-based functionality.

The current implementation is rather incomplete. In particular:

- Some Haskell functions (those related to rpt mode, rumble, leds) had hard-coded values in them. Therefore, they implemented only a very partial interface to their C counterparts. The new versions should be tested and, if any other function is like this, then exported properly.
- Not all functions/wiimote fields are accessible. In particular, acceleromoter and IR is in testing stage. Nunchuck, calibration, wiimote plus are not handled at all (but will be in the future).

All in all, the code works quite well and is currently being used to implement several real games.

Synopsis

- cwiidOpen :: IO (Maybe CWiidWiimote)
- data CWiidWiimote
- data CWiidState = CWiidState {
  - rptMode :: Int
  - led :: Int
  - rumble :: Int
  - battery :: Int
  - buttons :: Int
  - acc :: [Int]
  - irSrc :: [CWiidIRSrc]
  }
- cwiidSetRptMode :: CWiidWiimote -> CUChar -> IO CInt
- data CWiidLedFlag
- cwiidLed1 :: CWiidLedFlag
- cwiidLed2 :: CWiidLedFlag
- cwiidLed3 :: CWiidLedFlag
- cwiidLed4 :: CWiidLedFlag
- cwiidSetLed :: CWiidWiimote -> CWiidLedFlag -> IO CInt
- combineCwiidLedFlag :: [CWiidLedFlag] -> CWiidLedFlag
- cwiidSetRumble :: CWiidWiimote -> CUChar -> IO CInt
- cwiidGetBtnState :: CWiidWiimote -> IO CWiidBtnFlag
- cwiidIsBtnPushed :: CWiidBtnFlag -> CWiidBtnFlag -> Bool
- cwiidBtn2 :: CWiidBtnFlag
- cwiidBtn1 :: CWiidBtnFlag
- cwiidBtnB :: CWiidBtnFlag
- cwiidBtnA :: CWiidBtnFlag
- cwiidBtnMinus :: CWiidBtnFlag
- cwiidBtnHome :: CWiidBtnFlag
- cwiidBtnLeft :: CWiidBtnFlag
- cwiidBtnRight :: CWiidBtnFlag
- cwiidBtnDown :: CWiidBtnFlag
- cwiidBtnUp :: CWiidBtnFlag
- cwiidBtnPlus :: CWiidBtnFlag
- combineCwiidBtnFlag :: [CWiidBtnFlag] -> CWiidBtnFlag
- diffCwiidBtnFlag :: CWiidBtnFlag -> CWiidBtnFlag -> CWiidBtnFlag
- newtype CWiidBtnFlag = CWiidBtnFlag {
  - unCWiidBtnFlag :: Int
  }
- cwiidGetAcc :: CWiidWiimote -> IO CWiidAcc
- newtype CWiidAcc = CWiidAcc {
  - unCWiidAcc :: [Int]
  }
- data CWiidIRSrc = CWiidIRSrc {
  - cwiidIRSrcValid :: Bool
  - cwiidIRSrcPosX :: Int
  - cwiidIRSrcPosY :: Int
  - cwiidIRSrcSize :: Int
  }
- cwiidGetIR :: CWiidWiimote -> IO [CWiidIRSrc]

# Initialization

cwiidOpen :: IO (Maybe CWiidWiimote) Source #

Try to establish a connection to any existing Wiimote using any existing bluetooth interface.

The function returns `Nothing` if there is no bluetooth interface or if no wiimote can be located. If the connection succeeds, a `CWiidWiimote` is returned (inside a `Just`), which can be used to poll the wiimote using other functions.

There is a default timeout of 5 seconds.

- TODO: export cwiid_open_time and cwiid_close as well.

data CWiidWiimote Source #

A connection to an existing wiimote. Use `cwiidOpen` to connect to a wiimote and obtain one of these.

# State

data CWiidState Source #

The state of the wiimote. Use `cwiidSetRptMode` to enable/disable sensors.

- FIXME: incomplete state
- FIXME: export get_state

Constructors

CWiidState |

Fields

- rptMode :: Int
- led :: Int
- rumble :: Int
- battery :: Int
- buttons :: Int
- acc :: [Int]
- irSrc :: [CWiidIRSrc]

#### Instances

Instances details

Show CWiidState Source # |
Instance details Defined in System.CWiid Methods showsPrec :: Int -> CWiidState -> ShowS show :: CWiidState -> String showList :: [CWiidState] -> ShowS
Storable CWiidState Source # |

Instance details

Defined in System.CWiid

Methods

sizeOf :: CWiidState -> Int

alignment :: CWiidState -> Int

peekElemOff :: Ptr CWiidState -> Int -> IO CWiidState

pokeElemOff :: Ptr CWiidState -> Int -> CWiidState -> IO ()

peekByteOff :: Ptr b -> Int -> IO CWiidState

pokeByteOff :: Ptr b -> Int -> CWiidState -> IO ()

peek :: Ptr CWiidState -> IO CWiidState

poke :: Ptr CWiidState -> CWiidState -> IO ()

# Reception mode

cwiidSetRptMode :: CWiidWiimote -> CUChar -> IO CInt Source #

Enable/disable reception of certain sensors. Use 2 to enable buttons.

# Leds

data CWiidLedFlag Source #

#### Instances

Instances details

Eq CWiidLedFlag Source # |
Instance details Defined in System.CWiid Methods (==) :: CWiidLedFlag -> CWiidLedFlag -> Bool (/=) :: CWiidLedFlag -> CWiidLedFlag -> Bool
Show CWiidLedFlag Source # |
Instance details Defined in System.CWiid Methods showsPrec :: Int -> CWiidLedFlag -> ShowS show :: CWiidLedFlag -> String showList :: [CWiidLedFlag] -> ShowS

cwiidLed1 :: CWiidLedFlag Source #

Flag with exactly led 1 enabled. Use `combineCwiidLedFlag` to create flags with several leds enabled.

cwiidLed2 :: CWiidLedFlag Source #

Flag with exactly led 2 enabled. Use `combineCwiidLedFlag` to create flags with several leds enabled.

cwiidLed3 :: CWiidLedFlag Source #

Flag with exactly led 2 enabled. Use `combineCwiidLedFlag` to create flags with several leds enabled.

cwiidLed4 :: CWiidLedFlag Source #

Flag with exactly led 4 enabled. Use `combineCwiidLedFlag` to create flags with several leds enabled.

## Led operations

cwiidSetLed :: CWiidWiimote -> CWiidLedFlag -> IO CInt Source #

Enable/disable certain leds.

Use `cwiidLed1` .. `cwiidLed4` together with `combineCwiidLedFlag` to create a flag with just the leds you want enabled and change all at once with one operation.

combineCwiidLedFlag :: [CWiidLedFlag] -> CWiidLedFlag Source #

Combine several led flags into one led flag with those leds enabled and all other leds disabled.

# Rumble

cwiidSetRumble :: CWiidWiimote -> CUChar -> IO CInt Source #

# Buttons

cwiidGetBtnState :: CWiidWiimote -> IO CWiidBtnFlag Source #

Returns a mask with the buttons that are currently pushed.

cwiidIsBtnPushed Source #

Arguments

:: CWiidBtnFlag | The button flags as returned by `cwiidGetBtnState`.
-> CWiidBtnFlag | A mask that flags the button/s that we want to check.
-> Bool | `True` if they are all pushed, `False` otherwise.

Returns `True` if the button indicated by the flag is pushed, `False` otherwise.

This is a pure function, so the first argument must be the button flags as returned by `cwiidGetBtnState`.

cwiidBtn2 :: CWiidBtnFlag Source #

cwiidBtn1 :: CWiidBtnFlag Source #

cwiidBtnB :: CWiidBtnFlag Source #

cwiidBtnA :: CWiidBtnFlag Source #

cwiidBtnMinus :: CWiidBtnFlag Source #

cwiidBtnHome :: CWiidBtnFlag Source #

cwiidBtnLeft :: CWiidBtnFlag Source #

cwiidBtnRight :: CWiidBtnFlag Source #

cwiidBtnDown :: CWiidBtnFlag Source #

cwiidBtnUp :: CWiidBtnFlag Source #

cwiidBtnPlus :: CWiidBtnFlag Source #

combineCwiidBtnFlag :: [CWiidBtnFlag] -> CWiidBtnFlag Source #

diffCwiidBtnFlag :: CWiidBtnFlag -> CWiidBtnFlag -> CWiidBtnFlag Source #

newtype CWiidBtnFlag Source #

Constructors

CWiidBtnFlag |

Fields

- unCWiidBtnFlag :: Int

#### Instances

Instances details

Eq CWiidBtnFlag Source # |
Instance details Defined in System.CWiid Methods (==) :: CWiidBtnFlag -> CWiidBtnFlag -> Bool (/=) :: CWiidBtnFlag -> CWiidBtnFlag -> Bool
Show CWiidBtnFlag Source # |
Instance details Defined in System.CWiid Methods showsPrec :: Int -> CWiidBtnFlag -> ShowS show :: CWiidBtnFlag -> String showList :: [CWiidBtnFlag] -> ShowS

# Accelerometers

cwiidGetAcc :: CWiidWiimote -> IO CWiidAcc Source #

Obtain accelerometer information. FIXME: read wmgui/main.c:cwiid_acc(1119) to understand how to use this information, what else might need to be exported, and how to calibrate the accelerometers.

newtype CWiidAcc Source #

Array of accelerometer information. It will always contain exactly three elements.

- TODO: provide a more informative and restrictive interface with exactly three named Int (byte?) fields.

Constructors

CWiidAcc |

Fields

- unCWiidAcc :: [Int]

#### Instances

Instances details

Eq CWiidAcc Source # |
Instance details Defined in System.CWiid Methods (==) :: CWiidAcc -> CWiidAcc -> Bool (/=) :: CWiidAcc -> CWiidAcc -> Bool
Show CWiidAcc Source # |
Instance details Defined in System.CWiid Methods showsPrec :: Int -> CWiidAcc -> ShowS show :: CWiidAcc -> String showList :: [CWiidAcc] -> ShowS

# Infra-red

data CWiidIRSrc Source #

Internal representation of an infrared point. You should no use it unless you know what you are doing; use `CWiidIR` instead.

Constructors

CWiidIRSrc |

Fields

- cwiidIRSrcValid :: Bool
- cwiidIRSrcPosX :: Int
- cwiidIRSrcPosY :: Int
- cwiidIRSrcSize :: Int

#### Instances

Instances details

Show CWiidIRSrc Source # |
Instance details Defined in System.CWiid Methods showsPrec :: Int -> CWiidIRSrc -> ShowS show :: CWiidIRSrc -> String showList :: [CWiidIRSrc] -> ShowS
Storable CWiidIRSrc Source # |

Instance details

Defined in System.CWiid

Methods

sizeOf :: CWiidIRSrc -> Int

alignment :: CWiidIRSrc -> Int

peekElemOff :: Ptr CWiidIRSrc -> Int -> IO CWiidIRSrc

pokeElemOff :: Ptr CWiidIRSrc -> Int -> CWiidIRSrc -> IO ()

peekByteOff :: Ptr b -> Int -> IO CWiidIRSrc

pokeByteOff :: Ptr b -> Int -> CWiidIRSrc -> IO ()

peek :: Ptr CWiidIRSrc -> IO CWiidIRSrc

poke :: Ptr CWiidIRSrc -> CWiidIRSrc -> IO ()

cwiidGetIR :: CWiidWiimote -> IO [CWiidIRSrc] Source #