x52

package
v0.0.0-...-1044b80 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: BSD-3-Clause Imports: 5 Imported by: 2

README

Saitek X52/X52Pro Library

The Saitek X52/X52Pro library is used to interface with a supported Saitek X52/X52Pro joystick. The library uses the gousb library to communicate with the joystick.

API Overview

In order to use the library, you will need to create a context. All joystick LED and MFD data is managed through the context. You should close the context when you no longer need it.

ctx := x52.NewContext()
defer ctx.Close()

Unlike the corresponding C library, context creation does not require you to have the joystick plugged in until you wish to actually update it. Therefore, you will need to call OpenDevice to actually connect to the device. The OpenDevice will return a nil error if it was successful in connecting to the joystick, and a corresponding error value if it failed for any reason.

err := ctx.OpenDevice()
if err != nil {
    // ...
}

The library also provides a corresponding CloseDevice method, which can be used when the application no longer needs access to the joystick. However, the library will automatically call CloseDevice when the context is closed.

All the Set* methods set internal data structures within the context, and don't actually update the joystick. In order to do so, the application must call the Update method of the context.

err = ctx.SetLed(x52.LedFire, x52.LedOff)
if err != nil {
    // ...
}
// Write the updated state to the joystick
err = ctx.Update()

The library will also check and close the device automatically if updating it fails because the joystick was unplugged.

LED and MFD control

Currently, the library supports setting the state of all LEDs, the brightness of the LEDs and MFD, and the text on the MFD. The update API is still not working, so the sets won't take effect anyway. The API for these can be considered frozen. The library does NOT yet support setting the date and time display on the MFD, and the API for this is still a work in progress.

Limitations

The library can maintain a connection to only 1 supported device at a time. This means that if you, for some reason, have multiple X52 joysticks connected, only 1 of them will be controlled by the library. No guarantees are made about which of these will be selected, as this is a function of the order in which the devices are enumerated by the USB subsystem.

Documentation

Overview

Package x52 provides handling for the X52/X52Pro devices

Index

Constants

View Source
const (
	LedFire     = LED(0x01)
	LedA        = LED(0x02)
	LedB        = LED(0x04)
	LedD        = LED(0x06)
	LedE        = LED(0x08)
	LedT1       = LED(0x0a)
	LedT2       = LED(0x0c)
	LedT3       = LED(0x0e)
	LedPOV      = LED(0x10)
	LedClutch   = LED(0x12)
	LedThrottle = LED(0x14)
)

LED Identifiers

View Source
const (
	FeatureLED uint32 = iota
)

Feature flags

Variables

This section is empty.

Functions

This section is empty.

Types

type ClockFormat

type ClockFormat uint

ClockFormat describes the time format on the MFD

const (
	ClockFormat12Hr ClockFormat = iota
	ClockFormat24Hr
)

Clock Format Identifiers

type ClockID

type ClockID uint

ClockID identifies the clock on the X52 multifunction display

const (
	Clock1 ClockID = iota
	Clock2
	Clock3
)

Clock Identifiers

type Context

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

Context manages all resources related to device handling

func NewContext

func NewContext() *Context

NewContext returns a new Context against which to run device operations

func (*Context) Close

func (ctx *Context) Close() error

Close closes the context, and any devices that may have been opened will also be closed

func (*Context) Connect

func (ctx *Context) Connect() bool

Connect will try to connect to a supported X52/X52Pro joystick. If the joystick is plugged in and the function succeeds, it returns true, otherwise it returns false. If multiple supported devices are plugged in, then it will pick one of the supported devices in an unspecified manner.

func (*Context) Debug

func (ctx *Context) Debug(level int)

Debug changes the debug level. Level 0 means no debug, higher levels will print out more debugging information.

func (*Context) DebugUSB

func (ctx *Context) DebugUSB(level int)

DebugUSB changes the debug level of the USB subsystem. Level 0 means no debug, higher levels will print out more debugging information.

func (*Context) HasFeature

func (ctx *Context) HasFeature(feature uint32) bool

HasFeature returns true if the X52 device supports the requested feature

func (*Context) Raw

func (ctx *Context) Raw(index, value uint16) error

Raw sends a raw vendor control packet to the device

func (*Context) Reset

func (ctx *Context) Reset() error

Reset resets the connected device. If there is no device connected, it returns errNotConnected, otherwise it will return a corresponding USB error

func (ctx *Context) SetBlink(enable bool) error

SetBlink will enable or disable the blink functionality

func (*Context) SetClockFormat

func (ctx *Context) SetClockFormat(clock ClockID, format ClockFormat) error

SetClockFormat sets the clock format of the given clock

func (*Context) SetDateFormat

func (ctx *Context) SetDateFormat(format DateFormat) error

SetDateFormat sets the date format

func (*Context) SetLEDBrightness

func (ctx *Context) SetLEDBrightness(brightness uint16) error

SetLEDBrightness will set the brightness of the LED.

func (*Context) SetLed

func (ctx *Context) SetLed(led LED, state LedState) error

SetLed sets the state of the given LED. Not all LEDs support all states, LedFire and LedThrottle only support LedOn and LedOff states, the remaining LEDs support every state except LedOn. **Limitation**: This function will not work on a non-pro X52 at this time.

func (*Context) SetLocation

func (ctx *Context) SetLocation(clock ClockID, loc *time.Location) error

SetLocation updates the location of the given clock. You may not update the location of the primary clock, as it is computed when you call SetTime

func (*Context) SetMFDBrightness

func (ctx *Context) SetMFDBrightness(brightness uint16) error

SetMFDBrightness will set the brightness of the MFD.

func (*Context) SetMFDText

func (ctx *Context) SetMFDText(line uint8, data []byte) error

SetMFDText sets the display on the given MFD line. The data must be in the code page recognized by the MFD. This function only accepts line lengths of up to 16 bytes, with any additional data being silently discarded.

func (*Context) SetShift

func (ctx *Context) SetShift(enable bool) error

SetShift will enable or disable the shift functionality

func (*Context) SetTime

func (ctx *Context) SetTime(t time.Time) error

SetTime sets the time of the primary clock. The secondary and tertiary clocks are derived by setting a programmable offset from the primary clock.

func (*Context) Update

func (ctx *Context) Update() error

Update updates the X52 with the saved data

type DateFormat

type DateFormat uint

DateFormat describes the date format on the MFD

const (
	DateFormatDDMMYY DateFormat = iota
	DateFormatMMDDYY
	DateFormatYYMMDD
)

Date Format Identifiers

type LED

type LED uint

LED contains the supported LEDs

func (LED) String

func (led LED) String() string

String returns a string representation of the LED

type LedState

type LedState uint

LedState contains the possible LED states. Each LED only supports a subset of the states

const (
	LedOff LedState = iota
	LedOn
	LedRed
	LedAmber
	LedGreen
)

LED State Identifiers

func (LedState) String

func (state LedState) String() string

String returns a string representation of the LED state

Directories

Path Synopsis
Package util provides utility functions to simplify controlling the X52
Package util provides utility functions to simplify controlling the X52

Jump to

Keyboard shortcuts

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