Documentation
¶
Overview ¶
Package xwiimote has bindings for libxwiimote, a library to read and control inputs on a Nintendo WiiMote and accessories.
Index ¶
- Variables
- func IterDevices() (iter.Seq2[*Device, error], error)
- type Device
- func (dev *Device) Available(iface Interface) bool
- func (dev *Device) CloseInterfaces(ifaces ...Interface) error
- func (dev *Device) FD() int
- func (dev *Device) GetBattery() (uint, error)
- func (dev *Device) GetDevType() (string, error)
- func (dev *Device) GetExtension() (string, error)
- func (dev *Device) GetLED() (result Led, _ error)
- func (dev *Device) GetMPNormalization() (x, y, z, factor int32)
- func (dev *Device) GetSyspath() string
- func (p *Device) Handle(yield func(T))
- func (dev *Device) OpenInterfaces(wr bool, ifaces ...Interface) error
- func (dev *Device) Poll() (Event, bool, error)
- func (dev *Device) SetLED(leds Led) error
- func (dev *Device) SetMPNormalization(x, y, z, factor int32)
- func (p *Device) Stream(ch chan<- T)
- func (dev *Device) String() string
- func (p *Device) Wait(timeout time.Duration) (T, error)
- func (dev *Device) Watch(hotplug bool) error
- type Event
- type EventAccel
- type EventBalanceBoard
- type EventClassicControllerKey
- type EventClassicControllerMove
- type EventDrumsKey
- type EventDrumsMove
- type EventGone
- type EventGuitarKey
- type EventGuitarMove
- type EventIR
- type EventKey
- type EventMotionPlus
- type EventNunchukKey
- type EventNunchukMove
- type EventProControllerKey
- type EventProControllerMove
- type EventWatch
- type IRSlot
- type Interface
- type InterfaceAccel
- type InterfaceClassicController
- type InterfaceCore
- type InterfaceDrums
- type InterfaceGuitar
- type InterfaceIR
- type InterfaceMotionPlus
- type InterfaceNunchuck
- type InterfaceProController
- type Key
- type KeyState
- type Led
- type Monitor
- type MonitorType
- type Vec2
- type Vec3
Constants ¶
This section is empty.
Variables ¶
var ErrPollAgain = errors.New("invalid polling, should retrying")
ErrPollAgain is returned by a PollDriver to mark the poll invalid.
Functions ¶
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device describes the communication with a single device. That is, you create one for each device you use. All sub-interfaces are opened on this object.
func NewDevice ¶
NewDevice creates a new device object. No interfaces on the device are opened by default.
syspath must be a valid path to a wiimote device, either retrieved via a Monitor, an Enumerator or via udev directly. It must point to the hid device, which is normally /sys/bus/hid/devices/[dev].
The object and underlying structure is freed automatically by default.
func (*Device) Available ¶
IsAvailable returns a bitmask of available devices. These devices can be opened and are guaranteed to be present on the hardware at this time. If you watch your device for hotplug events you will get notified whenever this bitmask changes. See the WatchEvent event for more information.
func (*Device) CloseInterfaces ¶ added in v0.4.0
CloseInterfaces closes one or more interfaces on this device.
func (*Device) FD ¶ added in v0.2.0
FD returns the file-descriptor to notify readiness. If multiple file-descriptors are used internally, they are multi-plexed through an epoll descriptor. Therefore, this always returns the same single file-descriptor. You need to watch this for readable-events (POLLIN/EPOLLIN) and call Poll() whenever it is readable.
func (*Device) GetBattery ¶
GetBattery reads the current battery capacity. The capacity is represented as percentage, thus the return value is an integer between 0 and 100.
Batteries are a static interface that does not have to be opened first.
func (*Device) GetDevType ¶
GetDevType returns the device type. If the device type cannot be determined, it returns "unknown" and the corresponding error.
This is a static interface that does not have to be opened first.
func (*Device) GetExtension ¶
GetExtension returns the extension type. If no extension is connected or the extension cannot be determined, it returns a string "none" and the corresponding error.
This is a static interface that does not have to be opened first.
func (*Device) GetLED ¶
GetLED reads the LED state for the given LED.
LEDs are a static interface that does not have to be opened first.
func (*Device) GetMPNormalization ¶
GetMPNormalization reads the Motion-Plus normalization and calibration values. Please see SetMPNormalization() how this is handled.
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 SetMPNormalization() and you can feed them back in later.
func (*Device) GetSyspath ¶
GetSyspath returns the sysfs path of the underlying device. It is not neccesarily the same as the one during NewDevice. However, it is guaranteed to point at the same device (symlinks may be resolved).
func (*Device) Handle ¶ added in v0.4.0
func (p *Device) Handle(yield func(T))
Handle continuously polls and calls `yield` with new events. It blocks forever and should be used in a new goroutine.
func (*Device) OpenInterfaces ¶ added in v0.4.0
OpenInterfaces all the requested interfaces. If InterfaceWritable is also set, the interfaces are opened with write-access. Note that interfaces that are already opened are ignored and not touched. If any interface fails to open, this function still tries to open the other requested interfaces and then returns the error afterwards. Hence, if this function fails, you should use Opened() to get a bitmask of opened interfaces and see which failed (if that is of interest).
Note that interfaces may be closed automatically during runtime if the kernel removes the interface or on error conditions. You always get an EventWatch event which you should react on. This is returned regardless whether Watch() was enabled or not.
func (*Device) Poll ¶ added in v0.2.0
Poll for incoming events.
You should call this whenever the file-descriptor returned by FD is reported as being readable. This function will perform all non-blocking outstanding tasks and then return.
This function always performs any background tasks and outgoing event-writes if they don't block. It returns an error if they fail. This function then tries to read a single incoming event. If no event is available, it returns no error but sets continue-flag low and you should watch the file-desciptor again until it is readable. Otherwise, you should call this function in a row as long as it returns 0.
It returns the event or nil if an error occured, the continue-flag whether a new event can be polled right away and optionally and error, if the error is ErrRetry, consider polling again for new events.
func (*Device) SetLED ¶
SetLED writes the LED state for the given LED.
LEDs are a static interface that does not have to be opened first.
func (*Device) SetMPNormalization ¶
SetMPNormalization sets Motion-Plus normalization and calibration values. The Motion-Plus sensor is very sensitive and may return really crappy values. This interfaces allows to apply 3 absolute offsets x, y and z which are subtracted from any MP data before it is returned to the application. That is, if you set these values to 0, this has no effect (which is also the initial state).
The calibration factor is 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.
func (*Device) Stream ¶ added in v0.3.1
func (p *Device) Stream(ch chan<- T)
Stream continuously polls and writes events into ch. It is a wrapper for Handle. It blocks forever and should be used in a new goroutine.
p.Handle(func(ev T) { ch <- ev })
func (*Device) Wait ¶ added in v0.3.1
Wait waits for an event up to the specified timeout. A negative timeout is considered forever. It handles ErrRetry internally and returns the first valid event or error.
func (*Device) Watch ¶
Watch sets whether hotplug events should be reported or not. By default, no hotplug events are reported so this is off.
Note that this requires a separate udev-monitor for each device. Therefore, if your application uses its own udev-monitor, you should instead integrate the hotplug-detection into your udev-monitor.
type Event ¶
Event interface describes an event fired by Device.Dispatch(), consider using a type-switch to retrieve the specific event type and data
type EventAccel ¶
type EventAccel struct {
Accel Vec3
// contains filtered or unexported fields
}
EventAccel provides accelerometer data. Note that the accelerometer reports acceleration data, not speed data!
type EventBalanceBoard ¶
type EventBalanceBoard struct {
Weights [4]int32
// contains filtered or unexported fields
}
EventBalanceBoard provides balance-board weight data. Four sensors report weight-data for each of the four edges of the board.
type EventClassicControllerKey ¶
type EventClassicControllerKey struct {
EventKey
}
EventClassicControllerKey provides Classic Controller key events. Button events of the classic controller are reported via this interface and not via the core-interface (which only reports core-buttons). Valid buttons include: LEFT, RIGHT, UP, DOWN, PLUS, MINUS, HOME, X, Y, A, B, TR, TL, ZR, ZL.
type EventClassicControllerMove ¶
type EventClassicControllerMove struct {
StickLeft Vec2
StickRight Vec2
ShoulderLeft int32
ShoulderRight int32
// contains filtered or unexported fields
}
EventClassicControllerMove provides Classic Controller movement events. Movement of analog sticks are reported via this event. The payload is a struct xwii_event_abs and the first two array elements contain the absolute x and y position of both analog sticks. The x value of the third array element contains the absolute position of the TL trigger. The y value contains the absolute position for the TR trigger. Note that many classic controllers do not have analog TL/TR triggers, in which case these read 0 or MAX (63). The digital TL/TR buttons are always reported correctly.
type EventDrumsKey ¶
type EventDrumsKey struct {
EventKey
}
EventDrumsKey provides Drums key events. Button events for drums controllers. Valid buttons are PLUS and MINUS for the +/- buttons on the center-bar.
type EventDrumsMove ¶
type EventDrumsMove struct {
Pad Vec2
CymbalLeft int32
CymbalRight int32
TomLeft int32
TomRight int32
TomFarRight int32
Bass int32
HiHat int32
// contains filtered or unexported fields
}
EventDrumsMove provides Drums movement event Movement and pressure events for drums controllers.
type EventGone ¶
type EventGone struct {
// contains filtered or unexported fields
}
EventGone provides Removal Event. This event is sent whenever the device was removed. No payload is provided. Non-hotplug aware applications may discard this event. This is only returned if you explicitly watched for hotplug events.
See Device.Watch().
type EventGuitarKey ¶
type EventGuitarKey struct {
EventKey
}
EventGuitarKey provides Guitar key events Button events for guitar controllers. Valid buttons are HOME and PLUS for the StarPower/Home button and the + button. Furthermore, you get FRET_FAR_UP, FRET_UP, FRET_MID, FRET_LOW, FRET_FAR_LOW for fret activity and STRUM_BAR_UP and STRUM_BAR_LOW for the strum bar.
type EventGuitarMove ¶
type EventGuitarMove struct {
Stick Vec2
WhammyBar int32
FretBar int32
// contains filtered or unexported fields
}
EventGuitarMove provides Guitar movement events. Movement information for guitar controllers.
type EventIR ¶
type EventIR struct {
Slots [4]IRSlot
// contains filtered or unexported fields
}
EventIR provides IR-camera events. The camera can track up two four IR sources. As long as a single source is tracked, it stays at it's pre-allocated slot.
Use IRSlot.Valid() to see whether a specific slot is currently valid or whether it currently doesn't track any IR source.
type EventKey ¶
EventKey is fired whenever a key is pressed or released. Valid key-events include all the events reported by the core-interface, which is normally only LEFT, RIGHT, UP, DOWN, A, B, PLUS, MINUS, HOME, ONE, TWO.
type EventMotionPlus ¶
type EventMotionPlus struct {
Speed Vec3
// contains filtered or unexported fields
}
EventMotionPlus provides gyroscope events. These describe rotational speed, not acceleration, of the motion-plus extension.
type EventNunchukKey ¶
type EventNunchukKey struct {
EventKey
}
EventNunchukKey provides Nunchuk key events. Button events of the nunchuk controller are reported via this interface and not via the core-interface (which only reports core-buttons). Valid buttons include: C, Z
type EventNunchukMove ¶
EventNunchukMove provides Nunchuk movement events. Movement events of the nunchuk controller are reported via this interface. Payload is of type struct xwii_event_abs. The first array element contains the x/y positions of the analog stick. The second array element contains the accelerometer information.
type EventProControllerKey ¶
type EventProControllerKey struct {
EventKey
}
EventProControllerKey provides button events of the pro-controller and are reported via this interface and not via the core-interface (which only reports core-buttons). Valid buttons include: LEFT, RIGHT, UP, DOWN, PLUS, MINUS, HOME, X, Y, A, B, TR, TL, ZR, ZL, THUMBL, THUMBR. Payload type is struct xwii_event_key.
type EventProControllerMove ¶
type EventProControllerMove struct {
Sticks [2]Vec2
// contains filtered or unexported fields
}
EventProControllerMove provides movement of analog sticks on the pro-controller and is reported via this event.
type EventWatch ¶
type EventWatch struct {
// contains filtered or unexported fields
}
EventWatch is sent whenever an extension was hotplugged (plugged or unplugged), a device-detection finished or some other static data changed which cannot be monitored separately. An application should check what changed by examining the device is testing whether all required interfaces are still available. Non-hotplug aware devices may discard this event.
This is only returned if you explicitly watched for hotplug events. See Device.Watch().
This event is also returned if an interface is closed because the kernel closed our file-descriptor (for whatever reason). This is returned regardless whether you watch for hotplug events or not.
type Interface ¶
type Interface interface {
// Name of this device,
Name() string
// Node is an absolute path which points to the sys-directory. When opened, a node is bound to this interface.
Node() string
// Device is the parent of this interface. When opened, a device is bound to this interface.
Device() *Device
// Opened returns a bitmask of opened interfaces. Interfaces may be closed due to
// error-conditions at any time. However, interfaces are never opened
// automatically.
//
// You will get notified whenever this bitmask changes, except on explicit
// calls to Open() and Close(). See the EventWatch event for more information.
Opened() bool
// contains filtered or unexported methods
}
func GetInterface ¶ added in v0.4.0
type InterfaceAccel ¶
type InterfaceAccel struct {
// contains filtered or unexported fields
}
func (InterfaceAccel) Name ¶ added in v0.4.0
func (InterfaceAccel) Name() string
func (*InterfaceAccel) Node ¶ added in v0.4.0
func (iface *InterfaceAccel) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceAccel) Opened ¶ added in v0.4.0
func (iface *InterfaceAccel) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceClassicController ¶
type InterfaceClassicController struct {
// contains filtered or unexported fields
}
func (*InterfaceClassicController) Device ¶ added in v0.4.0
func (iface *InterfaceClassicController) Device() *Device
func (InterfaceClassicController) Name ¶ added in v0.4.0
func (InterfaceClassicController) Name() string
func (*InterfaceClassicController) Node ¶ added in v0.4.0
func (iface *InterfaceClassicController) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceClassicController) Opened ¶ added in v0.4.0
func (iface *InterfaceClassicController) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceCore ¶
type InterfaceCore struct {
// contains filtered or unexported fields
}
func (InterfaceCore) Name ¶ added in v0.4.0
func (InterfaceCore) Name() string
type InterfaceDrums ¶
type InterfaceDrums struct {
// contains filtered or unexported fields
}
func (InterfaceDrums) Name ¶ added in v0.4.0
func (InterfaceDrums) Name() string
func (*InterfaceDrums) Node ¶ added in v0.4.0
func (iface *InterfaceDrums) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceDrums) Opened ¶ added in v0.4.0
func (iface *InterfaceDrums) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceGuitar ¶
type InterfaceGuitar struct {
// contains filtered or unexported fields
}
func (InterfaceGuitar) Name ¶ added in v0.4.0
func (InterfaceGuitar) Name() string
func (*InterfaceGuitar) Node ¶ added in v0.4.0
func (iface *InterfaceGuitar) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceGuitar) Opened ¶ added in v0.4.0
func (iface *InterfaceGuitar) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceIR ¶
type InterfaceIR struct {
// contains filtered or unexported fields
}
func (InterfaceIR) Name ¶ added in v0.4.0
func (InterfaceIR) Name() string
func (*InterfaceIR) Node ¶ added in v0.4.0
func (iface *InterfaceIR) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceIR) Opened ¶ added in v0.4.0
func (iface *InterfaceIR) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceMotionPlus ¶
type InterfaceMotionPlus struct {
// contains filtered or unexported fields
}
func (*InterfaceMotionPlus) Device ¶ added in v0.4.0
func (iface *InterfaceMotionPlus) Device() *Device
func (InterfaceMotionPlus) Name ¶ added in v0.4.0
func (InterfaceMotionPlus) Name() string
func (*InterfaceMotionPlus) Node ¶ added in v0.4.0
func (iface *InterfaceMotionPlus) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceMotionPlus) Opened ¶ added in v0.4.0
func (iface *InterfaceMotionPlus) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceNunchuck ¶ added in v0.4.0
type InterfaceNunchuck struct {
// contains filtered or unexported fields
}
func (InterfaceNunchuck) Name ¶ added in v0.4.0
func (InterfaceNunchuck) Name() string
func (*InterfaceNunchuck) Node ¶ added in v0.4.0
func (iface *InterfaceNunchuck) Node() string
Node is an absolute path which points to the sys-directory. When opened, a node is bound to this device.
func (*InterfaceNunchuck) Opened ¶ added in v0.4.0
func (iface *InterfaceNunchuck) Opened() bool
Opened returns a bitmask of opened interfaces. Interfaces may be closed due to error-conditions at any time. However, interfaces are never opened automatically.
You will get notified whenever this bitmask changes, except on explicit calls to Open() and Close(). See the EventWatch event for more information.
type InterfaceProController ¶
type InterfaceProController struct {
// contains filtered or unexported fields
}
func (InterfaceProController) Name ¶ added in v0.4.0
func (InterfaceProController) Name() string
type Key ¶
type Key uint
Key Event Identifiers
For each key found on a supported device, a separate key identifier is defined. Note that a device may have a specific key (for instance: HOME) on the main device and on an extension device. An application can detect which key was pressed examining the event-type field. Some devices report common keys as both, extension and core events. In this case the kernel is required to filter these and you should report it as a bug. A single physical key-press should never be reported twice, even on two different interfaces.
const ( KeyLeft Key = iota KeyRight KeyUp KeyDown KeyA KeyB KeyPlus KeyMinus KeyHome KeyOne KeyTwo KeyX KeyY KeyTL KeyTR KeyZL KeyZR // Left thumb button // // This is reported if the left analog stick is pressed. Not all analog // sticks support this. The Wii-U Pro Controller is one of few devices // that report this event. KeyThumbL // Right thumb button // // This is reported if the right analog stick is pressed. Not all analog // sticks support this. The Wii-U Pro Controller is one of few devices // that report this event. KeyThumbR // Extra C button // // This button is not part of the standard action pad but reported by // extension controllers like the Nunchuk. It is supposed to extend the // standard A and B buttons. KeyC // Extra Z button // // This button is not part of the standard action pad but reported by // extension controllers like the Nunchuk. It is supposed to extend the // standard X and Y buttons. KeyZ // Guitar Strum-bar-up event // // Emitted by guitars if the strum-bar is moved up. KeyStrumBarUp // Guitar Strum-bar-down event // // Emitted by guitars if the strum-bar is moved down. KeyStrumBarDown // Guitar Fret-Far-Up event // // Emitted by guitars if the upper-most fret-bar is pressed. KeyFretFarUp // Guitar Fret-Up event // // Emitted by guitars if the second-upper fret-bar is pressed. KeyFretUp // Guitar Fret-Mid event // // Emitted by guitars if the mid fret-bar is pressed. KeyFretMid // Guitar Fret-Low event // // Emitted by guitars if the second-lowest fret-bar is pressed. KeyFretLow // Guitar Fret-Far-Low event // // Emitted by guitars if the lower-most fret-bar is pressed. KeyFretFarLow )
type Led ¶
type Led uint
Led described a Led of an device. The leds are counted left-to-right and can be OR'ed together.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor describes a monitor for xwiimote-devices. This includes currently available but also hot-plugged devices.
Monitors are not thread-safe.
func NewMonitor ¶
func NewMonitor(typ MonitorType) (*Monitor, error)
NewMonitor creates a new monitor.
A monitor always provides all devices that are available on a system and hot-plugged devices.
The object and underlying structure is freed automatically by default.
func (*Monitor) FD ¶ added in v0.2.0
FD returns the file-descriptor to notify readiness. The FD is non-blocking. Only one file-descriptor exists, that is, this function always returns the same descriptor.
func (*Monitor) Handle ¶ added in v0.4.0
func (p *Monitor) Handle(yield func(T))
Handle continuously polls and calls `yield` with new events. It blocks forever and should be used in a new goroutine.
func (*Monitor) Poll ¶
Poll returns a single device-name on each call. A device-name is actually an absolute sysfs path to the device's root-node. This is normally a path to /sys/bus/hid/devices/[dev]/. You can use this path to create a new struct xwii_iface object.
After a monitor was created, this function returns all currently available devices. After all devices have been returned. After that, this function polls the monitor for hotplug events and returns hotplugged devices, if the monitor was opened to watch the system for hotplug events.
Use FD() to get notified when a new event is available.
type MonitorType ¶ added in v0.3.1
type MonitorType uint
MonitorType describes how a monitor or enumerator should look for devices.
const ( // Monitor uses kernel uevents MonitorKernel MonitorType = 1 // Monitor uses udevd MonitorUdev MonitorType = 0 )
func (MonitorType) Name ¶ added in v0.4.0
func (t MonitorType) Name() string
func (MonitorType) String ¶ added in v0.3.1
func (i MonitorType) String() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
test
command
|
|
|
xwiimap
command
|
|
|
xwiipointer
command
|
|
|
pkg
|
|
|
irpointer
Package irpointer contains an algorithm to use your wiimote IR-sensors as pointer on a screen
|
Package irpointer contains an algorithm to use your wiimote IR-sensors as pointer on a screen |
|
udev
Package udev provides a cgo wrapper around the libudev C library
|
Package udev provides a cgo wrapper around the libudev C library |
|
udev/sequences
Package sequences contains some utility functions releated to iter.Seq and iter.Seq2
|
Package sequences contains some utility functions releated to iter.Seq and iter.Seq2 |
|
vinput
Package vinput can create a Virtual Input using uinput
|
Package vinput can create a Virtual Input using uinput |