Je te mets les deux versions.
Celle qui fonctionne:
#include <PS2X_lib_teensy.h>
const byte numPads = 4;
const byte numButtons = 16;
const byte numAxes = 4;
PS2X listPads[numPads];
byte errorsPads[numPads] = {1,1,1,1};
boolean anyPadFound = false;
byte currentBtn;
byte currentAxe;
byte i,j,k,n;
void setup(){
Gamepad.useManualSend(true);
InitPads();
}
void loop(){
for (i=0 ; i<numPads ; i++) {
if (errorsPads[i] == 0) {
listPads[i].read_gamepad();
if (listPads[i].Button(PSB_SELECT) && listPads[i].Button(PSB_START) && listPads[i].Button(PSB_PAD_UP)) {
i--;
anyPadFound = false;
InitPads();
} else {
for (j=0 ; j<numAxes ; j++) {
switch (j) {
case 0: currentAxe = listPads[i].Analog(PSS_LX); break;
case 1: currentAxe = listPads[i].Analog(PSS_LY); break;
case 2: currentAxe = listPads[i].Analog(PSS_RX); break;
case 3: currentAxe = listPads[i].Analog(PSS_RY); break;
default: break;
}
Gamepad.axe(j,currentAxe);
}
for (k=0 ; k<numButtons ; k++) {
switch (k) {
case 0: currentBtn = listPads[i].Button(PSB_TRIANGLE); break;
case 1: currentBtn = listPads[i].Button(PSB_CIRCLE); break;
case 2: currentBtn = listPads[i].Button(PSB_CROSS); break;
case 3: currentBtn = listPads[i].Button(PSB_SQUARE); break;
case 4: currentBtn = listPads[i].Button(PSB_L1); break;
case 5: currentBtn = listPads[i].Button(PSB_R1); break;
case 6: currentBtn = listPads[i].Button(PSB_L2); break;
case 7: currentBtn = listPads[i].Button(PSB_R2); break;
case 8: currentBtn = listPads[i].Button(PSB_SELECT); break;
case 9: currentBtn = listPads[i].Button(PSB_START); break;
case 10: currentBtn = listPads[i].Button(PSB_L3); break;
case 11: currentBtn = listPads[i].Button(PSB_R3); break;
case 12: currentBtn = listPads[i].Button(PSB_PAD_UP); break;
case 13: currentBtn = listPads[i].Button(PSB_PAD_RIGHT); break;
case 14: currentBtn = listPads[i].Button(PSB_PAD_DOWN); break;
case 15: currentBtn = listPads[i].Button(PSB_PAD_LEFT); break;
default: break;
}
Gamepad.button(k,currentBtn);
}
Gamepad.num(i);
Gamepad.send_now();
}
}
}
delay(5);
}
void InitPads() {
while (!anyPadFound) {
for (n=0 ; n<numPads ; n++) {
switch (n) {
// clock, command, attention, data, pressures?, rumble?
case 0: errorsPads[n] = listPads[n].config_gamepad(21,19,20,18, false, false); break;
case 1: errorsPads[n] = listPads[n].config_gamepad(15,13,14,12, false, false); break;
case 2: errorsPads[n] = listPads[n].config_gamepad(10,8,9,7, false, false); break;
case 3: errorsPads[n] = listPads[n].config_gamepad(3,1,2,0, false, false); break;
default: break;
}
if (!anyPadFound && errorsPads[n] == 0) { anyPadFound = !anyPadFound; }
}
delay(500);
}
}
Et la version qui doit normalement retenir le dernier statut:
#include <PS2X_lib_teensy.h>
const byte numPads = 4;
const byte numButtons = 16;
const byte numAxes = 4;
PS2X listPads[numPads];
byte errorsPads[numPads] = {1,1,1,1};
boolean anyPadFound = false;
boolean reInit = false;
boolean btnsPad[numPads][numButtons]; //j'ai essayé plusieurs typages sans succès : int, byte
byte axesPad[numPads][numAxes]; //pareil
boolean btnsChanged = false;
boolean axesChanged = false;
byte currentBtn;
byte currentAxe;
byte i,j,k,n;
void setup(){
Gamepad.useManualSend(true);
InitPads();
}
void loop(){
for (i=0 ; i<numPads ; i++) {
if (errorsPads[i] == 0) {
listPads[i].read_gamepad();
if (listPads[i].Button(PSB_SELECT) && listPads[i].Button(PSB_START) && listPads[i].Button(PSB_PAD_UP)) {
i--;
reInit = btnsChanged = true;
} else {
for (j=0 ; j<numAxes ; j++) {
switch (j) {
case 0: currentAxe = listPads[i].Analog(PSS_LX); break;
case 1: currentAxe = listPads[i].Analog(PSS_LY); break;
case 2: currentAxe = listPads[i].Analog(PSS_RX); break;
case 3: currentAxe = listPads[i].Analog(PSS_RY); break;
default: break;
}
if (axesPad[i][j] != currentAxe) {
axesChanged = true;
axesPad[i][j] = currentAxe;
Gamepad.axe(j,axesPad[i][j]);
}
}
for (k=0 ; k<numButtons ; k++) {
switch (k) {
case 0: currentBtn = listPads[i].Button(PSB_TRIANGLE); break;
case 1: currentBtn = listPads[i].Button(PSB_CIRCLE); break;
case 2: currentBtn = listPads[i].Button(PSB_CROSS); break;
case 3: currentBtn = listPads[i].Button(PSB_SQUARE); break;
case 4: currentBtn = listPads[i].Button(PSB_L1); break;
case 5: currentBtn = listPads[i].Button(PSB_R1); break;
case 6: currentBtn = listPads[i].Button(PSB_L2); break;
case 7: currentBtn = listPads[i].Button(PSB_R2); break;
case 8: currentBtn = listPads[i].Button(PSB_SELECT); break;
case 9: currentBtn = listPads[i].Button(PSB_START); break;
case 10: currentBtn = listPads[i].Button(PSB_L3); break;
case 11: currentBtn = listPads[i].Button(PSB_R3); break;
case 12: currentBtn = listPads[i].Button(PSB_PAD_UP); break;
case 13: currentBtn = listPads[i].Button(PSB_PAD_RIGHT); break;
case 14: currentBtn = listPads[i].Button(PSB_PAD_DOWN); break;
case 15: currentBtn = listPads[i].Button(PSB_PAD_LEFT); break;
default: break;
}
if (btnsPad[i][k] != currentBtn) {
btnsChanged = true;
btnsPad[i][k] = currentBtn;
Gamepad.button(k,btnsPad[i][k]);
}
}
}
if (axesChanged || btnsChanged) {
if (reInit) {
reInit = anyPadFound = false;
InitPads();
} else {
Gamepad.num(i);
Gamepad.send_now();
}
axesChanged = btnsChanged = false;
}
}
}
delay(5);
}
void InitPads() {
while (!anyPadFound) {
for (n=0 ; n<numPads ; n++) {
switch (n) {
// clock, command, attention, data, pressures?, rumble?
case 0: errorsPads[n] = listPads[n].config_gamepad(21,19,20,18, false, false); break;
case 1: errorsPads[n] = listPads[n].config_gamepad(15,13,14,12, false, false); break;
case 2: errorsPads[n] = listPads[n].config_gamepad(10,8,9,7, false, false); break;
case 3: errorsPads[n] = listPads[n].config_gamepad(3,1,2,0, false, false); break;
default: break;
}
if (!anyPadFound && errorsPads[n] == 0) { anyPadFound = !anyPadFound; }
}
delay(500);
}
}
Edit: réorganisation du deuxième code pour qu'il ressemble plus au premier.