Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. static byte enter_config[]={0x01,0x43,0x00,0x01,0x00};
  2. static byte set_mode[]={0x01,0x44,0x00,0x01,0x03,0x00,0x00,0x00,0x00};
  3. static byte set_bytes_large[]={0x01,0x4F,0x00,0xFF,0xFF,0x03,0x00,0x00,0x00};
  4. static byte exit_config[]={0x01,0x43,0x00,0x00,0x5A,0x5A,0x5A,0x5A,0x5A};
  5. static byte enable_rumble[]={0x01,0x4D,0x00,0x00,0x01};
  6. static byte type_read[]={0x01,0x45,0x00,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A};
  7.  
  8. unsigned char PS2X::_gamepad_shiftinout (char byte) {
  9. unsigned char tmp = 0;
  10. for(unsigned char i=0;i<8;i++) {
  11. if(CHK(byte,i)) CMD_SET();
  12. else CMD_CLR();
  13.  
  14. CLK_CLR();
  15. delayMicroseconds(CTRL_CLK);
  16.  
  17. //if(DAT_CHK()) SET(tmp,i);
  18. if(DAT_CHK()) bitSet(tmp,i);
  19.  
  20. CLK_SET();
  21. #if CTRL_CLK_HIGH
  22. delayMicroseconds(CTRL_CLK_HIGH);
  23. #endif
  24. }
  25. CMD_SET();
  26. delayMicroseconds(CTRL_BYTE_DELAY);
  27. return tmp;
  28. }
  29.  
  30. void PS2X::sendCommandString(byte string[], byte len) {
  31. #ifdef PS2X_COM_DEBUG
  32. byte temp[len];
  33. ATT_CLR(); // low enable joystick
  34. delayMicroseconds(CTRL_BYTE_DELAY);
  35.  
  36. for (int y=0; y < len; y++)
  37. temp[y] = _gamepad_shiftinout(string[y]);
  38.  
  39. ATT_SET(); //high disable joystick
  40. delay(read_delay); //wait a few
  41.  
  42. Serial.println("OUT:IN Configure");
  43. for(int i=0; i<len; i++) {
  44. Serial.print(string[i], HEX);
  45. Serial.print(":");
  46. Serial.print(temp[i], HEX);
  47. Serial.print(" ");
  48. }
  49. Serial.println("");
  50. #else
  51. ATT_CLR(); // low enable joystick
  52. for (int y=0; y < len; y++)
  53. _gamepad_shiftinout(string[y]);
  54. ATT_SET(); //high disable joystick
  55. delay(read_delay); //wait a few
  56. #endif
  57. }
  58.  
  59. void PS2X::reconfig_gamepad(){
  60. sendCommandString(enter_config, sizeof(enter_config));
  61. sendCommandString(set_mode, sizeof(set_mode));
  62. if (en_Rumble)
  63. sendCommandString(enable_rumble, sizeof(enable_rumble));
  64. if (en_Pressures)
  65. sendCommandString(set_bytes_large, sizeof(set_bytes_large));
  66. sendCommandString(exit_config, sizeof(exit_config));
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement