Update joystick package and examples
This commit is contained in:
parent
ef41a36f0f
commit
02ea69f7e0
|
@ -3,18 +3,13 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/joystick"
|
||||
"github.com/hybridgroup/gobot/platforms/joystick"
|
||||
)
|
||||
|
||||
func main() {
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor()
|
||||
joystickAdaptor.Name = "ps3"
|
||||
joystickAdaptor.Params = map[string]interface{}{
|
||||
"config": "../joystick/configs/dualshock3.json",
|
||||
}
|
||||
|
||||
joystickDriver := joystick.NewJoystickDriver(joystickAdaptor)
|
||||
joystickDriver.Name = "ps3"
|
||||
gbot := gobot.NewGobot()
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
|
||||
joystickDriver := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "../joystick/configs/dualshock3.json")
|
||||
|
||||
work := func() {
|
||||
gobot.On(joystickDriver.Events["square_press"], func(data interface{}) {
|
||||
|
@ -43,11 +38,8 @@ func main() {
|
|||
})
|
||||
}
|
||||
|
||||
robot := gobot.Robot{
|
||||
Connections: []gobot.Connection{joystickAdaptor},
|
||||
Devices: []gobot.Device{joystickDriver},
|
||||
Work: work,
|
||||
}
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystickDriver}, work))
|
||||
|
||||
robot.Start()
|
||||
gbot.Start()
|
||||
}
|
||||
|
|
|
@ -3,18 +3,13 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/joystick"
|
||||
"github.com/hybridgroup/gobot/platforms/joystick"
|
||||
)
|
||||
|
||||
func main() {
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor()
|
||||
joystickAdaptor.Name = "xbox360"
|
||||
joystickAdaptor.Params = map[string]interface{}{
|
||||
"config": "../joystick/configs/xbox360_power_a_mini_proex.json",
|
||||
}
|
||||
|
||||
joystickDriver := joystick.NewJoystickDriver(joystickAdaptor)
|
||||
joystickDriver.Name = "xbox360"
|
||||
gbot := gobot.NewGobot()
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor("xbox360")
|
||||
joystickDriver := joystick.NewJoystickDriver(joystickAdaptor, "xbox360", "../joystick/configs/xbox360_power_a_mini_proex.json")
|
||||
|
||||
work := func() {
|
||||
gobot.On(joystickDriver.Events["a_press"], func(data interface{}) {
|
||||
|
@ -55,11 +50,8 @@ func main() {
|
|||
})
|
||||
}
|
||||
|
||||
robot := gobot.Robot{
|
||||
Connections: []gobot.Connection{joystickAdaptor},
|
||||
Devices: []gobot.Device{joystickDriver},
|
||||
Work: work,
|
||||
}
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystickDriver}, work))
|
||||
|
||||
robot.Start()
|
||||
gbot.Start()
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ type JoystickAdaptor struct {
|
|||
connect func(*JoystickAdaptor)
|
||||
}
|
||||
|
||||
func NewJoystickAdaptor() *JoystickAdaptor {
|
||||
func NewJoystickAdaptor(name string) *JoystickAdaptor {
|
||||
return &JoystickAdaptor{
|
||||
connect: func(j *JoystickAdaptor) {
|
||||
sdl.Init(sdl.INIT_JOYSTICK)
|
||||
|
|
|
@ -11,7 +11,7 @@ var _ = Describe("JoystickAdaptor", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
j = NewJoystickAdaptor()
|
||||
j = NewJoystickAdaptor("bot")
|
||||
})
|
||||
|
||||
PIt("Must be able to Finalize", func() {
|
||||
|
|
|
@ -34,7 +34,7 @@ type joystickConfig struct {
|
|||
Hats []hat `json:"Hats"`
|
||||
}
|
||||
|
||||
func NewJoystickDriver(a *JoystickAdaptor) *JoystickDriver {
|
||||
func NewJoystickDriver(a *JoystickAdaptor, name string, config string) *JoystickDriver {
|
||||
d := &JoystickDriver{
|
||||
Driver: gobot.Driver{
|
||||
Events: make(map[string]chan interface{}),
|
||||
|
@ -42,14 +42,7 @@ func NewJoystickDriver(a *JoystickAdaptor) *JoystickDriver {
|
|||
Adaptor: a,
|
||||
}
|
||||
|
||||
var configFile string
|
||||
if value, ok := d.Adaptor.Params["config"]; ok {
|
||||
configFile = value.(string)
|
||||
} else {
|
||||
panic("No joystick config specified")
|
||||
}
|
||||
|
||||
file, e := ioutil.ReadFile(configFile)
|
||||
file, e := ioutil.ReadFile(config)
|
||||
if e != nil {
|
||||
panic(fmt.Sprintf("File error: %v\n", e))
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ var _ = Describe("JoystickDriver", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
d = NewJoystickDriver(NewJoystickAdaptor())
|
||||
d = NewJoystickDriver(NewJoystickAdaptor("bot"), "bot", "/dev/null")
|
||||
})
|
||||
|
||||
PIt("Must be able to Start", func() {
|
||||
|
|
Loading…
Reference in New Issue