BYTE waitRelease = 0xFF;
static BYTE checkButtonPressed(BYTE buttons, BYTE maskButton, BYTE maskHid)
{
if( buttons&maskButton )
{
/* button is not pressed */
waitRelease |= maskButton;
}
else
{
/* button is pressed */
if( waitRelease&maskButton )
{
waitRelease &= ~maskButton;
return maskHid;
}
}
return 0;
}
//button 1:up1 button 2:right1 button 3:down1 button 4:left1
//button //button 5:start button 6:select button 7:b_5 button 8:b_6
hid_report_in[5]=0x00; //initialized all button as 0
if (ConfBoutonNormal == TRUE)
{if(!b_1)hid_report_in[5] |=0x01; //if b_1 is pressed, send report to button and set bit0 as 1
else hid_report_in[5] &=0xFE; //if not, clear bit0 to 0
if(!b_2)hid_report_in[5] |=0x02; //if b_1 is pressed, set bit1 as 1
else hid_report_in[5] &=0xFD; //if not, clear bit1 to 0
if(!b_3)hid_report_in[5] |=0x04; //if b_1 is pressed, set bit2 as 1
else hid_report_in[5] &=0xFB; //if not, clear bit2 to 0
if(!b_4)hid_report_in[5] |=0x08; //if b_1 is pressed, set bit3 as 1
else hid_report_in[5] &=0xF7;} //if not, clear bit3 to 0
else
{if(!b_1)hid_report_in[5] |=0x08; //if b_1 is pressed, send report to button and set bit0 as 1
else hid_report_in[5] &=0xF7; //if not, clear bit0 to 0
if(!b_2)hid_report_in[5] |=0x01; //if b_1 is pressed, set bit1 as 1
else hid_report_in[5] &=0xFE; //if not, clear bit1 to 0
if(!b_3)hid_report_in[5] |=0x02; //if b_1 is pressed, set bit2 as 1
else hid_report_in[5] &=0xFD; //if not, clear bit2 to 0
if(!b_4)hid_report_in[5] |=0x04; //if b_1 is pressed, set bit3 as 1
else hid_report_in[5] &=0xFB;} //if not, clear bit3 to 0
if(!b_8)hid_report_in[5] |=0x10; //if select is pressed, set bit4 as 1
else hid_report_in[5] &=0xEF; //if not, clear bit4 to 0
if(!b_7)hid_report_in[5] |=0x20; //if start is pressed, set bit5 as 1
else hid_report_in[5] &=0xDF; //if not, clear bit5 to 0
if(!b_6)hid_report_in[5] |=0x40; //if b_6 is pressed, set bit6 as 1
else hid_report_in[5] &=0xBF; //if not, clear bit6 to 0
if(!b_5)hid_report_in[5] |=0x80; //if b_5 is pressed, set bit7 as 1
else hid_report_in[5] &=0x7F;
hid_report_in[5] = 0x00;
if( ConfBoutonNormal )
{
/* Ordre 1234 */
hid_report_in[5] |= checkButtonPressed(PORTB, 0x01, 0x01); //b1
hid_report_in[5] |= checkButtonPressed(PORTB, 0x02, 0x02); //b2
hid_report_in[5] |= checkButtonPressed(PORTB, 0x04, 0x04); //b3
hid_report_in[5] |= checkButtonPressed(PORTB, 0x08, 0x08); //b4
}
else
{
/* Ordre 4123 (NeoGeo) */
hid_report_in[5] |= checkButtonPressed(PORTB, 0x01, 0x08); //b1 reported as b4
hid_report_in[5] |= checkButtonPressed(PORTB, 0x02, 0x01); //b2 reported as b1
hid_report_in[5] |= checkButtonPressed(PORTB, 0x04, 0x02); //b3 reported as b2
hid_report_in[5] |= checkButtonPressed(PORTB, 0x08, 0x04); //b4 reported as b3
}
hid_report_in[5] |= checkButtonPressed(PORTB, 0x10, 0x80); //b5
hid_report_in[5] |= checkButtonPressed(PORTB, 0x20, 0x40); //b6
hid_report_in[5] |= checkButtonPressed(PORTB, 0x40, 0x20); //b7
hid_report_in[5] |= checkButtonPressed(PORTB, 0x80, 0x10); //b8
EDIT : L'ordre qui te parait chelou est pour inverser logiciellement les boutons :D
Pour passer de 1234 à 4123 pour une disposition Neogeo
hid_report_in[5]=0x00;
waitRelease = 0xFF
def checkButtonPressed(button, maskButton, maskHid):
global waitRelease
if button&maskButton:
waitRelease |= maskButton
else:
if waitRelease&maskButton:
waitRelease &= ~maskButton
return maskHid
return 0
print "cas 1=%s" % checkButtonPressed(0xFF, 0x01, 123)
print "cas 2=%s" % checkButtonPressed(0xFE, 0x01, 123)
print "cas 3=%s" % checkButtonPressed(0xFE, 0x01, 123)
print "cas 4=%s" % checkButtonPressed(0xFE, 0x01, 123)
print "cas 5=%s" % checkButtonPressed(0xFF, 0x01, 123)
while(1)
{
........
........
........
DelayMs(50) ;
LectureInput();
........
........
}