Skip to content

Commit 11ed4cd

Browse files
committed
Avoid deadzoning for neGcon/JogCon
1 parent 0a6fe05 commit 11ed4cd

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

examples/PsxControllerShieldDemo/PsxControllerShieldDemo.ino

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,26 +212,31 @@ boolean leftAnalogMoved (int8_t& x, int8_t& y) {
212212
byte lx, ly;
213213

214214
if (psx.getLeftAnalog (lx, ly)) { // [0 ... 255]
215-
int8_t deltaLX = lx - ANALOG_IDLE_VALUE; // [-128 ... 127]
216-
uint8_t deltaLXabs = abs (deltaLX);
217-
if (deltaLXabs > ANALOG_DEAD_ZONE) {
218-
x = deltaLX;
219-
if (x == -128)
220-
x = -127;
221-
ret = true;
222-
} else {
223-
x = 0;
224-
}
225-
226-
int8_t deltaLY = ly - ANALOG_IDLE_VALUE;
227-
uint8_t deltaLYabs = abs (deltaLY);
228-
if (deltaLYabs > ANALOG_DEAD_ZONE) {
229-
y = deltaLY;
230-
if (y == -128)
231-
y = -127;
232-
ret = true;
215+
if (psx.getProtocol () != PSPROTO_NEGCON && psx.getProtocol () != PSPROTO_JOGCON) {
216+
int8_t deltaLX = lx - ANALOG_IDLE_VALUE; // [-128 ... 127]
217+
uint8_t deltaLXabs = abs (deltaLX);
218+
if (deltaLXabs > ANALOG_DEAD_ZONE) {
219+
x = deltaLX;
220+
if (x == -128)
221+
x = -127;
222+
ret = true;
223+
} else {
224+
x = 0;
225+
}
226+
227+
int8_t deltaLY = ly - ANALOG_IDLE_VALUE;
228+
uint8_t deltaLYabs = abs (deltaLY);
229+
if (deltaLYabs > ANALOG_DEAD_ZONE) {
230+
y = deltaLY;
231+
if (y == -128)
232+
y = -127;
233+
ret = true;
234+
} else {
235+
y = 0;
236+
}
233237
} else {
234-
y = 0;
238+
// The neGcon and JogCon are more precise and work better without any dead zone
239+
x = lx, y = ly;
235240
}
236241
}
237242

0 commit comments

Comments
 (0)