-
Notifications
You must be signed in to change notification settings - Fork 0
Monitor
Monitor object allow you to enumerate WiiRemotes connected to the system. It basically maps xwii_monitor
functional adapted for Lua usage.
- C function:
xwii_monitor_new
Create new monitor object. Arguments are mapped 1-to-1 to C function with false
assumed by default. Object don't have to be closed manually: it is finalized either by garbage collector or using <toclose>
(in Lua 5.4+).
Arguments:
-
poll
-- should enumeration of newly connected devices be supported. Defaults tofalse
. -
direct
-- "kernel uevents should be used instead of udevd". No idea what it does, I just mapped it. Defaults tofalse
.
Return:
- New monitor object or nothing on error.
- C function:
xwii_monitor_get_fd
Sets blocking mode for monitor. Return two values.
For polling mode usage take a look at monitor.lua
example, where it's used together with lgi library to trigger callback when WiiRemote is connected.
Arguments:
-
blocking
-- should blocking be enabled on this monitor. Defaults tofalse
.
Return:
- Was operation successful.
false
only if was called on monitor with polling disabled; - File descriptor for polling (actual return value of C function). Can be used if you have some library which support polling from them. Read original docs for more information. Always
-1
if first value is false.
Note: unlike interface descriptor, this one was noticed to fire false alarms. If you're using file descriptor for polling, DO NOT open it in blocking mode or you'll likely deadlock yourself.
- C function:
xwii_monitor_poll
Maps C function directly. Basically, works this way:
- Returns path string for each connected WiiRemote.
- Returns
nil
once. - If polling is enabled:
-
- If blocking mode is enabled, locks until new WiiRemote is connected (if none were since last poll) and always return path.
-
- If blocking mode is disabled, either return newly connected device or
nil
if none were.
- If blocking mode is disabled, either return newly connected device or
- If polling is disabled, always return
nil
.
Refer to original docs for more details.
- C function:
xwii_monitor_poll
Wrapper around monitor:poll()
for easier usage. It's basically the same as monitor.poll, monitor
.
It's useful with for
loop:
local wii = require 'xwiimote'
local mon = wii.monitor()
print('Connected wiimotes:')
for path in mon:iter() do
print(path)
end
This example will print all connected WiiRemotes and then exit.