xwiimote

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: Zlib Imports: 17 Imported by: 0

README

go-xwiimote - Go bindings for xwiimote

This repository contains bindings for libxwiimote and some helpers. Detailed documentation is located here.

xwiimote            -- bindings for libxwiimote
├── pkg
│   ├── irpointer   -- algorithm to convert IR events to a pointer on a screen
│   └── vinput      -- library to create a virtual input device using Linux' uinput
└── cmd
    ├── xwiimap     -- utility to map wiimote buttons to physical keys.
    └── xwiipointer -- utility to use wiimote as mouse using IR-tracking.

libxwiimote is a library which cooperates with the xwiimote-kernel driver which is included since Linux 3.1 and supersedes cwiid which is a driverless interface.

Prerequisite

  • Linux 3.1 or newer (3.11 or newer recommended)
  • bluez 4.101 or newer (bluez-5.0 or newer recommended)
  • Go
  • libxwiimote

Supported devices are:

  • Nintendo Wii Remote (Nintendo RVL-CNT-01)
  • Nintendo Wii Remote Plus (Nintendo RVL-CNT-01-TR)
  • Nintendo Wii Nunchuk Extension
  • Nintendo Wii Classic Controller Extension
  • Nintendo Wii Classic Controller Pro Extension
  • Nintendo Wii Balance Board (Nintendo RVL-WBC-01)
  • Nintendo Wii U Pro Controller (Nintendo RVL-CNT-01-UC)
  • Nintendo Wii Guitar Extensions
  • Nintendo Wii Drums Extensions

Usage

For example usage you can check the cmd-directory.

Find new devices

First you have to choose whether you want to monitor for new devices or only use currently available devices. If you want to monitor for new devices you should use Montor:

monitor := xwiimote.NewMonitor(xwiimote.MonitorUdev)
defer monitor.Free()

for {
    // Wait infinitely for a new device.
    path, err := monitor.Wait(-1)
    if err != nil || path == "" {
        log.Printf("error while polling: %v\n", err)
        continue
    }
    -> device at path
}

If you only want to use currently available devices, you can use the IterDevices-function:

for path := range xwiimote.IterDevices(xwiimote.MonitorUdev) {
    -> device at path
}

The path returned points at the sysfs location.

Create a device

This is a sparse example how to create a new device. Refer to the documentation for more information.

// create a new device which is located at path
dev, err := xwiimote.NewDevice(path)
if err != nil {
    log.Fatalf("error: unable to get device: %s", err)
}
// freeing is not mandatory and is done automatically by GC.
defer dev.Free()

// open interfaces, we're only interested in core functionality.
if err := dev.Open(xwiimote.InterfaceCore); err != nil {
    log.Fatalf("error: unable to open device: %s", err)
}

for {
    // Wait infinitely for a new event.
    ev, err := dev.Wait(-1)
    if err != nil {
        log.Printf("unable to poll event: %v\n", err)
    }
    switch ev := ev.(type) {
    case *xwiimote.EventKey:
        log.Printf("key event: %v\n", ev.Code)
    }
}
Use a IR pointer

The IRPointer has a state which must be updated when appropriate, after updating the health and position can be read.

pointer := irpointer.NewIRPointer(nil)
var (
    lastIR *xwiimote.EventIR
    lastAccel *xwiimote.EventAccel
)
for {
    ev, err := dev.Wait(-1)
    if err != nil {
        log.Printf("unable to poll event: %v\n", err)
    }
    switch ev := ev.(type) {
    case *xwiimote.EventIR:
        lastIR = ev
    case *xwiimote.EventAccel:
        lastAccel = ev
    if lastIR != nil && lastAccel != nil {
        pointer.Update(lastIR.Slots, lastAccel.Accel)
        /* optionally only update when there is a new IR AND Accel event
        lastIR = nil
        lastAccel = nil
        */
    }
    // if the pointer has sufficient health and a valid position -> do somthing
    if pointer.Health >= irpointer.IRSingle && pointer.Position != nil {
        x, y := pointer.Position.X, pointer.Position.Y
        if x >= -340 && x < 340 && y >= -92 && y < 290 {
            fmt.Printf("[%v] pointer at (%.2f %.2f) at %.2fm distance\n", pointer.Health, pointer.Position.X, pointer.Position.Y, pointer.Distance)
        }
    }
}

Contributing

Feel free to add functionality and make a pull request! Please keep the structure clean:

/       -> only releated to libxwiimote itself and bindings
/pkg    -> utility packages not related to libxwiimote
Tooling

This project makes use of stringer to generate .String() methods for enums.

  • Install stringer:
    $ go install golang.org/x/tools/cmd/stringer
    
  • Run generators:
    $ go generate ./...
    
Formatting

Before submitting any changes, please format the project using gofmt.

Licensing

The irpointer package is licensed under 2-clause-BSD License (as noted in the source), remaining code is licensed under Zlib License.

Documentation

Overview

Package xwiimote has bindings for libxwiimote, a library to read and control inputs on a Nintendo WiiMote and accessories.

Index

Constants

This section is empty.

Variables

View Source
var ErrPollAgain = errors.New("invalid polling, should retrying")

ErrPollAgain is returned by a PollDriver to mark the poll invalid.

Functions

func IterDevices added in v0.3.1

func IterDevices() (iter.Seq2[*Device, error], error)

IterDevices returns all currently available devices. It returns an error if the initialization failed. Each iteration yields a device and error if the device-creation failed.

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

func NewDevice(syspath string) (*Device, error)

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

func (dev *Device) Available(iface Interface) bool

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

func (dev *Device) CloseInterfaces(ifaces ...Interface) error

CloseInterfaces closes one or more interfaces on this device.

func (*Device) FD added in v0.2.0

func (dev *Device) FD() int

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

func (dev *Device) GetBattery() (uint, error)

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

func (dev *Device) GetDevType() (string, error)

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

func (dev *Device) GetExtension() (string, error)

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

func (dev *Device) GetLED() (result Led, _ error)

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

func (dev *Device) GetMPNormalization() (x, y, z, factor int32)

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

func (dev *Device) GetSyspath() string

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

func (dev *Device) OpenInterfaces(wr bool, ifaces ...Interface) error

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

func (dev *Device) Poll() (Event, bool, error)

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

func (dev *Device) SetLED(leds Led) error

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

func (dev *Device) SetMPNormalization(x, y, z, factor int32)

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) String added in v0.3.1

func (dev *Device) String() string

func (*Device) Wait added in v0.3.1

func (p *Device) Wait(timeout time.Duration) (T, error)

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

func (dev *Device) Watch(hotplug bool) error

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

type Event interface {
	Interface() Interface
	Timestamp() time.Time
}

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!

func (*EventAccel) Interface added in v0.4.0

func (evt *EventAccel) Interface() Interface

func (*EventAccel) Timestamp

func (evt *EventAccel) Timestamp() time.Time

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.

func (*EventBalanceBoard) Interface added in v0.4.0

func (evt *EventBalanceBoard) Interface() Interface

func (*EventBalanceBoard) Timestamp

func (evt *EventBalanceBoard) Timestamp() time.Time

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.

func (*EventClassicControllerKey) Interface added in v0.4.0

func (evt *EventClassicControllerKey) Interface() Interface

func (*EventClassicControllerKey) Timestamp

func (evt *EventClassicControllerKey) Timestamp() time.Time

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.

func (*EventClassicControllerMove) Interface added in v0.4.0

func (evt *EventClassicControllerMove) Interface() Interface

func (*EventClassicControllerMove) Timestamp

func (evt *EventClassicControllerMove) Timestamp() time.Time

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.

func (*EventDrumsKey) Interface added in v0.4.0

func (evt *EventDrumsKey) Interface() Interface

func (*EventDrumsKey) Timestamp

func (evt *EventDrumsKey) Timestamp() time.Time

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.

func (*EventDrumsMove) Interface added in v0.4.0

func (evt *EventDrumsMove) Interface() Interface

func (*EventDrumsMove) Timestamp

func (evt *EventDrumsMove) Timestamp() time.Time

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().

func (*EventGone) Interface added in v0.4.0

func (evt *EventGone) Interface() Interface

func (*EventGone) Timestamp

func (evt *EventGone) Timestamp() time.Time

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.

func (*EventGuitarKey) Interface added in v0.4.0

func (evt *EventGuitarKey) Interface() Interface

func (*EventGuitarKey) Timestamp

func (evt *EventGuitarKey) Timestamp() time.Time

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.

func (*EventGuitarMove) Interface added in v0.4.0

func (evt *EventGuitarMove) Interface() Interface

func (*EventGuitarMove) Timestamp

func (evt *EventGuitarMove) Timestamp() time.Time

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.

func (*EventIR) Interface added in v0.4.0

func (evt *EventIR) Interface() Interface

func (*EventIR) Timestamp

func (evt *EventIR) Timestamp() time.Time

type EventKey

type EventKey struct {
	Code  Key
	State KeyState
	// contains filtered or unexported fields
}

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.

func (*EventKey) Interface added in v0.4.0

func (evt *EventKey) Interface() Interface

func (*EventKey) Timestamp

func (evt *EventKey) Timestamp() time.Time

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.

func (*EventMotionPlus) Interface added in v0.4.0

func (evt *EventMotionPlus) Interface() Interface

func (*EventMotionPlus) Timestamp

func (evt *EventMotionPlus) Timestamp() time.Time

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

func (*EventNunchukKey) Interface added in v0.4.0

func (evt *EventNunchukKey) Interface() Interface

func (*EventNunchukKey) Timestamp

func (evt *EventNunchukKey) Timestamp() time.Time

type EventNunchukMove

type EventNunchukMove struct {
	Stick Vec2
	Accel Vec3
	// contains filtered or unexported fields
}

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.

func (*EventNunchukMove) Interface added in v0.4.0

func (evt *EventNunchukMove) Interface() Interface

func (*EventNunchukMove) Timestamp

func (evt *EventNunchukMove) Timestamp() time.Time

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.

func (*EventProControllerKey) Interface added in v0.4.0

func (evt *EventProControllerKey) Interface() Interface

func (*EventProControllerKey) Timestamp

func (evt *EventProControllerKey) Timestamp() time.Time

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.

func (*EventProControllerMove) Interface added in v0.4.0

func (evt *EventProControllerMove) Interface() Interface

func (*EventProControllerMove) Timestamp

func (evt *EventProControllerMove) Timestamp() time.Time

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.

func (*EventWatch) Interface added in v0.4.0

func (evt *EventWatch) Interface() Interface

func (*EventWatch) Timestamp

func (evt *EventWatch) Timestamp() time.Time

type IRSlot

type IRSlot struct {
	Vec2
}

IRSlot describes Infra-Red Tracking on a WiiMote

func (IRSlot) Valid

func (slot IRSlot) Valid() bool

Valid returns wether this slot holds a valid source. If not it has no track and is considered disabled.

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

func GetInterface(name string) Interface

type InterfaceAccel

type InterfaceAccel struct {
	// contains filtered or unexported fields
}

func (*InterfaceAccel) Device added in v0.4.0

func (iface *InterfaceAccel) Device() *Device

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) 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

func (*InterfaceCore) Rumble added in v0.4.0

func (dev *InterfaceCore) Rumble(state bool) error

Rumble sets the rumble motor.

This requires the core-interface to be opened in writable mode.

type InterfaceDrums

type InterfaceDrums struct {
	// contains filtered or unexported fields
}

func (*InterfaceDrums) Device added in v0.4.0

func (iface *InterfaceDrums) Device() *Device

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) Device added in v0.4.0

func (iface *InterfaceGuitar) Device() *Device

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) Device added in v0.4.0

func (iface *InterfaceIR) Device() *Device

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) Device added in v0.4.0

func (iface *InterfaceNunchuck) Device() *Device

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) Rumble added in v0.4.0

func (dev *InterfaceProController) Rumble(state bool) error

Rumble sets the rumble motor.

This requires the core-interface to be opened in writable mode.

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
)

func (Key) String added in v0.3.1

func (i Key) String() string

type KeyState

type KeyState uint
const (
	// The key is released, alternativly KeyUp
	StateReleased KeyState = iota
	// The key is pressed, alternativly KeyDown
	StatePressed
	// The key is hold down and repeats
	StateRepeated
)

func (KeyState) String added in v0.3.1

func (i KeyState) String() string

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.

const (
	Led1 Led = 1 << iota
	Led2
	Led3
	Led4
)

func (Led) String added in v0.3.1

func (i Led) String() string

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

func (mon *Monitor) FD() int

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

func (mon *Monitor) Poll() (*Device, bool, error)

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.

func (*Monitor) Stream added in v0.3.1

func (p *Monitor) 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 (*Monitor) Wait added in v0.3.1

func (p *Monitor) Wait(timeout time.Duration) (T, error)

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.

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

type Vec2 added in v0.2.0

type Vec2 struct{ X, Y int32 }

Vec2 represents a 2D point or vector to X and Y, may be interpreted different depending on the event .

type Vec3 added in v0.2.0

type Vec3 struct{ X, Y, Z int32 }

Vec3 represents a 3D point or vector to X, Y and Z, may be interpreted different depending on the event.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL