joycon

package module
v0.0.0-...-1f3feea Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 11 Imported by: 0

README

joycon

Nintendo Switch's Joycon Device access library(via bluetooth only)

Reverse engineering info

https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering

Feature

  • supported deveces: Joycon(L/R), Pro-Controller
  • get: Digial Buttons state
  • get: Analog Sticks state
  • set: Raw Vibration data
  • calibration support for analog stick.

Dependencies

  • go get -u github.com/flynn/hid
  • go get -u github.com/shibukawa/gotomation optional

Usage

In advance, you perform Bluetooth pairing for Joycon. (Joycon must be connected before execute below code.)

Note: When Joycon is fitted to the main body, BT sessions are overwritten, so when you connect to PC later, you need to redo pairing.

package main

import "github.com/nobonobo/joycon"

func main() {
    devices, err := joycon.Search(joycon.JoyConL)
    if err != nil {
        log.Fatalln(err)
    }
    jc, err := joycon.NewJoycon(devices[0].Path, false)
    if err != nil {
        log.Fatalln(err)
    }
    s := <-jc.State()
    fmt.Println(s.Buttons)  // Button bits
    fmt.Println(s.LeftAdj)  // Left Analog Stick State
    fmt.Println(s.RightAdj) // Right Analog Stick State
    a := <-jc.Sensor()
    fmt.Println(a.Accel) // Acceleration Sensor State
    fmt.Println(a.Gyro)  // Gyro Sensor State

    jc.Close()
}

TODO

  • Deadzone parameter read from SPI memory.
  • Rich Vibration support.
  • Set Player LED.
  • Set HomeButton LED.
  • Low power mode support.
  • IR sensor capture.(wip)

Documentation

Index

Constants

View Source
const (
	GyroRange = 16000
	SensorRes = 65535
	GyroGain  = 4000
	//AccelK     = GyroRange / SensorRes / 1000
	AccelK = 1.0 / 4096
	//GyroK      = GyroGain / SensorRes
	GyroK = 1.0 / 4096
)

Variables

This section is empty.

Functions

func Search(dts ...DeviceType) ([]*hid.DeviceInfo, error)

Search ...

Types

type CalibInfo

type CalibInfo struct {
	Center Stick
	Min    Stick
	Max    Stick
}

CalibInfo ...

func (*CalibInfo) UnmarshalBinary

func (ci *CalibInfo) UnmarshalBinary(b []byte) error

UnmarshalBinary ...

type DeviceType

type DeviceType int
const (
	JoyConL DeviceType = 0x2006
	JoyConR DeviceType = 0x2007
	ProCon  DeviceType = 0x2009
)

type IRData

type IRData struct {
}

IRData ...

func (*IRData) UnmarshalBinary

func (ir *IRData) UnmarshalBinary(b []byte) error

UnmarshalBinary ...

type Joycon

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

Joycon ...

func NewJoycon

func NewJoycon(devicePath string, irenable bool) (*Joycon, error)

NewJoycon ...

func (*Joycon) Close

func (jc *Joycon) Close()

Close ...

func (*Joycon) IRData

func (jc *Joycon) IRData() <-chan IRData

IRData ...

func (*Joycon) IsLeft

func (jc *Joycon) IsLeft() bool

IsLeft ...

func (*Joycon) IsProCon

func (jc *Joycon) IsProCon() bool

IsProCon ...

func (*Joycon) IsRight

func (jc *Joycon) IsRight() bool

IsRight ...

func (*Joycon) LeftStickCalibration

func (jc *Joycon) LeftStickCalibration() CalibInfo

LeftStickCalibration ...

func (*Joycon) Name

func (jc *Joycon) Name() string

Name ...

func (*Joycon) ReadSPI

func (jc *Joycon) ReadSPI(addr uint16, length int) ([]byte, error)

ReadSPI ...

func (*Joycon) RightStickCalibration

func (jc *Joycon) RightStickCalibration() CalibInfo

RightStickCalibration ...

func (*Joycon) SendRumble

func (jc *Joycon) SendRumble(rs ...RumbleSet) error

SendRumble ...

func (*Joycon) Sensor

func (jc *Joycon) Sensor() <-chan Sensor

Sensor ...

func (*Joycon) State

func (jc *Joycon) State() <-chan State

State ...

func (*Joycon) Stats

func (jc *Joycon) Stats() Stats

Stats ...

func (*Joycon) Subcommand

func (jc *Joycon) Subcommand(b []byte) ([]byte, error)

Subcommand ...

type Rumble

type Rumble struct {
	HiFreq uint8 // 7bits normal 64
	HiAmp  uint8 // 7bits normal 0
	LoFreq uint8 // 7bits normal 64
	LoAmp  uint8 // 7bits normal 0
}

Rumble ...

type RumbleSet

type RumbleSet [2]Rumble

RumbleSet ...

func (RumbleSet) MarshalBinary

func (rs RumbleSet) MarshalBinary() ([]byte, error)

MarshalBinary ...

type Sensor

type Sensor struct {
	Tick  byte
	Gyro  Vec3
	Accel Vec3
}

Sensor ...

type Sensors

type Sensors [3]Sensor

Sensors ...

func (*Sensors) UnmarshalBinary

func (s *Sensors) UnmarshalBinary(b []byte) error

UnmarshalBinary ...

type State

type State struct {
	Tick     byte
	Battery  int
	Buttons  uint32
	Left     Stick
	Right    Stick
	LeftAdj  Vec2
	RightAdj Vec2
	Err      error
}

State ...

func (*State) UnmarshalBinary

func (s *State) UnmarshalBinary(b []byte) error

UnmarshalBinary ...

type Stats

type Stats struct {
	RumbleCount uint64
	SensorCount uint64
	IRDataCount uint64
	StateCount  uint64
}

Stats ...

type Stick

type Stick struct {
	X int16
	Y int16
}

Stick ...

func (Stick) String

func (s Stick) String() string

String ...

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

Vec2 ...

func (Vec2) String

func (v Vec2) String() string

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

Vec3 ...

func (Vec3) String

func (v Vec3) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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