Documentation
¶
Overview ¶
Package joysticks, provides simplified event routing, through channels, from the Linux joystick driver File-like interface.
events can be listened for from any thread, dynamically re-mapped and simulated.
Highlevel Usage ¶
'Capture', one call to setup and start basic 'Event' channeling on the first available device.
Midlevel ¶
'Connect(index)' to a HID.
Use methods to add (or alter) 'Event' channels.
Start running by calling 'ParcelOutEvents()'.
(unlike highlevel, event index to channel mappings can be changed dynamically.)
Lowlevel ¶
'Connect' to a HID by index number.
handle all events directly appearing on the returned HID's OSEvents channel.
Interface ¶
'Event' interface, provides a time.Duration through a call to the Moment() method, returning whatever the underlying Linux driver provides as the events timestamp, as a time.Duration.
returned 'Event's need asserting to their underlying type ( '***Event' ) to access data other than moment.
Index ¶
- Variables
- func Capture(registrees ...Channel) []chan Event
- func DeviceExists(index uint8) bool
- func Duplicator(c chan Event) (chan Event, chan Event)
- func PositionFromVelocity(c chan Event) chan Event
- func Repeater(c1, c2 chan Event) chan Event
- type AngleEvent
- type AxisEvent
- type ButtonEvent
- type Channel
- type CoordsEvent
- type Event
- type HID
- func (d HID) ButtonClosed(index uint8) bool
- func (d HID) ButtonExists(index uint8) (ok bool)
- func (d HID) HatCoords(index uint8, coords []float32)
- func (d HID) HatExists(index uint8) (ok bool)
- func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8)
- func (d HID) OnButton(index uint8) chan Event
- func (d HID) OnCenter(index uint8) chan Event
- func (d HID) OnClose(index uint8) chan Event
- func (d HID) OnDouble(index uint8) chan Event
- func (d HID) OnEdge(index uint8) chan Event
- func (d HID) OnHat(index uint8) chan Event
- func (d HID) OnLong(index uint8) chan Event
- func (d HID) OnMove(index uint8) chan Event
- func (d HID) OnOpen(index uint8) chan Event
- func (d HID) OnPanX(index uint8) chan Event
- func (d HID) OnPanY(index uint8) chan Event
- func (d HID) OnRotate(index uint8) chan Event
- func (d HID) OnSpeedX(index uint8) chan Event
- func (d HID) OnSpeedY(index uint8) chan Event
- func (d HID) ParcelOutEvents()
- type HatEvent
- type RadiusEvent
Constants ¶
This section is empty.
Variables ¶
var DefaultRepeat = time.Second / 4
var DoublePressDelay = time.Second / 10
var LongPressDelay = time.Second / 2
var VelocityRepeat = time.Second / 10
Functions ¶
func Capture ¶
Capture is highlevel automation of the setup of event channels. Returned is a slice of chan's, matching each registree, which then receive events of the type and index the registree indicated. It uses the first available joystick, from a max of 4. Since it doesn't return a HID object, channels are immutable.
func Duplicator ¶
duplicate event onto two chan's
func PositionFromVelocity ¶
creates a chan on which you get CoordsEvent's that are the time integration of the CoordsEvent's on the parameter chan.
Types ¶
type AngleEvent ¶
type AngleEvent struct { Angle float32 // contains filtered or unexported fields }
Hat angle event type. Angle{-Pi...Pi}
type AxisEvent ¶
type AxisEvent struct { V float32 // contains filtered or unexported fields }
Hat Axis event type. V{-1...1}
type ButtonEvent ¶
type ButtonEvent struct {
// contains filtered or unexported fields
}
button changed
type Channel ¶
Type of register-able methods and the index they are called with. (Note: the event type is indicated by the method.)
type CoordsEvent ¶
type CoordsEvent struct {
X, Y float32
// contains filtered or unexported fields
}
Hat position event type. X,Y{-1...1}
type HID ¶
type HID struct { OSEvents chan osEventRecord Buttons map[uint8]button HatAxes map[uint8]hatAxis Events map[eventSignature]chan Event }
HID holds the in-coming event channel, available button and hat indexes, and registered events, for a human interface device. It has methods to control and adjust behaviour.
func Connect ¶
Connect sets up a go routine that puts a joysticks events onto registered channels. to register channels use the returned HID object's On<xxx>(index) methods. Note: only one event, of each type '<xxx>', for each 'index', so re-registering, or deleting, an event stops events going on the old channel. It Needs the HID objects ParcelOutEvents() method to be running to perform routing.(so usually in a go routine.)
func (HID) HatCoords ¶
Hat latest position. provided coords slice needs to be long enough to hold all the hat's axis.
func (HID) InsertSyntheticEvent ¶
insert events as if from hardware.
func (HID) OnDouble ¶
button goes closed and the previous event, open, was less than DoublePressDelay ago, event channel.
func (HID) OnLong ¶
button goes open and the previous event, closed, was more than LongPressDelay ago, event channel.
func (HID) ParcelOutEvents ¶
func (d HID) ParcelOutEvents()
ParcelOutEvents waits on the HID.OSEvents channel (so is blocking), then puts any events matching onto any registered channel(s).