Documentation ¶
Overview ¶
Package jcpc (Joy-Con PC) contains constants, interface definitions, and short utility functions for the joy-con driver.
Index ¶
- Constants
- Variables
- func SPIFlashRead(jc JoyCon, addr, size uint32) ([]byte, error)
- func SPIFlashWrite(jc JoyCon, addr uint16, p []byte) error
- func SetHomeLightPulse(jc JoyCon, pulseData []byte)
- func SetPlayerLights(jc JoyCon, pattern byte)
- type AxisID
- type BluetoothDeviceNotification
- type BluetoothManager
- type ButtonID
- type ButtonState
- func (b ButtonState) DiffMask(other ButtonState) ButtonState
- func (b ButtonState) Get(i ButtonID) bool
- func (b ButtonState) HasAll(mask ButtonState) bool
- func (b ButtonState) HasAny(mask ButtonState) bool
- func (b ButtonState) PairCheckDouble(b2 ButtonState) bool
- func (b ButtonState) PairCheckSelf() (selfPair bool, maybeDouble bool)
- func (b ButtonState) Remove(side JoyConType) ButtonState
- func (b ButtonState) Set(i ButtonID, state bool) ButtonState
- func (b ButtonState) Union(other ButtonState) ButtonState
- type CombinedState
- type Controller
- type GyroFrame
- type InputMode
- type InputRemappingOptions
- type Interface
- type JoyCon
- type JoyConNotify
- type JoyConType
- type Options
- type Output
- type OutputFactory
- type RumbleData
Constants ¶
const ( ButtonPushDown = 1 << iota ButtonPushRight ButtonPushLeft ButtonPushUp // remember to rotate these for L and R Joy-Cons ButtonPushSL ButtonPushSR ButtonPushMinus ButtonPushPlus ButtonPushLStick ButtonPushRStick ButtonPushHome ButtonPushCapture ButtonPushLR ButtonPushZLZR )
Bits in the 0x3F "push" mode treated as a little-endian int16. See ConvertPushReport().
const ( // Stick - uint8 from [0, 255] Axis_L_Horiz = iota Axis_L_Vertical Axis_R_Horiz Axis_R_Vertical // Gyro - int16 from [-0x10FF, +0x10FF] Axis_Yaw_X Axis_Yaw_Y Axis_Pitch_X Axis_Pitch_Y Axis_Roll_X Axis_Roll_Y Axis_Orientation_Min = Axis_Yaw_X )
const ( VENDOR_NINTENDO = 0x057e JOYCON_PRODUCT_L = 0x2006 JOYCON_PRODUCT_R = 0x2007 JOYCON_PRODUCT_FAKE = 0x2008 // TODO JOYCON_PRODUCT_PRO = 0x2009 JOYCON_PRODUCT_CHARGEGRIP = 0x200e )
const ( NotifyInput = 1 << iota NotifyConnection NotifyBattery )
const ( InputIRPolling InputMode = 0 InputIRPollingUnused = 1 InputIRPollingSpecial = 2 InputMCUUpdate = 0x23 // not fully known InputStandard = 0x30 InputNFC = 0x31 InputUnknown33 = 0x33 InputUnknown35 = 0x35 InputLazyButtons InputMode = 0x3F InputActivePolling = 0x13F // pseudo-mode, driver only )
const SPIMaxData = 0x1C
Variables ¶
var ( // Side Joy-Con ButtonsSLSR_R = ButtonState{byte((Button_R_SL | Button_R_SR) & 0xFF), 0, 0} ButtonsSLSR_L = ButtonState{0, 0, byte((Button_L_SL | Button_L_SR) & 0xFF)} // Upright Pair ButtonsRZR = ButtonState{byte((Button_R_R | Button_R_ZR) & 0xFF), 0, 0} ButtonsLZL = ButtonState{0, 0, byte((Button_L_L | Button_L_ZL) & 0xFF)} // Pro Controller ButtonsLR = ButtonState{byte(Button_R_R & 0xFF), 0, byte(Button_L_L & 0xFF)} ButtonsZLZR = ButtonState{byte(Button_R_ZR & 0xFF), 0, byte(Button_L_ZL & 0xFF)} ButtonsAnyLR = ButtonState{}.Union(ButtonsRZR).Union(ButtonsLZL).Union(ButtonsSLSR_L).Union(ButtonsSLSR_R) )
All button combinations considered to be a L+R press or part of one
var ButtonList = []ButtonID{ Button_R_Y, Button_R_X, Button_R_B, Button_R_A, Button_R_SR, Button_R_SL, Button_R_R, Button_R_ZR, Button_Minus, Button_Plus, Button_R_Stick, Button_L_Stick, Button_Home, Button_Capture, Button_Unused1, Button_IsChargeGrip, Button_L_Down, Button_L_Up, Button_L_Right, Button_L_Left, Button_L_SR, Button_L_SL, Button_L_L, Button_L_ZL, }
var GyroZero [3]GyroFrame
var RumbleDataNeutral = RumbleData{[8]byte{0, 1, 0x40, 0x40, 0, 1, 0x40, 0x40}, 8}
Functions ¶
func SetHomeLightPulse ¶
func SetPlayerLights ¶
Types ¶
type BluetoothManager ¶
type BluetoothManager interface { // Call StartDiscovery when the UI enters a "change controller // order/layout" screen. StartDiscovery() // Call StopDiscovery when the UI exits a "change controller order/layout" // screen. Paired controllers set up for auto-reconnect will still generate // device connect events. StopDiscovery() // Check for devices already connected to the system, send notifications // on NotifyChannel, and subscribe to future changes. InitialScan() // The UI code should call this after a L+R press to ensure clean // auto-reconnect. SavePairingInfo(mac [6]byte) // The UI code must provide a way for the user to reset auto-reconnect // records, which (Linux) will occur whenever the Joy-Con is connected to a // different Switch. DeletePairingInfo() NotifyChannel() <-chan BluetoothDeviceNotification }
BluetoothManager provides an interface to the OS bluetooth stack.
type ButtonID ¶
type ButtonID int16
const ( Button_R_Y ButtonID = 0x000 + (1 << iota) Button_R_X Button_R_B Button_R_A Button_R_SR Button_R_SL Button_R_R Button_R_ZR )
First byte of ButtonState.
const ( Button_Minus ButtonID = 0x100 + (1 << iota) Button_Plus Button_R_Stick Button_L_Stick Button_Home Button_Capture Button_Unused1 Button_IsChargeGrip )
Middle byte of ButtonState.
type ButtonState ¶
type ButtonState [3]byte
func ButtonsFromSlice ¶
func ButtonsFromSlice(b []byte) ButtonState
ButtonsFromSlice copies the provided slice from a standard input report into a ButtonState.
func ConvertPushReport ¶
func ConvertPushReport(side JoyConType, buttons []byte) ButtonState
ConvertPushReport converts a 0x3F "push" button press report into a ButtonState. Only for Left and Right Joy-Cons (Pro Controllers use a different format).
The report ID (0x3F) should be removed from the 'buttons' slice.
func (ButtonState) DiffMask ¶
func (b ButtonState) DiffMask(other ButtonState) ButtonState
DiffMask returns a ButtonState with a '1' bit everywhere that this state differs from `other`.
func (ButtonState) Get ¶
func (b ButtonState) Get(i ButtonID) bool
Get the state of a single ButtonID.
func (ButtonState) HasAll ¶
func (b ButtonState) HasAll(mask ButtonState) bool
func (ButtonState) HasAny ¶
func (b ButtonState) HasAny(mask ButtonState) bool
func (ButtonState) PairCheckDouble ¶
func (b ButtonState) PairCheckDouble(b2 ButtonState) bool
Check for a double Joy-Con L+R press. Make sure not to call this if either of the two controllers is a Pro Controller.
func (ButtonState) PairCheckSelf ¶
func (b ButtonState) PairCheckSelf() (selfPair bool, maybeDouble bool)
Check for a L+R press. If this might be half of a double Joy-Con, the second return value (maybeDouble) will be true.
func (ButtonState) Remove ¶
func (b ButtonState) Remove(side JoyConType) ButtonState
func (ButtonState) Set ¶
func (b ButtonState) Set(i ButtonID, state bool) ButtonState
func (ButtonState) Union ¶
func (b ButtonState) Union(other ButtonState) ButtonState
Union returns a ButtonState with all 'on' positions contained in either argument.
type CombinedState ¶
type CombinedState struct { // 3 frames of 6 values Gyro [3]GyroFrame // [left, right][horizontal, vertical] // range is -0x7FF to +0x7FF AdjSticks [2][2]int16 Buttons ButtonState }
type Controller ¶
type Controller interface { JoyConNotify BindToOutput(Output) // forwards to each JoyCon Rumble(d []RumbleData) OnFrame() Close() error }
type InputRemappingOptions ¶
type InputRemappingOptions struct {
InvertedAxes []AxisID
}
InputRemappingOptions specifies if and how Buttons or Axes should be remapped currently only Axis-Inversion is implemented
type Interface ¶
type Interface interface { JoyConNotify RemoveController(c Controller) }
type JoyCon ¶
type JoyCon interface { BindToController(Controller) BindToInterface(Interface) Serial() string Type() JoyConType // Returns true if a reconnect is needed - a communication error has occurred, and // Close() / Shutdown() have not been called. WantsReconnect() bool // Returns true if Close() or Shutdown() have been called. IsStopping() bool // Ask the JoyCon to disconnect and stay disconnected. Shutdown() // Must be of type github.com/GeertJohan/go.hid#DeviceInfo Reconnect(hidDeviceInfo interface{}) Buttons() ButtonState // Indexed by [left,right][x,y] // Prefer use of ReadInto() for stick data RawSticks() [2][2]uint16 Battery() (int8, bool) ReadInto(out *CombinedState, includeGyro bool) ChangeInputMode(mode InputMode) bool // returns false if impossible EnableGyro(status bool) SPIRead(addr uint32, len byte) ([]byte, error) SPIWrite(addr uint32, p []byte) error // Valid returns have alpha=255. If alpha=0 the value is not yet available. CaseColor() color.RGBA ButtonColor() color.RGBA Rumble(d []RumbleData) SendCustomSubcommand(d []byte) OnFrame() Close() error }
type JoyConNotify ¶
type JoyConType ¶
type JoyConType int
const ( TypeInvalid JoyConType = iota TypeLeft TypeRight TypeBoth )
func (JoyConType) IsLeft ¶
func (t JoyConType) IsLeft() bool
func (JoyConType) IsRight ¶
func (t JoyConType) IsRight() bool
func (JoyConType) String ¶
func (t JoyConType) String() string
type Options ¶
type Options struct {
InputRemapping InputRemappingOptions
}
Options specifies Options for changing the programms behavior (for example obtained via cli-flags)
type Output ¶
type Output interface { BeginUpdate() error ButtonUpdate(b ButtonID, value bool) StickUpdate(axis AxisID, value int16) GyroUpdate(vals GyroFrame) FlushUpdate() error OnFrame() Close() error }
Output represents an OS-level event sink for a Controller object. The Controller should call BeginUpdate(), then several *Update() methods, followed by FlushUpdate().
type OutputFactory ¶
type OutputFactory func(t JoyConType, playerNum int, remap InputRemappingOptions) (Output, error)