mirror of
https://github.com/SMerrony/telloterm.git
synced 2023-04-24 19:01:59 +03:00
Add deadZone and windows joystick
This commit is contained in:
31
joystick.go
31
joystick.go
@@ -25,6 +25,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/SMerrony/tello"
|
"github.com/SMerrony/tello"
|
||||||
@@ -62,6 +63,8 @@ const (
|
|||||||
btnUnknown
|
btnUnknown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const deadZone = 2000
|
||||||
|
|
||||||
type joystickConfig struct {
|
type joystickConfig struct {
|
||||||
axes []int
|
axes []int
|
||||||
buttons []uint
|
buttons []uint
|
||||||
@@ -77,6 +80,17 @@ var dualShock4Config = joystickConfig{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dualShock4ConfigWin = joystickConfig{
|
||||||
|
axes: []int{
|
||||||
|
axLeftX: 0, axLeftY: 1, axRightX: 2, axRightY: 3,
|
||||||
|
},
|
||||||
|
buttons: []uint{
|
||||||
|
btnX: 1, btnCircle: 2, btnTriangle: 3, btnSquare: 0, btnL1: 4,
|
||||||
|
btnL2: 6, btnR1: 5, btnR2: 7,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// hotas mapping seems the same on windows and linux
|
||||||
var tflightHotasXConfig = joystickConfig{
|
var tflightHotasXConfig = joystickConfig{
|
||||||
axes: []int{
|
axes: []int{
|
||||||
axLeftX: 4, axLeftY: 2, axRightX: 0, axRightY: 1,
|
axLeftX: 4, axLeftY: 2, axRightX: 0, axRightY: 1,
|
||||||
@@ -126,7 +140,12 @@ func setupJoystick(id int) bool {
|
|||||||
}
|
}
|
||||||
switch *jsTypeFlag {
|
switch *jsTypeFlag {
|
||||||
case "DualShock4":
|
case "DualShock4":
|
||||||
jsConfig = dualShock4Config
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
jsConfig = dualShock4ConfigWin
|
||||||
|
default:
|
||||||
|
jsConfig = dualShock4Config
|
||||||
|
}
|
||||||
case "HotasX":
|
case "HotasX":
|
||||||
jsConfig = tflightHotasXConfig
|
jsConfig = tflightHotasXConfig
|
||||||
default:
|
default:
|
||||||
@@ -153,6 +172,16 @@ func readJoystick(test bool) {
|
|||||||
sm.Ly = int16(jsState.AxisData[jsConfig.axes[axLeftY]]) * -1
|
sm.Ly = int16(jsState.AxisData[jsConfig.axes[axLeftY]]) * -1
|
||||||
sm.Rx = int16(jsState.AxisData[jsConfig.axes[axRightX]])
|
sm.Rx = int16(jsState.AxisData[jsConfig.axes[axRightX]])
|
||||||
sm.Ry = int16(jsState.AxisData[jsConfig.axes[axRightY]]) * -1
|
sm.Ry = int16(jsState.AxisData[jsConfig.axes[axRightY]]) * -1
|
||||||
|
switch {
|
||||||
|
case sm.Lx < deadZone:
|
||||||
|
sm.Lx = 0
|
||||||
|
case sm.Ly < deadZone:
|
||||||
|
sm.Ly = 0
|
||||||
|
case sm.Rx < deadZone:
|
||||||
|
sm.Rx = 0
|
||||||
|
case sm.Ry < deadZone:
|
||||||
|
sm.Ry = 0
|
||||||
|
}
|
||||||
|
|
||||||
if test {
|
if test {
|
||||||
log.Printf("JS: Lx: %d, Ly: %d, Rx: %d, Ry: %d\n", sm.Lx, sm.Ly, sm.Rx, sm.Ry)
|
log.Printf("JS: Lx: %d, Ly: %d, Rx: %d, Ry: %d\n", sm.Lx, sm.Ly, sm.Rx, sm.Ry)
|
||||||
|
|||||||
Reference in New Issue
Block a user