-
Notifications
You must be signed in to change notification settings - Fork 0
Interface
Interface object represent WiiMote device connected to your system. It's Lua version of xwii_iface
.
- C function:
xwii_iface_new
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. Usewii.monitor
to obtain one.
Return:
- New monitor object.
Error
- If object can't be created for some reason.
- C function:
xwii_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.
- C function:
xwii_iface_watch
Maps C function directly. Enable or disable watch
events. Note: they are disabled by default.
Arguments:
-
watch
-- shouldwatch
events be enabled or disabled. Defaults tofalse.
Return:
- Standard
assert
-compatible notation.
- C function:
xwii_iface_open
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.
- C function:
xwii_iface_close
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).
- C function:
xwii_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).
- C function:
xwii_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).
- C function:
xwii_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.
- C function:
xwii_iface_dispatch
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.
- C function:
xwii_iface_rumble
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 tofalse
.
Return:
- Standard
assert
-compatible notation.
- C function:
xwii_iface_get_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 befalse
, don't actually wrap this intoassert
until you sure you want to!
- C function:
xwii_iface_set_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.
- C function:
xwii_iface_get_battery
Get battery state.
Return:
- Battery state (0%-100%) in standard
assert
-compatible notation.
- C function:
xwii_iface_get_devtype
Get device type.
Return:
- Device type string in standard
assert
-compatible notation.
- C function:
xwii_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.
- C function:
xwii_iface_set_mp_normalization
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.
- C function:
xwii_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.