Merge pull request #523 from morfeo8marc/dev

joystick: add xbox360 rock band drums controller
This commit is contained in:
Ron Evans 2018-05-08 08:24:27 +02:00 committed by GitHub
commit c91f4d5932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,70 @@
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/joystick"
)
func main() {
joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor, "xbox360RockBandDrums")
work := func() {
stick.On(joystick.RedPress, func(data interface{}) {
fmt.Println("red_press")
})
stick.On(joystick.RedRelease, func(data interface{}) {
fmt.Println("red_release")
})
stick.On(joystick.YellowPress, func(data interface{}) {
fmt.Println("yellow_press")
})
stick.On(joystick.YellowRelease, func(data interface{}) {
fmt.Println("yellow_release")
})
stick.On(joystick.BluePress, func(data interface{}) {
fmt.Println("blue_press")
})
stick.On(joystick.BlueRelease, func(data interface{}) {
fmt.Println("blue_release")
})
stick.On(joystick.GreenPress, func(data interface{}) {
fmt.Println("green_press")
})
stick.On(joystick.GreenRelease, func(data interface{}) {
fmt.Println("blue_release")
})
stick.On(joystick.PedalPress, func(data interface{}) {
fmt.Println("pedal_press")
})
stick.On(joystick.PedalRelease, func(data interface{}) {
fmt.Println("pedal_release")
})
stick.On(joystick.UpPress, func(data interface{}) {
fmt.Println("up", data)
})
stick.On(joystick.DownPress, func(data interface{}) {
fmt.Println("down", data)
})
stick.On(joystick.LeftPress, func(data interface{}) {
fmt.Println("left", data)
})
stick.On(joystick.RightPress, func(data interface{}) {
fmt.Println("right", data)
})
}
robot := gobot.NewRobot("joystickBot",
[]gobot.Connection{joystickAdaptor},
[]gobot.Device{stick},
work,
)
robot.Start()
}

View File

@ -117,4 +117,24 @@ const (
BackPress = "back_press"
// back button release event
BackRelease = "back_release"
// red pad press event
RedPress = "red_press"
// red pad release event
RedRelease = "red_release"
// yellow pad press event
YellowPress = "yellow_press"
// yellow pad release event
YellowRelease = "yellow_release"
// blue pad press event
BluePress = "blue_press"
// blue pad release event
BlueRelease = "blue_release"
// green pad press event
GreenPress = "green_press"
// green pad release event
GreenRelease = "green_release"
// pedal press event
PedalPress = "pedal_press"
// pedal release event
PedalRelease = "pedal_release"
)

View File

@ -102,6 +102,8 @@ func (j *Driver) Start() (err error) {
j.config = dualshock4Config
case "xbox360":
j.config = xbox360Config
case "xbox360RockBandDrums":
j.config = xbox360RockBandDrumsConfig
default:
j.loadFile()
}

View File

@ -0,0 +1,58 @@
package joystick
var xbox360RockBandDrumsConfig = joystickConfig{
Name: "XBox 360 Rock Band Drums Controller",
GUID: "4444",
Axis: []pair{},
Buttons: []pair{
pair{
Name: "green",
ID: 0,
},
pair{
Name: "red",
ID: 1,
},
pair{
Name: "blue",
ID: 2,
},
pair{
Name: "yellow",
ID: 3,
},
pair{
Name: "pedal",
ID: 4,
},
pair{
Name: "back",
ID: 6,
},
pair{
Name: "start",
ID: 7,
},
pair{
Name: "home",
ID: 8,
},
pair{
Name: "left",
ID: 11,
},
pair{
Name: "right",
ID: 12,
},
pair{
Name: "up",
ID: 13,
},
pair{
Name: "down",
ID: 14,
},
},
Hats: []hat{},
}