Skip to content

Commit cf173e9

Browse files
authored
targets/sg48key, sgh60: fix joystick center drift (#78)
ADCDevice.Get2 assigned the raw value to a 2048-wide zone by flooring, so zone 0 covered only [0, 2047] - entirely on the positive side of true center - and the dead zone extended one zone (2048 counts) further in the positive direction than in the negative one. The stick therefore registered movement much earlier in one direction, observed as a slight drift near center. Add half a zone before shifting so the assignment rounds to the nearest zone and the dead zone becomes symmetric. Both targets carry the same copy of ADCDevice; confirmed on sg48key hardware.
1 parent bf3b040 commit cf173e9

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

targets/sg48key/adcdevice.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func (a *ADCDevice) Get2() int16 {
6262

6363
ret := int(a.Value)
6464
ret += 0x4000
65+
// Round to the nearest 2048-wide zone instead of always flooring. Without
66+
// this, zone 0 (the dead zone's center bucket) covers only [0, 2047] -
67+
// entirely on the positive side of true center - so the negative side of
68+
// the dead zone is one zone (2048 counts) narrower than the positive
69+
// side, and the stick registers movement much more easily to one side
70+
// (observed as a slight drift) than the other.
71+
ret += 1024
6572
ret >>= 11
6673
ret -= 8
6774

targets/sgh60/adcdevice.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func (a *ADCDevice) Get2() int16 {
6262

6363
ret := int(a.Value)
6464
ret += 0x4000
65+
// Round to the nearest 2048-wide zone instead of always flooring. Without
66+
// this, zone 0 (the dead zone's center bucket) covers only [0, 2047] -
67+
// entirely on the positive side of true center - so the negative side of
68+
// the dead zone is one zone (2048 counts) narrower than the positive
69+
// side, and the stick registers movement much more easily to one side
70+
// (observed as a slight drift) than the other.
71+
ret += 1024
6572
ret >>= 11
6673
ret -= 8
6774

0 commit comments

Comments
 (0)