Skip to content

Commit

Permalink
joystick: full corrected ds3 and ds4 mappings plus examples to match …
Browse files Browse the repository at this point in the history
…for latest sdl 2.0.8

Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed May 25, 2018
1 parent ed867b9 commit 615cd71
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 66 deletions.
6 changes: 6 additions & 0 deletions examples/joystick_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func main() {
stick.On(joystick.SelectRelease, func(data interface{}) {
fmt.Println("select_release")
})
stick.On(joystick.HomePress, func(data interface{}) {
fmt.Println("home_press")
})
stick.On(joystick.HomeRelease, func(data interface{}) {
fmt.Println("home_release")
})
stick.On(joystick.RightPress, func(data interface{}) {
fmt.Println("right_press")
})
Expand Down
74 changes: 74 additions & 0 deletions examples/joystick_ps4.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,74 @@ func main() {
stick.On(joystick.XRelease, func(data interface{}) {
fmt.Println("x_release")
})
stick.On(joystick.HomePress, func(data interface{}) {
fmt.Println("home_press")
})
stick.On(joystick.HomeRelease, func(data interface{}) {
fmt.Println("home_release")
})
stick.On(joystick.SharePress, func(data interface{}) {
fmt.Println("share_press")
})
stick.On(joystick.ShareRelease, func(data interface{}) {
fmt.Println("share_release")
})
stick.On(joystick.OptionsPress, func(data interface{}) {
fmt.Println("options_press")
})
stick.On(joystick.OptionsRelease, func(data interface{}) {
fmt.Println("options_release")
})
stick.On(joystick.L1Press, func(data interface{}) {
fmt.Println("l1_press")
})
stick.On(joystick.L1Release, func(data interface{}) {
fmt.Println("l1_release")
})
stick.On(joystick.L2Press, func(data interface{}) {
fmt.Println("l2_press")
})
stick.On(joystick.L2Release, func(data interface{}) {
fmt.Println("l2_release")
})
stick.On(joystick.R1Press, func(data interface{}) {
fmt.Println("r1_press")
})
stick.On(joystick.R1Release, func(data interface{}) {
fmt.Println("r1_release")
})
stick.On(joystick.R2Press, func(data interface{}) {
fmt.Println("r2_press")
})
stick.On(joystick.R2Release, func(data interface{}) {
fmt.Println("r2_release")
})

stick.On(joystick.UpPress, func(data interface{}) {
fmt.Println("up_press")
})
stick.On(joystick.UpRelease, func(data interface{}) {
fmt.Println("up_release")
})
stick.On(joystick.DownPress, func(data interface{}) {
fmt.Println("down_press")
})
stick.On(joystick.DownRelease, func(data interface{}) {
fmt.Println("down_release")
})
stick.On(joystick.RightPress, func(data interface{}) {
fmt.Println("right_press")
})
stick.On(joystick.RightRelease, func(data interface{}) {
fmt.Println("right_release")
})
stick.On(joystick.LeftPress, func(data interface{}) {
fmt.Println("left_press")
})
stick.On(joystick.LeftRelease, func(data interface{}) {
fmt.Println("left_release")
})

stick.On(joystick.LeftX, func(data interface{}) {
fmt.Println("left_x", data)
})
Expand All @@ -52,6 +120,12 @@ func main() {
stick.On(joystick.RightY, func(data interface{}) {
fmt.Println("right_y", data)
})
stick.On(joystick.L2, func(data interface{}) {
fmt.Println("L2", data)
})
stick.On(joystick.R2, func(data interface{}) {
fmt.Println("R2", data)
})
}

robot := gobot.NewRobot("joystickBot",
Expand Down
44 changes: 27 additions & 17 deletions platforms/dji/tello/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -179,26 +180,28 @@ type WifiData struct {

// Driver represents the DJI Tello drone
type Driver struct {
name string
reqAddr string
reqConn *net.UDPConn // UDP connection to send/receive drone commands
videoConn *net.UDPConn // UDP connection for drone video
respPort string
cmdMutex sync.Mutex
seq int16
rx, ry, lx, ly float32
throttle int
bouncing bool
name string
reqAddr string
reqConn *net.UDPConn // UDP connection to send/receive drone commands
videoConn *net.UDPConn // UDP connection for drone video
respPort string
videoPort string
cmdMutex sync.Mutex
seq int16
rx, ry, lx, ly float32
throttle int
bouncing bool
gobot.Eventer
}

// NewDriver creates a driver for the Tello drone. Pass in the UDP port to use for the responses
// from the drone.
func NewDriver(port string) *Driver {
d := &Driver{name: gobot.DefaultName("Tello"),
reqAddr: "192.168.10.1:8889",
respPort: port,
Eventer: gobot.NewEventer(),
reqAddr: "192.168.10.1:8889",
respPort: port,
videoPort: "6038",
Eventer: gobot.NewEventer(),
}

d.AddEvent(ConnectedEvent)
Expand Down Expand Up @@ -256,9 +259,8 @@ func (d *Driver) Start() error {
}
}()

// starts notifications coming from drone to port 6038 aka 0x9617 when encoded low-endian.
// TODO: allow setting a specific video port.
d.SendCommand("conn_req:\x96\x17")
// starts notifications coming from drone to video port normally 6038
d.SendCommand(d.connectionString())

// send stick commands
go func() {
Expand Down Expand Up @@ -292,7 +294,7 @@ func (d *Driver) TakeOff() (err error) {
return
}

// Throw & Go support
// Throw & Go support
func (d *Driver) ThrowTakeOff() (err error) {
buf, _ := d.createPacket(throwtakeoffCommand, 0x48, 0)
d.seq++
Expand Down Expand Up @@ -809,3 +811,11 @@ func (d *Driver) createPacket(cmd int16, pktType byte, len int16) (buf *bytes.Bu

return buf, nil
}

func (d *Driver) connectionString() string {
x, _ := strconv.Atoi(d.videoPort)
b := [2]byte{}
binary.LittleEndian.PutUint16(b[:], uint16(x))
res := fmt.Sprintf("conn_req:%s", b)
return res
}
42 changes: 17 additions & 25 deletions platforms/joystick/joystick_dualshock3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,73 @@ var dualshock3Config = joystickConfig{
},
pair{
Name: "right_x",
ID: 2,
ID: 3,
},
pair{
Name: "right_y",
ID: 3,
ID: 4,
},
},
Buttons: []pair{
pair{
Name: "square",
ID: 15,
ID: 3,
},
pair{
Name: "triangle",
ID: 12,
ID: 2,
},
pair{
Name: "circle",
ID: 13,
ID: 1,
},
pair{
Name: "x",
ID: 14,
ID: 0,
},
pair{
Name: "up",
ID: 4,
ID: 13,
},
pair{
Name: "down",
ID: 6,
ID: 14,
},
pair{
Name: "left",
ID: 7,
ID: 15,
},
pair{
Name: "right",
ID: 5,
},
pair{
Name: "left_stick",
ID: 1,
},
pair{
Name: "right_stick",
ID: 2,
ID: 16,
},
pair{
Name: "l1",
ID: 10,
ID: 4,
},
{
Name: "l2",
ID: 8,
ID: 6,
},
pair{
Name: "r1",
ID: 11,
ID: 5,
},
pair{
Name: "r2",
ID: 9,
ID: 7,
},
pair{
Name: "start",
ID: 3,
ID: 9,
},
pair{
Name: "select",
ID: 0,
ID: 8,
},
pair{
Name: "home",
ID: 16,
ID: 10,
},
},
Hats: []hat{},
Expand Down
Loading

0 comments on commit 615cd71

Please sign in to comment.