platforms/joystick: remove unused interface and go fmt cleanup
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
b3b92796bb
commit
2afb3e6b91
|
@ -3,9 +3,7 @@ Package joystick provides the Gobot adaptor and drivers for game controllers tha
|
|||
|
||||
Installing:
|
||||
|
||||
This package requires `sdl2` to be installed on your system
|
||||
|
||||
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
|
||||
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -20,9 +18,7 @@ Example:
|
|||
|
||||
func main() {
|
||||
joystickAdaptor := joystick.NewAdaptor(0)
|
||||
joystick := joystick.NewDriver(joystickAdaptor,
|
||||
"./platforms/joystick/configs/dualshock3.json",
|
||||
)
|
||||
joystick := joystick.NewDriver(joystickAdaptor, "dualshock3")
|
||||
|
||||
work := func() {
|
||||
joystick.On(joystick.Event("square_press"), func(data interface{}) {
|
||||
|
|
|
@ -8,15 +8,10 @@ import (
|
|||
js "github.com/0xcafed00d/joystick"
|
||||
)
|
||||
|
||||
type joystick interface {
|
||||
Close()
|
||||
ID() int
|
||||
}
|
||||
|
||||
// Adaptor represents a connection to a joystick
|
||||
type Adaptor struct {
|
||||
name string
|
||||
id int
|
||||
id int
|
||||
joystick js.Joystick
|
||||
connect func(*Adaptor) error
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot/v2"
|
||||
js "github.com/0xcafed00d/joystick"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -41,15 +41,15 @@ const (
|
|||
|
||||
// Driver represents a joystick
|
||||
type Driver struct {
|
||||
name string
|
||||
interval time.Duration
|
||||
connection gobot.Connection
|
||||
configPath string
|
||||
config joystickConfig
|
||||
name string
|
||||
interval time.Duration
|
||||
connection gobot.Connection
|
||||
configPath string
|
||||
config joystickConfig
|
||||
buttonState map[int]bool
|
||||
axisState map[int]int
|
||||
axisState map[int]int
|
||||
|
||||
halt chan bool
|
||||
halt chan bool
|
||||
gobot.Eventer
|
||||
}
|
||||
|
||||
|
@ -76,12 +76,12 @@ type joystickConfig struct {
|
|||
// time.Duration: Interval at which the Driver is polled for new information
|
||||
func NewDriver(a *Adaptor, config string, v ...time.Duration) *Driver {
|
||||
d := &Driver{
|
||||
name: gobot.DefaultName("Joystick"),
|
||||
connection: a,
|
||||
Eventer: gobot.NewEventer(),
|
||||
configPath: config,
|
||||
name: gobot.DefaultName("Joystick"),
|
||||
connection: a,
|
||||
Eventer: gobot.NewEventer(),
|
||||
configPath: config,
|
||||
buttonState: make(map[int]bool),
|
||||
axisState: make(map[int]int),
|
||||
axisState: make(map[int]int),
|
||||
|
||||
interval: 10 * time.Millisecond,
|
||||
halt: make(chan bool),
|
||||
|
@ -161,8 +161,16 @@ func (j *Driver) Start() (err error) {
|
|||
j.Publish(j.Event("error"), err)
|
||||
break
|
||||
}
|
||||
j.handleButtons(state)
|
||||
j.handleAxes(state)
|
||||
|
||||
// might just be missing a button definition, so keep going
|
||||
if err := j.handleButtons(state); err != nil {
|
||||
j.Publish(j.Event("error"), err)
|
||||
}
|
||||
|
||||
// might just be missing an axis definition, so keep going
|
||||
if err := j.handleAxes(state); err != nil {
|
||||
j.Publish(j.Event("error"), err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(j.interval):
|
||||
|
|
|
@ -4,9 +4,9 @@ import js "github.com/0xcafed00d/joystick"
|
|||
|
||||
type testJoystick struct{}
|
||||
|
||||
func (t *testJoystick) Close() {}
|
||||
func (t *testJoystick) ID() int { return 0 }
|
||||
func (t *testJoystick) ButtonCount() int { return 0 }
|
||||
func (t *testJoystick) AxisCount() int { return 0 }
|
||||
func (t *testJoystick) Name() string { return "test-joy" }
|
||||
func (t *testJoystick) Close() {}
|
||||
func (t *testJoystick) ID() int { return 0 }
|
||||
func (t *testJoystick) ButtonCount() int { return 0 }
|
||||
func (t *testJoystick) AxisCount() int { return 0 }
|
||||
func (t *testJoystick) Name() string { return "test-joy" }
|
||||
func (t *testJoystick) Read() (js.State, error) { return js.State{}, nil }
|
||||
|
|
Loading…
Reference in New Issue