retroport

package module
v0.0.0-...-e78f441 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2014 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

RetroPort

This package provides a simple Go interface to the [USB RetroPort] hardware. Only the SNES adapter is supported for now, but I expect it'd be very simple to add support for the others.

Documentation

The docs can be found at [godoc.org] docs. It's pretty simple.

Usage

package main

import (
  "fmt"
  "os"
  "time"
  "github.com/adammck/retroport"
)

func main() {

  // open the device
  f, err := os.Open("/dev/hidraw0")
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  // keep the state synchronized in a goroutine
  c := retroport.MakeSNES(f)
  go c.Run()

  // keep dumping the buttons until L and R are held together
  for {
    if c.Any() {
      if c.L && c.R {
        os.Exit(0)
      }

      fmt.Println(c.Buttons())
    }

    time.Sleep(50 * time.Millisecond)
  }
}

License

[MIT] license.

Author

[Adam Mckaig] adammck made this.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SNES

type SNES struct {
	Up     bool
	Down   bool
	Left   bool
	Right  bool
	X      bool
	Y      bool
	A      bool
	B      bool
	L      bool
	R      bool
	Select bool
	Start  bool
	// contains filtered or unexported fields
}

func MakeSNES

func MakeSNES(reader io.Reader) *SNES

MakeSNES returns a pointer to a SNES controller for the given io.reader.

func (*SNES) Any

func (c *SNES) Any() bool

Any returns true if any button is currently pressed.

func (*SNES) Buttons

func (c *SNES) Buttons() string

Buttons returns a string containing a representation of the buttons which are currently pressed. It's just informational, don't rely on the format.

func (*SNES) Run

func (c *SNES) Run()

Run loops forever, keeping the state of the controller up to date. This should be called in a goroutine.

func (*SNES) String

func (c *SNES) String() string

Jump to

Keyboard shortcuts

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