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

Monitor

Valeri edited this page Aug 28, 2019 · 3 revisions

Monitor

Monitor object allow you to enumerate WiiRemotes connected to the system. It basically maps xwii_monitor functional adapted for Lua usage.

wii.monitor([poll, direct])

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 to false.
  • direct -- "kernel uevents should be used instead of udevd". No idea what it does, I just mapped it. Defaults to false.

Return:

  • New monitor object or nothing on error.

monitor:set_blocking([blocking])

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 to false.

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.

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 polling is disabled, always return nil.

Refer to original docs for more details.

monitor:iter()

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.

Clone this wiki locally