Categorygithub.com/raspberrypi-go-drivers/switchprocontroller

# README

Nintendo Switch Pro Controller

PkgGoDev golangci-lint Go Report Card License: MIT

This drivers allows to read inputs from a Nintendo Switch Pro Controller connected using Bluetooth

Requirements

  • a Nintendo Switch Pro Controller connected to a Raspberry Pi using Bluetooth

Documentation

For full documentation, please visit PkgGoDev

Quick start

import (
	"fmt"

	"github.com/raspberrypi-go-drivers/switchprocontroller"
)

func main() {
	controller := switchprocontroller.NewSwitchProController()
	controller.StartListener(0)
	for {
		select {
		case event := <-controller.Events:
			if event.Button != nil {
				fmt.Printf("%s:%d\n", event.Button.Name, event.Button.State)
			} else if event.Stick != nil {
				fmt.Printf("%s - Y:%f X:%f\n", event.Stick.Name, event.Stick.Y, event.Stick.X)
			}
		case <-time.After(60 * time.Second):
			fmt.Println("timeout")
			return
		}
	}
}

Raspberry Pi compatibility

This driver has has only been tested on an Raspberry Pi Zero WH using integrated bluetooth but may work well on other Raspberry Pi having integrated Bluetooth

License

MIT License

# Functions

NewSwitchProController creates and initialize a SwitchProController instance.

# Structs

Button represent a physical button There's two possible State 1: button pressed 0: button released.
Event is an event.
Stick represent a physical stick It contains a value (in %) for each axis (x and y), this value is contained between -100 and 100 0 is the default value when the stick is in the default position.
SwitchProController represent the physical controller .