Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Interface

Valeri edited this page Aug 28, 2019 · 2 revisions

Interface

Interface object represent WiiMote device connected to your system. It's Lua version of xwii_iface.

wii.iface(syspath)

Create new interface object. It don't have to be closed manually: object is finalized either by garbage collector or using <toclose> (in Lua 5.4+).

Arguments:

  • syspath -- path to device you're trying to open. Use wii.monitor to obtain one.

Return:

  • New monitor object.

Error

  • If object can't be created for some reason.

iface:get_fd()

Get file descriptor for polling. Never errors and result is always valid (until you pass bad object of course).

For polling mode usage take a look at simple_read.lua example, where it's used together with lgi library to trigger callback when WiiRemote button is pressed.

Return:

  • File descriptor for polling (actual return value of C function). Can be used if you have some library which support polling from them (like lgi or LuaPosix). Read original docs for more information.

iface:watch([watch])

Maps C function directly. Enable or disable watch events. Note: they are disabled by default.

Arguments:

  • watch -- should watch events be enabled or disabled. Defaults to false.

Return:

  • Standard assert-compatible notation.

iface:open(bitmask)

Open (start listening listening to) interfaces specified by bitmask. On error still try to open all requested interfaces.

Arguments:

  • bitmask -- bitmask for requested interfaces (check out constants for (possibly ORed with |) values).

Return:

  • Standard assert-compatible notation.

iface:close(bitmask)

Close (stop listening listening to) interfaces specified by bitmask. This never fails (while this world is sane), so no value is returned.

  • bitmask -- bitmask for interfaces to close (check out constants for (possibly ORed with |) values).

iface:opened()

Return currently opened intefaces in form of bitmask. Never fails and valid value is always returned.

Note: returned value may change between calls without any action from your side if extension was disconnected.

Return:

  • bitmask for currently opened interfaces (AND with constants to check if one is).

iface:available()

Return currently available intefaces in form of bitmask. Never fails and valid value is always returned.

Note: returned value may change between calls without any action from your side if extension was connected or disconnected.

Return:

  • bitmask for currently available interfaces (AND with constants to check if one is).

iface:poll()/iface:dispatch()

Read event if one is ready. Both names correspond to the same function and there's absolutely no difference between them (unlike C ones where poll is deprecated for good reasons).

Return:

  • event if one was successfully read and parsed.
  • true if event was received but failed to parse.
  • nil if no events are ready at the moment (-EAGAIN was returned).
  • nil and string error message on error

You really want to check out next function as it is much more applicable for general usage.

iface:iter()

Wrapper around iface:poll() for easier usage. It's basically the same as iface.poll, iface.
It's useful with for loop. Check out simple_read.lua for example usage.

iface:rumble([on])

Turn rumble on or off. To make this command work, your application should open core interface in writable mode first.

When your application exits, WiiRemote will automatically stop rumbling.

Arguments:

  • on -- target state of rumbling. Defaults to false.

Return:

  • Standard assert-compatible notation.

iface:get_led(led)

Get status of LED.

Arguments:

  • led -- number of LED to check (integer 1-4).

Return:

  • State as boolean in standard assert-compatible notation. Note: as result may be false, don't actually wrap this into assert until you sure you want to!

iface:set_led(led)

Turn led LED on or off. You probably need root/sudo rights to use this.

Arguments:

  • led -- number of LED to turn on/off (integer 1-4).

Return:

  • Standard assert-compatible notation.

iface:get_battery()

Get battery state.

Return:

  • Battery state (0%-100%) in standard assert-compatible notation.

iface:get_devtype()

Get device type.

Return:

  • Device type string in standard assert-compatible notation.

iface:get_extension()

Get extension type.

Note: returned value may change between calls without any action from your side if extension was connected or disconnected.

Return:

  • Extension type string in standard assert-compatible notation.

iface:set_mp_normalization(x, y, z, factor)

Set MP normalization and calibration. Read original docs for details on why.

Arguments:

  • x, y, z -- static values to add to or subtract from MotionPlus data.
  • factor -- "used to perform runtime calibration. If it is 0 (the initial state), no runtime calibration is performed. Otherwise, the factor is used to re-calibrate the zero-point of MP data depending on MP input. This is an angoing calibration which modifies the internal state of the x, y and z values." -- that's what original docs say. No idea how to use, sorry.

Return:

  • Standard assert-compatible notation.

iface:get_mp_normalization()

Get MP normalization and calibration. Read original docs for details on why. This call never fail.

Return:

  • x, y, z, factor -- see above.

Note that if the calibration factor is not 0, the normalization values may change depending on incoming MP data. Therefore, the data read via this function may differ from the values that you wrote to previously. However, apart from applied calibration, these value are the same as were set previously via xwii_iface_set_mp_normalization() and you can feed them back in later.