From ed596583c78b3915ae57bddd9907c64161c5362c Mon Sep 17 00:00:00 2001 From: Lauszus Date: Sun, 2 May 2021 13:51:00 +0000 Subject: [PATCH] deploy: 45bf971f3bfc549ce8c23eeff26857562eef80a8 --- _b_t_d_8cpp_source.html | 2 +- _p_s3_b_t_8cpp_source.html | 1242 ++++++------- _p_s3_b_t_8h_source.html | 50 +- _p_s3_enums_8h.html | 35 + _p_s3_enums_8h_source.html | 11 +- _p_s3_u_s_b_8cpp_source.html | 552 +++--- _p_s3_u_s_b_8h_source.html | 46 +- _p_s4_b_t_8h_source.html | 4 +- _p_s4_parser_8cpp_source.html | 256 +-- _p_s4_parser_8h_source.html | 49 +- _p_s4_u_s_b_8h_source.html | 4 +- _p_s5_b_t_8h_source.html | 4 +- _p_s5_parser_8cpp_source.html | 272 +-- _p_s5_parser_8h_source.html | 51 +- _p_s5_u_s_b_8h_source.html | 4 +- _p_s_buzz_8cpp_source.html | 73 +- _p_s_buzz_8h_source.html | 20 +- _usb_8cpp_source.html | 2 +- _wii_8cpp_source.html | 389 +++-- _wii_8h_source.html | 180 +- _x_b_o_x_o_l_d_8cpp_source.html | 179 +- _x_b_o_x_o_l_d_8h_source.html | 61 +- _x_b_o_x_o_n_e_8cpp_source.html | 260 +-- _x_b_o_x_o_n_e_8h_source.html | 10 +- _x_b_o_x_o_n_e_s_b_t_8h_source.html | 4 +- _x_b_o_x_o_n_e_s_parser_8cpp_source.html | 341 ++-- _x_b_o_x_o_n_e_s_parser_8h_source.html | 44 +- _x_b_o_x_r_e_c_v_8cpp_source.html | 380 ++-- _x_b_o_x_r_e_c_v_8h_source.html | 22 +- _x_b_o_x_u_s_b_8cpp_source.html | 190 +- _x_b_o_x_u_s_b_8h_source.html | 16 +- class_p_s3_b_t.html | 50 +- class_p_s3_u_s_b.html | 46 +- class_p_s4_parser.html | 12 +- class_p_s5_parser.html | 12 +- class_p_s_buzz.html | 6 +- class_w_i_i.html | 16 +- class_x_b_o_x_o_l_d.html | 8 +- class_x_b_o_x_o_n_e.html | 8 +- class_x_b_o_x_o_n_e_s_parser.html | 14 +- class_x_b_o_x_r_e_c_v.html | 20 +- class_x_b_o_x_u_s_b.html | 14 +- controller_enums_8h.html | 295 ++-- controller_enums_8h_source.html | 353 ++-- functions_func_w.html | 2 +- functions_w.html | 2 +- globals_b.html | 3 + globals_eval.html | 18 +- globals_func.html | 10 +- globals_g.html | 10 +- globals_r.html | 4 +- globals_w.html | 6 +- globals_y.html | 6 +- hidboot_8h_source.html | 2 +- hidcomposite_8cpp_source.html | 2 +- hiduniversal_8cpp_source.html | 2 +- masstorage_8cpp_source.html | 2 +- printhex_8h_source.html | 2 +- search/all_10.js | 2034 +++++++++++----------- search/all_11.js | 2 +- search/all_12.js | 198 +-- search/all_13.js | 440 ++--- search/all_14.js | 134 +- search/all_15.js | 336 ++-- search/all_16.js | 52 +- search/all_17.js | 88 +- search/all_18.js | 276 +-- search/all_19.js | 8 +- search/all_1a.js | 8 +- search/all_2.js | 7 +- search/all_3.js | 266 +-- search/all_4.js | 130 +- search/all_5.js | 122 +- search/all_6.js | 118 +- search/all_7.js | 244 +-- search/all_8.js | 330 ++-- search/all_9.js | 62 +- search/all_a.js | 4 +- search/all_b.js | 60 +- search/all_c.js | 260 +-- search/all_d.js | 246 +-- search/all_e.js | 36 +- search/all_f.js | 56 +- search/classes_0.js | 14 +- search/classes_1.js | 12 +- search/classes_10.js | 18 +- search/classes_2.js | 26 +- search/classes_3.js | 2 +- search/classes_4.js | 4 +- search/classes_5.js | 20 +- search/classes_6.js | 2 +- search/classes_7.js | 6 +- search/classes_8.js | 2 +- search/classes_9.js | 18 +- search/classes_a.js | 44 +- search/classes_b.js | 10 +- search/classes_c.js | 8 +- search/classes_d.js | 6 +- search/classes_e.js | 32 +- search/classes_f.js | 2 +- search/defines_0.js | 8 +- search/defines_1.js | 72 +- search/defines_10.js | 86 +- search/defines_11.js | 66 +- search/defines_12.js | 236 +-- search/defines_13.js | 68 +- search/defines_14.js | 254 +-- search/defines_15.js | 18 +- search/defines_16.js | 22 +- search/defines_17.js | 212 +-- search/defines_2.js | 378 ++-- search/defines_3.js | 110 +- search/defines_4.js | 34 +- search/defines_5.js | 72 +- search/defines_6.js | 96 +- search/defines_7.js | 18 +- search/defines_8.js | 216 +-- search/defines_9.js | 8 +- search/defines_a.js | 4 +- search/defines_b.js | 40 +- search/defines_c.js | 150 +- search/defines_d.js | 136 +- search/defines_e.js | 22 +- search/defines_f.js | 10 +- search/enums_0.js | 8 +- search/enums_1.js | 4 +- search/enums_2.js | 2 +- search/enums_3.js | 2 +- search/enums_4.js | 2 +- search/enums_5.js | 4 +- search/enums_6.js | 4 +- search/enums_7.js | 2 +- search/enums_8.js | 4 +- search/enums_9.js | 2 +- search/enums_a.js | 2 +- search/enumvalues_0.js | 18 +- search/enumvalues_1.js | 16 +- search/enumvalues_10.js | 18 +- search/enumvalues_11.js | 6 +- search/enumvalues_12.js | 6 +- search/enumvalues_13.js | 8 +- search/enumvalues_14.js | 4 +- search/enumvalues_15.js | 4 +- search/enumvalues_16.js | 6 +- search/enumvalues_2.js | 14 +- search/enumvalues_3.js | 22 +- search/enumvalues_4.js | 6 +- search/enumvalues_5.js | 4 +- search/enumvalues_6.js | 14 +- search/enumvalues_7.js | 8 +- search/enumvalues_8.js | 10 +- search/enumvalues_9.js | 38 +- search/enumvalues_a.js | 32 +- search/enumvalues_b.js | 2 +- search/enumvalues_c.js | 8 +- search/enumvalues_d.js | 12 +- search/enumvalues_e.js | 30 +- search/enumvalues_f.js | 18 +- search/files_0.js | 14 +- search/files_1.js | 8 +- search/files_2.js | 20 +- search/files_3.js | 22 +- search/files_4.js | 20 +- search/files_5.js | 40 +- search/files_6.js | 2 +- search/files_7.js | 8 +- search/files_8.js | 26 +- search/files_9.js | 2 +- search/files_a.js | 6 +- search/files_b.js | 24 +- search/functions_0.js | 28 +- search/functions_1.js | 23 +- search/functions_10.js | 138 +- search/functions_11.js | 2 +- search/functions_12.js | 10 +- search/functions_13.js | 4 +- search/functions_14.js | 10 +- search/functions_15.js | 14 +- search/functions_16.js | 2 +- search/functions_2.js | 42 +- search/functions_3.js | 24 +- search/functions_4.js | 16 +- search/functions_5.js | 10 +- search/functions_6.js | 170 +- search/functions_7.js | 60 +- search/functions_8.js | 22 +- search/functions_9.js | 2 +- search/functions_a.js | 24 +- search/functions_b.js | 16 +- search/functions_c.js | 8 +- search/functions_d.js | 34 +- search/functions_e.js | 98 +- search/functions_f.js | 40 +- search/pages_0.js | 2 +- search/pages_1.js | 2 +- search/typedefs_0.js | 2 +- search/typedefs_1.js | 6 +- search/typedefs_2.js | 2 +- search/typedefs_3.js | 2 +- search/typedefs_4.js | 4 +- search/typedefs_5.js | 4 +- search/typedefs_6.js | 4 +- search/variables_0.js | 2 +- search/variables_1.js | 68 +- search/variables_10.js | 2 +- search/variables_11.js | 62 +- search/variables_12.js | 38 +- search/variables_13.js | 40 +- search/variables_14.js | 16 +- search/variables_15.js | 22 +- search/variables_16.js | 42 +- search/variables_17.js | 20 +- search/variables_18.js | 8 +- search/variables_2.js | 254 +-- search/variables_3.js | 64 +- search/variables_4.js | 46 +- search/variables_5.js | 28 +- search/variables_6.js | 6 +- search/variables_7.js | 44 +- search/variables_8.js | 14 +- search/variables_9.js | 34 +- search/variables_a.js | 8 +- search/variables_b.js | 48 +- search/variables_c.js | 38 +- search/variables_d.js | 4 +- search/variables_e.js | 8 +- search/variables_f.js | 1772 +++++++++---------- usbhub_8cpp_source.html | 2 +- xbox_enums_8h.html | 35 + xbox_enums_8h_source.html | 11 +- 230 files changed, 9093 insertions(+), 8757 deletions(-) diff --git a/_b_t_d_8cpp_source.html b/_b_t_d_8cpp_source.html index be538eb9..c153e945 100644 --- a/_b_t_d_8cpp_source.html +++ b/_b_t_d_8cpp_source.html @@ -1816,7 +1816,7 @@ $(function() {
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
Definition: Usb.cpp:209
const char * btdName
Definition: BTD.h:477
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1330
-
@ L
+
@ L
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:360
#define hci_clear_flag(flag)
Definition: BTD.h:81
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:96
diff --git a/_p_s3_b_t_8cpp_source.html b/_p_s3_b_t_8cpp_source.html index 87b7b17c..aaf2dfa7 100644 --- a/_p_s3_b_t_8cpp_source.html +++ b/_p_s3_b_t_8cpp_source.html @@ -115,598 +115,601 @@ $(function() {
47 }
48 
49 bool PS3BT::getButtonPress(ButtonEnum b) {
-
50  return (ButtonState & pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]));
-
51 }
-
52 
-
53 bool PS3BT::getButtonClick(ButtonEnum b) {
-
54  uint32_t button = pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]);
-
55  bool click = (ButtonClickState & button);
-
56  ButtonClickState &= ~button; // Clear "click" event
-
57  return click;
-
58 }
-
59 
-
60 uint8_t PS3BT::getAnalogButton(ButtonEnum a) {
-
61  return (uint8_t)(l2capinbuf[pgm_read_byte(&PS3_ANALOG_BUTTONS[(uint8_t)a])]);
-
62 }
-
63 
-
64 uint8_t PS3BT::getAnalogHat(AnalogHatEnum a) {
-
65  return (uint8_t)(l2capinbuf[(uint8_t)a + 15]);
-
66 }
-
67 
-
68 int16_t PS3BT::getSensor(SensorEnum a) {
-
69  if(PS3Connected) {
-
70  if(a == aX || a == aY || a == aZ || a == gZ)
-
71  return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
-
72  else
-
73  return 0;
-
74  } else if(PS3MoveConnected) {
-
75  if(a == mXmove || a == mYmove) // These are all 12-bits long
-
76  return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1]));
-
77  else if(a == mZmove || a == tempMove) // The tempearature is also 12 bits long
-
78  return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4));
-
79  else // aXmove, aYmove, aZmove, gXmove, gYmove and gZmove
-
80  return (l2capinbuf[(uint16_t)a] | (l2capinbuf[(uint16_t)a + 1] << 8));
-
81  } else
-
82  return 0;
-
83 }
-
84 
-
85 float PS3BT::getAngle(AngleEnum a) {
-
86  float accXval, accYval, accZval;
+
50  const int8_t index = getButtonIndexPS3(b); if (index < 0) return 0;
+
51  return (ButtonState & pgm_read_dword(&PS3_BUTTONS[index]));
+
52 }
+
53 
+
54 bool PS3BT::getButtonClick(ButtonEnum b) {
+
55  const int8_t index = getButtonIndexPS3(b); if (index < 0) return 0;
+
56  uint32_t button = pgm_read_dword(&PS3_BUTTONS[index]);
+
57  bool click = (ButtonClickState & button);
+
58  ButtonClickState &= ~button; // Clear "click" event
+
59  return click;
+
60 }
+
61 
+
62 uint8_t PS3BT::getAnalogButton(ButtonEnum a) {
+
63  const int8_t index = getButtonIndexPS3(a); if (index < 0) return 0;
+
64  return (uint8_t)(l2capinbuf[pgm_read_byte(&PS3_ANALOG_BUTTONS[index])]);
+
65 }
+
66 
+
67 uint8_t PS3BT::getAnalogHat(AnalogHatEnum a) {
+
68  return (uint8_t)(l2capinbuf[(uint8_t)a + 15]);
+
69 }
+
70 
+
71 int16_t PS3BT::getSensor(SensorEnum a) {
+
72  if(PS3Connected) {
+
73  if(a == aX || a == aY || a == aZ || a == gZ)
+
74  return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
+
75  else
+
76  return 0;
+
77  } else if(PS3MoveConnected) {
+
78  if(a == mXmove || a == mYmove) // These are all 12-bits long
+
79  return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1]));
+
80  else if(a == mZmove || a == tempMove) // The tempearature is also 12 bits long
+
81  return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4));
+
82  else // aXmove, aYmove, aZmove, gXmove, gYmove and gZmove
+
83  return (l2capinbuf[(uint16_t)a] | (l2capinbuf[(uint16_t)a + 1] << 8));
+
84  } else
+
85  return 0;
+
86 }
87 
-
88  if(PS3Connected) {
-
89  // Data for the Kionix KXPC4 used in the DualShock 3
-
90  const float zeroG = 511.5f; // 1.65/3.3*1023 (1.65V)
-
91  accXval = -((float)getSensor(aX) - zeroG);
-
92  accYval = -((float)getSensor(aY) - zeroG);
-
93  accZval = -((float)getSensor(aZ) - zeroG);
-
94  } else if(PS3MoveConnected) {
-
95  // It's a Kionix KXSC4 inside the Motion controller
-
96  const uint16_t zeroG = 0x8000;
-
97  accXval = -(int16_t)(getSensor(aXmove) - zeroG);
-
98  accYval = (int16_t)(getSensor(aYmove) - zeroG);
-
99  accZval = (int16_t)(getSensor(aZmove) - zeroG);
-
100  } else
-
101  return 0;
-
102 
-
103  // Convert to 360 degrees resolution
-
104  // atan2 outputs the value of -π to π (radians)
-
105  // We are then converting it to 0 to 2π and then to degrees
-
106  if(a == Pitch)
-
107  return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG;
-
108  else
-
109  return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG;
-
110 }
-
111 
-
112 float PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl
-
113  if(!PS3MoveConnected)
-
114  return 0;
-
115  int16_t value = getSensor(a);
-
116  if(a == mXmove || a == mYmove || a == mZmove) {
-
117  if(value > 2047)
-
118  value -= 0x1000;
-
119  return (float)value / 3.2f; // unit: muT = 10^(-6) Tesla
-
120  } else if(a == aXmove || a == aYmove || a == aZmove) {
-
121  if(value < 0)
-
122  value += 0x8000;
-
123  else
-
124  value -= 0x8000;
-
125  return (float)value / 442.0f; // unit: m/(s^2)
-
126  } else if(a == gXmove || a == gYmove || a == gZmove) {
-
127  if(value < 0)
-
128  value += 0x8000;
-
129  else
-
130  value -= 0x8000;
-
131  if(a == gXmove)
-
132  return (float)value / 11.6f; // unit: deg/s
-
133  else if(a == gYmove)
-
134  return (float)value / 11.2f; // unit: deg/s
-
135  else // gZmove
-
136  return (float)value / 9.6f; // unit: deg/s
-
137  } else
-
138  return 0;
-
139 }
-
140 
-
141 String PS3BT::getTemperature() {
-
142  if(PS3MoveConnected) {
-
143  int16_t input = getSensor(tempMove);
-
144 
-
145  String output = String(input / 100);
-
146  output += ".";
-
147  if(input % 100 < 10)
-
148  output += "0";
-
149  output += String(input % 100);
-
150 
-
151  return output;
-
152  } else
-
153  return "Error";
-
154 }
-
155 
-
156 bool PS3BT::getStatus(StatusEnum c) {
-
157  return (l2capinbuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff));
-
158 }
-
159 
-
160 void PS3BT::printStatusString() {
-
161  char statusOutput[102]; // Max string length plus null character
-
162  if(PS3Connected || PS3NavigationConnected) {
-
163  strcpy_P(statusOutput, PSTR("\r\nConnectionStatus: "));
-
164 
-
165  if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged"));
-
166  else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged"));
-
167  else strcat_P(statusOutput, PSTR("Error"));
-
168 
-
169  strcat_P(statusOutput, PSTR(" - PowerRating: "));
-
170 
-
171  if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging"));
-
172  else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
-
173  else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
-
174  else if(getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying"));
-
175  else if(getStatus(Low)) strcat_P(statusOutput, PSTR("Low"));
-
176  else if(getStatus(High)) strcat_P(statusOutput, PSTR("High"));
-
177  else if(getStatus(Full)) strcat_P(statusOutput, PSTR("Full"));
-
178  else strcat_P(statusOutput, PSTR("Error"));
-
179 
-
180  strcat_P(statusOutput, PSTR(" - WirelessStatus: "));
-
181 
-
182  if(getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on"));
-
183  else if(getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off"));
-
184  else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on"));
-
185  else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off"));
-
186  else strcat_P(statusOutput, PSTR("Error"));
-
187  } else if(PS3MoveConnected) {
-
188  strcpy_P(statusOutput, PSTR("\r\nPowerRating: "));
-
189 
-
190  if(getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging"));
-
191  else if(getStatus(MoveNotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
-
192  else if(getStatus(MoveShutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
-
193  else if(getStatus(MoveDying)) strcat_P(statusOutput, PSTR("Dying"));
-
194  else if(getStatus(MoveLow)) strcat_P(statusOutput, PSTR("Low"));
-
195  else if(getStatus(MoveHigh)) strcat_P(statusOutput, PSTR("High"));
-
196  else if(getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full"));
-
197  else strcat_P(statusOutput, PSTR("Error"));
-
198  } else
-
199  strcpy_P(statusOutput, PSTR("\r\nError"));
-
200 
-
201  USB_HOST_SERIAL.write(statusOutput);
-
202 }
+
88 float PS3BT::getAngle(AngleEnum a) {
+
89  float accXval, accYval, accZval;
+
90 
+
91  if(PS3Connected) {
+
92  // Data for the Kionix KXPC4 used in the DualShock 3
+
93  const float zeroG = 511.5f; // 1.65/3.3*1023 (1.65V)
+
94  accXval = -((float)getSensor(aX) - zeroG);
+
95  accYval = -((float)getSensor(aY) - zeroG);
+
96  accZval = -((float)getSensor(aZ) - zeroG);
+
97  } else if(PS3MoveConnected) {
+
98  // It's a Kionix KXSC4 inside the Motion controller
+
99  const uint16_t zeroG = 0x8000;
+
100  accXval = -(int16_t)(getSensor(aXmove) - zeroG);
+
101  accYval = (int16_t)(getSensor(aYmove) - zeroG);
+
102  accZval = (int16_t)(getSensor(aZmove) - zeroG);
+
103  } else
+
104  return 0;
+
105 
+
106  // Convert to 360 degrees resolution
+
107  // atan2 outputs the value of -π to π (radians)
+
108  // We are then converting it to 0 to 2π and then to degrees
+
109  if(a == Pitch)
+
110  return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG;
+
111  else
+
112  return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG;
+
113 }
+
114 
+
115 float PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl
+
116  if(!PS3MoveConnected)
+
117  return 0;
+
118  int16_t value = getSensor(a);
+
119  if(a == mXmove || a == mYmove || a == mZmove) {
+
120  if(value > 2047)
+
121  value -= 0x1000;
+
122  return (float)value / 3.2f; // unit: muT = 10^(-6) Tesla
+
123  } else if(a == aXmove || a == aYmove || a == aZmove) {
+
124  if(value < 0)
+
125  value += 0x8000;
+
126  else
+
127  value -= 0x8000;
+
128  return (float)value / 442.0f; // unit: m/(s^2)
+
129  } else if(a == gXmove || a == gYmove || a == gZmove) {
+
130  if(value < 0)
+
131  value += 0x8000;
+
132  else
+
133  value -= 0x8000;
+
134  if(a == gXmove)
+
135  return (float)value / 11.6f; // unit: deg/s
+
136  else if(a == gYmove)
+
137  return (float)value / 11.2f; // unit: deg/s
+
138  else // gZmove
+
139  return (float)value / 9.6f; // unit: deg/s
+
140  } else
+
141  return 0;
+
142 }
+
143 
+
144 String PS3BT::getTemperature() {
+
145  if(PS3MoveConnected) {
+
146  int16_t input = getSensor(tempMove);
+
147 
+
148  String output = String(input / 100);
+
149  output += ".";
+
150  if(input % 100 < 10)
+
151  output += "0";
+
152  output += String(input % 100);
+
153 
+
154  return output;
+
155  } else
+
156  return "Error";
+
157 }
+
158 
+
159 bool PS3BT::getStatus(StatusEnum c) {
+
160  return (l2capinbuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff));
+
161 }
+
162 
+
163 void PS3BT::printStatusString() {
+
164  char statusOutput[102]; // Max string length plus null character
+
165  if(PS3Connected || PS3NavigationConnected) {
+
166  strcpy_P(statusOutput, PSTR("\r\nConnectionStatus: "));
+
167 
+
168  if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged"));
+
169  else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged"));
+
170  else strcat_P(statusOutput, PSTR("Error"));
+
171 
+
172  strcat_P(statusOutput, PSTR(" - PowerRating: "));
+
173 
+
174  if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging"));
+
175  else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
+
176  else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
+
177  else if(getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying"));
+
178  else if(getStatus(Low)) strcat_P(statusOutput, PSTR("Low"));
+
179  else if(getStatus(High)) strcat_P(statusOutput, PSTR("High"));
+
180  else if(getStatus(Full)) strcat_P(statusOutput, PSTR("Full"));
+
181  else strcat_P(statusOutput, PSTR("Error"));
+
182 
+
183  strcat_P(statusOutput, PSTR(" - WirelessStatus: "));
+
184 
+
185  if(getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on"));
+
186  else if(getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off"));
+
187  else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on"));
+
188  else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off"));
+
189  else strcat_P(statusOutput, PSTR("Error"));
+
190  } else if(PS3MoveConnected) {
+
191  strcpy_P(statusOutput, PSTR("\r\nPowerRating: "));
+
192 
+
193  if(getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging"));
+
194  else if(getStatus(MoveNotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
+
195  else if(getStatus(MoveShutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
+
196  else if(getStatus(MoveDying)) strcat_P(statusOutput, PSTR("Dying"));
+
197  else if(getStatus(MoveLow)) strcat_P(statusOutput, PSTR("Low"));
+
198  else if(getStatus(MoveHigh)) strcat_P(statusOutput, PSTR("High"));
+
199  else if(getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full"));
+
200  else strcat_P(statusOutput, PSTR("Error"));
+
201  } else
+
202  strcpy_P(statusOutput, PSTR("\r\nError"));
203 
-
204 void PS3BT::Reset() {
-
205  PS3Connected = false;
-
206  PS3MoveConnected = false;
-
207  PS3NavigationConnected = false;
-
208  activeConnection = false;
-
209  l2cap_event_flag = 0; // Reset flags
-
210  l2cap_state = L2CAP_WAIT;
-
211 
-
212  // Needed for PS3 Dualshock Controller commands to work via Bluetooth
-
213  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
-
214  HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
-
215 }
-
216 
-
217 void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
-
218  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
-
219  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
-
220  Reset();
-
221  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
-
222 }
-
223 
-
224 void PS3BT::ACLData(uint8_t* ACLData) {
-
225  if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected && !activeConnection && !pBtd->connectToWii && !pBtd->incomingWii && !pBtd->pairWithWii) {
-
226  if(ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
227  if((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) {
-
228  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
-
229  activeConnection = true;
-
230  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
231  l2cap_state = L2CAP_WAIT;
-
232  remote_name_first = pBtd->remote_name[0]; // Store the first letter in remote name for the connection
-
233 #ifdef DEBUG_USB_HOST
-
234  if(pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle
-
235  Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
-
236  Notify(pBtd->hci_version, 0x80);
-
237  Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80);
-
238  }
-
239 #endif
-
240  }
-
241  }
-
242  }
-
243 
-
244  if(checkHciHandle(ACLData, hci_handle)) { // acl_handle_ok
-
245  memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
-
246  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
-
247  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
-
248 #ifdef DEBUG_USB_HOST
-
249  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
-
250  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
251  Notify(PSTR(" "), 0x80);
-
252  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
253  Notify(PSTR(" Data: "), 0x80);
-
254  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
-
255  Notify(PSTR(" "), 0x80);
-
256  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
-
257  Notify(PSTR(" "), 0x80);
-
258  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
259  Notify(PSTR(" "), 0x80);
-
260  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
261 #endif
-
262  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
263 #ifdef EXTRADEBUG
-
264  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
-
265  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
266  Notify(PSTR(" "), 0x80);
-
267  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
268  Notify(PSTR(" SCID: "), 0x80);
-
269  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
270  Notify(PSTR(" "), 0x80);
-
271  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
272  Notify(PSTR(" Identifier: "), 0x80);
-
273  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
274 #endif
-
275  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
-
276  identifier = l2capinbuf[9];
-
277  control_scid[0] = l2capinbuf[14];
-
278  control_scid[1] = l2capinbuf[15];
-
279  l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
-
280  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
-
281  identifier = l2capinbuf[9];
-
282  interrupt_scid[0] = l2capinbuf[14];
-
283  interrupt_scid[1] = l2capinbuf[15];
-
284  l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
-
285  }
-
286  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
-
287  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
-
288  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
289  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
-
290  l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
-
291  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
292  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
-
293  l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
-
294  }
-
295  }
-
296  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
-
297  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
298  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
-
299  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
-
300  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
301  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
-
302  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
-
303  }
-
304  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
-
305  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
306 #ifdef DEBUG_USB_HOST
-
307  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
-
308 #endif
-
309  identifier = l2capinbuf[9];
-
310  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
-
311  Reset();
-
312  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
313 #ifdef DEBUG_USB_HOST
-
314  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
-
315 #endif
-
316  identifier = l2capinbuf[9];
-
317  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
-
318  Reset();
-
319  }
-
320  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
-
321  if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
-
322  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
-
323  identifier = l2capinbuf[9];
-
324  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
-
325  } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
-
326  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
-
327  identifier = l2capinbuf[9];
-
328  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
-
329  }
-
330  }
-
331 #ifdef EXTRADEBUG
-
332  else {
-
333  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
-
334  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
335  }
-
336 #endif
-
337  } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
-
338  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
-
339  if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
-
340  /* Read Report */
-
341  if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
-
342  lastMessageTime = (uint32_t)millis(); // Store the last message time
-
343 
-
344  if(PS3Connected || PS3NavigationConnected)
-
345  ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
-
346  else if(PS3MoveConnected)
-
347  ButtonState = (uint32_t)(l2capinbuf[10] | ((uint16_t)l2capinbuf[11] << 8) | ((uint32_t)l2capinbuf[12] << 16));
-
348 
-
349  //Notify(PSTR("\r\nButtonState", 0x80);
-
350  //PrintHex<uint32_t>(ButtonState, 0x80);
+
204  USB_HOST_SERIAL.write(statusOutput);
+
205 }
+
206 
+
207 void PS3BT::Reset() {
+
208  PS3Connected = false;
+
209  PS3MoveConnected = false;
+
210  PS3NavigationConnected = false;
+
211  activeConnection = false;
+
212  l2cap_event_flag = 0; // Reset flags
+
213  l2cap_state = L2CAP_WAIT;
+
214 
+
215  // Needed for PS3 Dualshock Controller commands to work via Bluetooth
+
216  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
+
217  HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
+
218 }
+
219 
+
220 void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
+
221  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
+
222  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
+
223  Reset();
+
224  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
+
225 }
+
226 
+
227 void PS3BT::ACLData(uint8_t* ACLData) {
+
228  if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected && !activeConnection && !pBtd->connectToWii && !pBtd->incomingWii && !pBtd->pairWithWii) {
+
229  if(ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
230  if((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) {
+
231  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
+
232  activeConnection = true;
+
233  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
+
234  l2cap_state = L2CAP_WAIT;
+
235  remote_name_first = pBtd->remote_name[0]; // Store the first letter in remote name for the connection
+
236 #ifdef DEBUG_USB_HOST
+
237  if(pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle
+
238  Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
+
239  Notify(pBtd->hci_version, 0x80);
+
240  Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80);
+
241  }
+
242 #endif
+
243  }
+
244  }
+
245  }
+
246 
+
247  if(checkHciHandle(ACLData, hci_handle)) { // acl_handle_ok
+
248  memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
+
249  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
+
250  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
+
251 #ifdef DEBUG_USB_HOST
+
252  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
+
253  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
254  Notify(PSTR(" "), 0x80);
+
255  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
256  Notify(PSTR(" Data: "), 0x80);
+
257  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
+
258  Notify(PSTR(" "), 0x80);
+
259  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
+
260  Notify(PSTR(" "), 0x80);
+
261  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
262  Notify(PSTR(" "), 0x80);
+
263  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
264 #endif
+
265  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
266 #ifdef EXTRADEBUG
+
267  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
+
268  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
269  Notify(PSTR(" "), 0x80);
+
270  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
271  Notify(PSTR(" SCID: "), 0x80);
+
272  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
273  Notify(PSTR(" "), 0x80);
+
274  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
275  Notify(PSTR(" Identifier: "), 0x80);
+
276  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
277 #endif
+
278  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
279  identifier = l2capinbuf[9];
+
280  control_scid[0] = l2capinbuf[14];
+
281  control_scid[1] = l2capinbuf[15];
+
282  l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
+
283  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
+
284  identifier = l2capinbuf[9];
+
285  interrupt_scid[0] = l2capinbuf[14];
+
286  interrupt_scid[1] = l2capinbuf[15];
+
287  l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
+
288  }
+
289  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
+
290  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
+
291  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
292  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
+
293  l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
+
294  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
295  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
+
296  l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
+
297  }
+
298  }
+
299  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
+
300  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
301  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
+
302  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
+
303  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
304  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
+
305  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
+
306  }
+
307  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
+
308  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
309 #ifdef DEBUG_USB_HOST
+
310  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
+
311 #endif
+
312  identifier = l2capinbuf[9];
+
313  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
+
314  Reset();
+
315  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
316 #ifdef DEBUG_USB_HOST
+
317  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
+
318 #endif
+
319  identifier = l2capinbuf[9];
+
320  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
+
321  Reset();
+
322  }
+
323  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
+
324  if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
+
325  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
+
326  identifier = l2capinbuf[9];
+
327  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
+
328  } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
+
329  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
+
330  identifier = l2capinbuf[9];
+
331  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
+
332  }
+
333  }
+
334 #ifdef EXTRADEBUG
+
335  else {
+
336  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
+
337  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
338  }
+
339 #endif
+
340  } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
+
341  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
+
342  if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
+
343  /* Read Report */
+
344  if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
+
345  lastMessageTime = (uint32_t)millis(); // Store the last message time
+
346 
+
347  if(PS3Connected || PS3NavigationConnected)
+
348  ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
+
349  else if(PS3MoveConnected)
+
350  ButtonState = (uint32_t)(l2capinbuf[10] | ((uint16_t)l2capinbuf[11] << 8) | ((uint32_t)l2capinbuf[12] << 16));
351 
-
352  if(ButtonState != OldButtonState) {
-
353  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
-
354  OldButtonState = ButtonState;
-
355  }
-
356 
-
357 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
-
358  for(uint8_t i = 10; i < 58; i++) {
-
359  D_PrintHex<uint8_t > (l2capinbuf[i], 0x80);
-
360  Notify(PSTR(" "), 0x80);
-
361  }
-
362  Notify(PSTR("\r\n"), 0x80);
-
363 #endif
-
364  }
-
365  }
-
366  }
-
367  L2CAP_task();
-
368  }
-
369 }
-
370 
-
371 void PS3BT::L2CAP_task() {
-
372  switch(l2cap_state) {
-
373  case L2CAP_WAIT:
-
374  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)) {
-
375 #ifdef DEBUG_USB_HOST
-
376  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
-
377 #endif
-
378  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
-
379  delay(1);
-
380  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
-
381  identifier++;
+
352  //Notify(PSTR("\r\nButtonState", 0x80);
+
353  //PrintHex<uint32_t>(ButtonState, 0x80);
+
354 
+
355  if(ButtonState != OldButtonState) {
+
356  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
+
357  OldButtonState = ButtonState;
+
358  }
+
359 
+
360 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
+
361  for(uint8_t i = 10; i < 58; i++) {
+
362  D_PrintHex<uint8_t > (l2capinbuf[i], 0x80);
+
363  Notify(PSTR(" "), 0x80);
+
364  }
+
365  Notify(PSTR("\r\n"), 0x80);
+
366 #endif
+
367  }
+
368  }
+
369  }
+
370  L2CAP_task();
+
371  }
+
372 }
+
373 
+
374 void PS3BT::L2CAP_task() {
+
375  switch(l2cap_state) {
+
376  case L2CAP_WAIT:
+
377  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)) {
+
378 #ifdef DEBUG_USB_HOST
+
379  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
+
380 #endif
+
381  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
382  delay(1);
-
383  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
384  l2cap_state = L2CAP_CONTROL_SUCCESS;
-
385  }
-
386  break;
-
387 
-
388  case L2CAP_CONTROL_SUCCESS:
-
389  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
-
390 #ifdef DEBUG_USB_HOST
-
391  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
-
392 #endif
-
393  l2cap_state = L2CAP_INTERRUPT_SETUP;
-
394  }
-
395  break;
-
396 
-
397  case L2CAP_INTERRUPT_SETUP:
-
398  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
-
399 #ifdef DEBUG_USB_HOST
-
400  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
-
401 #endif
-
402  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
-
403  delay(1);
-
404  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
-
405  identifier++;
+
383  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
+
384  identifier++;
+
385  delay(1);
+
386  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
+
387  l2cap_state = L2CAP_CONTROL_SUCCESS;
+
388  }
+
389  break;
+
390 
+
391  case L2CAP_CONTROL_SUCCESS:
+
392  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
393 #ifdef DEBUG_USB_HOST
+
394  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
+
395 #endif
+
396  l2cap_state = L2CAP_INTERRUPT_SETUP;
+
397  }
+
398  break;
+
399 
+
400  case L2CAP_INTERRUPT_SETUP:
+
401  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
+
402 #ifdef DEBUG_USB_HOST
+
403  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
+
404 #endif
+
405  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
406  delay(1);
-
407  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
408 
-
409  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
-
410  }
-
411  break;
-
412 
-
413  case L2CAP_INTERRUPT_CONFIG_REQUEST:
-
414  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
-
415 #ifdef DEBUG_USB_HOST
-
416  Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80);
-
417 #endif
-
418  if(remote_name_first == 'M') { // First letter in Motion Controller ('M')
-
419  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
-
420  l2cap_state = TURN_ON_LED;
-
421  } else
-
422  l2cap_state = PS3_ENABLE_SIXAXIS;
-
423  timer = (uint32_t)millis();
-
424  }
-
425  break;
-
426 
-
427  /* These states are handled in Run() */
-
428 
-
429  case L2CAP_INTERRUPT_DISCONNECT:
-
430  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)) {
-
431 #ifdef DEBUG_USB_HOST
-
432  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
-
433 #endif
-
434  identifier++;
-
435  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
-
436  l2cap_state = L2CAP_CONTROL_DISCONNECT;
-
437  }
-
438  break;
-
439 
-
440  case L2CAP_CONTROL_DISCONNECT:
-
441  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
-
442 #ifdef DEBUG_USB_HOST
-
443  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
-
444 #endif
-
445  pBtd->hci_disconnect(hci_handle);
-
446  hci_handle = -1; // Reset handle
-
447  l2cap_event_flag = 0; // Reset flags
-
448  l2cap_state = L2CAP_WAIT;
-
449  }
-
450  break;
-
451  }
-
452 }
-
453 
-
454 void PS3BT::Run() {
-
455  switch(l2cap_state) {
-
456  case PS3_ENABLE_SIXAXIS:
-
457  if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command
-
458  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
-
459  for(uint8_t i = 15; i < 19; i++)
-
460  l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
-
461  enable_sixaxis();
-
462  l2cap_state = TURN_ON_LED;
-
463  timer = (uint32_t)millis();
-
464  }
-
465  break;
-
466 
-
467  case TURN_ON_LED:
-
468  if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command
-
469  if(remote_name_first == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
-
470 #ifdef DEBUG_USB_HOST
-
471  Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
-
472 #endif
-
473  PS3Connected = true;
-
474  } else if(remote_name_first == 'N') { // First letter in Navigation Controller ('N')
-
475 #ifdef DEBUG_USB_HOST
-
476  Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
-
477 #endif
-
478  PS3NavigationConnected = true;
-
479  } else if(remote_name_first == 'M') { // First letter in Motion Controller ('M')
-
480  timer = (uint32_t)millis();
-
481 #ifdef DEBUG_USB_HOST
-
482  Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
-
483 #endif
-
484  PS3MoveConnected = true;
-
485  }
-
486  ButtonState = 0; // Clear all values
-
487  OldButtonState = 0;
-
488  ButtonClickState = 0;
-
489 
-
490  onInit(); // Turn on the LED on the controller
-
491  l2cap_state = L2CAP_DONE;
-
492  }
-
493  break;
-
494 
-
495  case L2CAP_DONE:
-
496  if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at approximately every 5th second for it to stay on
-
497  if((int32_t)((uint32_t)millis() - timer) > 4000) { // Send at least every 4th second
-
498  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
-
499  timer = (uint32_t)millis();
-
500  }
-
501  }
-
502  break;
-
503  }
-
504 }
-
505 
-
506 /************************************************************/
-
507 /* HID Commands */
-
508 /************************************************************/
-
509 
-
510 // Playstation Sixaxis Dualshock and Navigation Controller commands
-
511 
-
512 void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) {
-
513  if((int32_t)((uint32_t)millis() - timerHID) <= 150) // Check if is has been more than 150ms since last command
-
514  delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands
-
515  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel
-
516  timerHID = (uint32_t)millis();
-
517 }
-
518 
-
519 void PS3BT::setAllOff() {
-
520  HIDBuffer[3] = 0x00; // Rumble bytes
-
521  HIDBuffer[4] = 0x00;
-
522  HIDBuffer[5] = 0x00;
-
523  HIDBuffer[6] = 0x00;
-
524 
-
525  HIDBuffer[11] = 0x00; // LED byte
-
526 
-
527  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
528 }
+
407  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
+
408  identifier++;
+
409  delay(1);
+
410  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
411 
+
412  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
+
413  }
+
414  break;
+
415 
+
416  case L2CAP_INTERRUPT_CONFIG_REQUEST:
+
417  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
+
418 #ifdef DEBUG_USB_HOST
+
419  Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80);
+
420 #endif
+
421  if(remote_name_first == 'M') { // First letter in Motion Controller ('M')
+
422  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
+
423  l2cap_state = TURN_ON_LED;
+
424  } else
+
425  l2cap_state = PS3_ENABLE_SIXAXIS;
+
426  timer = (uint32_t)millis();
+
427  }
+
428  break;
+
429 
+
430  /* These states are handled in Run() */
+
431 
+
432  case L2CAP_INTERRUPT_DISCONNECT:
+
433  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)) {
+
434 #ifdef DEBUG_USB_HOST
+
435  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
+
436 #endif
+
437  identifier++;
+
438  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
+
439  l2cap_state = L2CAP_CONTROL_DISCONNECT;
+
440  }
+
441  break;
+
442 
+
443  case L2CAP_CONTROL_DISCONNECT:
+
444  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
+
445 #ifdef DEBUG_USB_HOST
+
446  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
+
447 #endif
+
448  pBtd->hci_disconnect(hci_handle);
+
449  hci_handle = -1; // Reset handle
+
450  l2cap_event_flag = 0; // Reset flags
+
451  l2cap_state = L2CAP_WAIT;
+
452  }
+
453  break;
+
454  }
+
455 }
+
456 
+
457 void PS3BT::Run() {
+
458  switch(l2cap_state) {
+
459  case PS3_ENABLE_SIXAXIS:
+
460  if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command
+
461  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
+
462  for(uint8_t i = 15; i < 19; i++)
+
463  l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
+
464  enable_sixaxis();
+
465  l2cap_state = TURN_ON_LED;
+
466  timer = (uint32_t)millis();
+
467  }
+
468  break;
+
469 
+
470  case TURN_ON_LED:
+
471  if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command
+
472  if(remote_name_first == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
+
473 #ifdef DEBUG_USB_HOST
+
474  Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
+
475 #endif
+
476  PS3Connected = true;
+
477  } else if(remote_name_first == 'N') { // First letter in Navigation Controller ('N')
+
478 #ifdef DEBUG_USB_HOST
+
479  Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
+
480 #endif
+
481  PS3NavigationConnected = true;
+
482  } else if(remote_name_first == 'M') { // First letter in Motion Controller ('M')
+
483  timer = (uint32_t)millis();
+
484 #ifdef DEBUG_USB_HOST
+
485  Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
+
486 #endif
+
487  PS3MoveConnected = true;
+
488  }
+
489  ButtonState = 0; // Clear all values
+
490  OldButtonState = 0;
+
491  ButtonClickState = 0;
+
492 
+
493  onInit(); // Turn on the LED on the controller
+
494  l2cap_state = L2CAP_DONE;
+
495  }
+
496  break;
+
497 
+
498  case L2CAP_DONE:
+
499  if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at approximately every 5th second for it to stay on
+
500  if((int32_t)((uint32_t)millis() - timer) > 4000) { // Send at least every 4th second
+
501  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
+
502  timer = (uint32_t)millis();
+
503  }
+
504  }
+
505  break;
+
506  }
+
507 }
+
508 
+
509 /************************************************************/
+
510 /* HID Commands */
+
511 /************************************************************/
+
512 
+
513 // Playstation Sixaxis Dualshock and Navigation Controller commands
+
514 
+
515 void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) {
+
516  if((int32_t)((uint32_t)millis() - timerHID) <= 150) // Check if is has been more than 150ms since last command
+
517  delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands
+
518  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel
+
519  timerHID = (uint32_t)millis();
+
520 }
+
521 
+
522 void PS3BT::setAllOff() {
+
523  HIDBuffer[3] = 0x00; // Rumble bytes
+
524  HIDBuffer[4] = 0x00;
+
525  HIDBuffer[5] = 0x00;
+
526  HIDBuffer[6] = 0x00;
+
527 
+
528  HIDBuffer[11] = 0x00; // LED byte
529 
-
530 void PS3BT::setRumbleOff() {
-
531  uint8_t rumbleBuf[HID_BUFFERSIZE];
-
532  memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE);
-
533  rumbleBuf[3] = 0x00;
-
534  rumbleBuf[4] = 0x00;
-
535  rumbleBuf[5] = 0x00;
-
536  rumbleBuf[6] = 0x00;
-
537  HID_Command(rumbleBuf, HID_BUFFERSIZE);
-
538 }
-
539 
-
540 void PS3BT::setRumbleOn(RumbleEnum mode) {
-
541  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
-
542  if(mode == RumbleHigh) {
-
543  power[0] = 0x00;
-
544  power[1] = 0xff;
-
545  }
-
546  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
-
547 }
-
548 
-
549 void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
-
550  uint8_t rumbleBuf[HID_BUFFERSIZE];
-
551  memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE);
-
552  rumbleBuf[3] = rightDuration;
-
553  rumbleBuf[4] = rightPower;
-
554  rumbleBuf[5] = leftDuration;
-
555  rumbleBuf[6] = leftPower;
-
556  HID_Command(rumbleBuf, HID_BUFFERSIZE);
-
557 }
-
558 
-
559 void PS3BT::setLedRaw(uint8_t value) {
-
560  HIDBuffer[11] = value << 1;
-
561  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
562 }
-
563 
-
564 void PS3BT::setLedOff(LEDEnum a) {
-
565  HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1));
-
566  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
567 }
-
568 
-
569 void PS3BT::setLedOn(LEDEnum a) {
-
570  if(a == OFF)
-
571  setLedRaw(0);
-
572  else {
-
573  HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
-
574  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
575  }
-
576 }
-
577 
-
578 void PS3BT::setLedToggle(LEDEnum a) {
-
579  HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
-
580  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
581 }
-
582 
-
583 void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
-
584  uint8_t cmd_buf[6];
-
585  cmd_buf[0] = 0x53; // HID BT Set_report (0x50) | Report Type (Feature 0x03)
-
586  cmd_buf[1] = 0xF4; // Report ID
-
587  cmd_buf[2] = 0x42; // Special PS3 Controller enable commands
-
588  cmd_buf[3] = 0x03;
-
589  cmd_buf[4] = 0x00;
-
590  cmd_buf[5] = 0x00;
-
591 
-
592  HID_Command(cmd_buf, 6);
-
593 }
+
530  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
531 }
+
532 
+
533 void PS3BT::setRumbleOff() {
+
534  uint8_t rumbleBuf[HID_BUFFERSIZE];
+
535  memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE);
+
536  rumbleBuf[3] = 0x00;
+
537  rumbleBuf[4] = 0x00;
+
538  rumbleBuf[5] = 0x00;
+
539  rumbleBuf[6] = 0x00;
+
540  HID_Command(rumbleBuf, HID_BUFFERSIZE);
+
541 }
+
542 
+
543 void PS3BT::setRumbleOn(RumbleEnum mode) {
+
544  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
+
545  if(mode == RumbleHigh) {
+
546  power[0] = 0x00;
+
547  power[1] = 0xff;
+
548  }
+
549  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
+
550 }
+
551 
+
552 void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
+
553  uint8_t rumbleBuf[HID_BUFFERSIZE];
+
554  memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE);
+
555  rumbleBuf[3] = rightDuration;
+
556  rumbleBuf[4] = rightPower;
+
557  rumbleBuf[5] = leftDuration;
+
558  rumbleBuf[6] = leftPower;
+
559  HID_Command(rumbleBuf, HID_BUFFERSIZE);
+
560 }
+
561 
+
562 void PS3BT::setLedRaw(uint8_t value) {
+
563  HIDBuffer[11] = value << 1;
+
564  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
565 }
+
566 
+
567 void PS3BT::setLedOff(LEDEnum a) {
+
568  HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1));
+
569  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
570 }
+
571 
+
572 void PS3BT::setLedOn(LEDEnum a) {
+
573  if(a == OFF)
+
574  setLedRaw(0);
+
575  else {
+
576  HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
577  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
578  }
+
579 }
+
580 
+
581 void PS3BT::setLedToggle(LEDEnum a) {
+
582  HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
583  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
584 }
+
585 
+
586 void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
+
587  uint8_t cmd_buf[6];
+
588  cmd_buf[0] = 0x53; // HID BT Set_report (0x50) | Report Type (Feature 0x03)
+
589  cmd_buf[1] = 0xF4; // Report ID
+
590  cmd_buf[2] = 0x42; // Special PS3 Controller enable commands
+
591  cmd_buf[3] = 0x03;
+
592  cmd_buf[4] = 0x00;
+
593  cmd_buf[5] = 0x00;
594 
-
595 // Playstation Move Controller commands
-
596 
-
597 void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) {
-
598  if((int32_t)((uint32_t)millis() - timerHID) <= 150)// Check if is has been less than 150ms since last command
-
599  delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands
-
600  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel
-
601  timerHID = (uint32_t)millis();
-
602 }
-
603 
-
604 void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
-
605  // Set the Bulb's values into the write buffer
-
606  HIDMoveBuffer[3] = r;
-
607  HIDMoveBuffer[4] = g;
-
608  HIDMoveBuffer[5] = b;
-
609 
-
610  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
-
611 }
+
595  HID_Command(cmd_buf, 6);
+
596 }
+
597 
+
598 // Playstation Move Controller commands
+
599 
+
600 void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) {
+
601  if((int32_t)((uint32_t)millis() - timerHID) <= 150)// Check if is has been less than 150ms since last command
+
602  delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands
+
603  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel
+
604  timerHID = (uint32_t)millis();
+
605 }
+
606 
+
607 void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
+
608  // Set the Bulb's values into the write buffer
+
609  HIDMoveBuffer[3] = r;
+
610  HIDMoveBuffer[4] = g;
+
611  HIDMoveBuffer[5] = b;
612 
-
613 void PS3BT::moveSetBulb(ColorsEnum color) { // Use this to set the Color using the predefined colors in enum
-
614  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
-
615 }
-
616 
-
617 void PS3BT::moveSetRumble(uint8_t rumble) {
-
618 #ifdef DEBUG_USB_HOST
-
619  if(rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
-
620  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
-
621 #endif
-
622  // Set the rumble value into the write buffer
-
623  HIDMoveBuffer[7] = rumble;
-
624 
-
625  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
-
626 }
+
613  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
+
614 }
+
615 
+
616 void PS3BT::moveSetBulb(ColorsEnum color) { // Use this to set the Color using the predefined colors in enum
+
617  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
+
618 }
+
619 
+
620 void PS3BT::moveSetRumble(uint8_t rumble) {
+
621 #ifdef DEBUG_USB_HOST
+
622  if(rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
+
623  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
+
624 #endif
+
625  // Set the rumble value into the write buffer
+
626  HIDMoveBuffer[7] = rumble;
627 
-
628 void PS3BT::onInit() {
-
629  if(pFuncOnInit)
-
630  pFuncOnInit(); // Call the user function
-
631  else {
-
632  if(PS3MoveConnected)
-
633  moveSetBulb(Red);
-
634  else // Dualshock 3 or Navigation controller
-
635  setLedOn(static_cast<LEDEnum>(LED1));
-
636  }
-
637 }
+
628  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
+
629 }
+
630 
+
631 void PS3BT::onInit() {
+
632  if(pFuncOnInit)
+
633  pFuncOnInit(); // Call the user function
+
634  else {
+
635  if(PS3MoveConnected)
+
636  moveSetBulb(Red);
+
637  else // Dualshock 3 or Navigation controller
+
638  setLedOn(static_cast<LEDEnum>(LED1));
+
639  }
+
640 }
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTD.h:126
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1399
-
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:604
+
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:607
#define L2CAP_INTERRUPT_SETUP
Definition: BTD.h:123
bool PS3MoveConnected
Definition: PS3BT.h:182
@ NotCharging
Definition: PS3Enums.h:120
@@ -715,22 +718,22 @@ $(function() {
#define SUCCESSFUL
Definition: BTD.h:187
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1447
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1505
-
void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:224
+
void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
#define TURN_ON_LED
Definition: BTD.h:139
-
@ gYmove
+
@ gYmove
void setLedOff()
Definition: PS3BT.h:138
-
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:578
+
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:581
@ LED1
bool PS3NavigationConnected
Definition: PS3BT.h:184
@ Cable
Definition: PS3Enums.h:136
bool incomingWii
Definition: BTD.h:504
#define USB_HOST_SERIAL
Definition: settings.h:49
-
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:156
-
@ aZ
-
@ aYmove
-
@ mZmove
+
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
+
@ aZ
+
@ aYmove
+
@ mZmove
@ Unplugged
Definition: PS3Enums.h:117
-
SensorEnum
+
SensorEnum
#define PENDING
Definition: BTD.h:186
#define l2cap_check_flag(flag)
Definition: BTD.h:170
#define L2CAP_CONTROL_SUCCESS
Definition: BTD.h:119
@@ -739,42 +742,43 @@ $(function() {
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTD.h:147
#define strcat_P(dest, src)
@ Bluetooth
Definition: PS3Enums.h:138
-
@ gZmove
-
AngleEnum
-
@ aXmove
+
@ gZmove
+
AngleEnum
+
@ aXmove
+
int8_t getButtonIndexPS3(ButtonEnum b)
Definition: PS3Enums.h:141
#define Notify(...)
Definition: message.h:51
@ MoveShutdown
Definition: PS3Enums.h:129
bool connectToWii
Definition: BTD.h:500
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTD.h:125
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTD.h:152
Definition: BTD.h:221
-
void printStatusString()
Definition: PS3BT.cpp:160
-
void Reset()
Definition: PS3BT.cpp:204
+
void printStatusString()
Definition: PS3BT.cpp:163
+
void Reset()
Definition: PS3BT.cpp:207
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:181
-
@ aY
-
@ mXmove
+
@ aY
+
@ mXmove
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTD.h:155
const uint8_t PS3_LEDS[]
Definition: PS3Enums.h:43
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTD.h:149
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:180
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTD.h:146
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:24
-
void disconnect()
Definition: PS3BT.cpp:217
+
void disconnect()
Definition: PS3BT.cpp:220
LEDEnum
@ High
Definition: PS3Enums.h:124
@ MoveDying
Definition: PS3Enums.h:130
PS3BT(BTD *pBtd, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
Definition: PS3BT.cpp:23
-
@ Pitch
+
@ Pitch
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1522
-
@ gXmove
+
@ gXmove
uint32_t l2cap_event_flag
Definition: BTD.h:652
BTD * pBtd
Definition: BTD.h:646
#define L2CAP_DONE
Definition: BTD.h:114
-
String getTemperature()
Definition: PS3BT.cpp:141
+
String getTemperature()
Definition: PS3BT.cpp:144
char remote_name[30]
Definition: BTD.h:488
const uint32_t PS3_BUTTONS[]
Definition: PS3Enums.h:62
#define HID_CTRL_PSM
Definition: BTD.h:192
-
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:569
+
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:572
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1554
uint8_t hci_version
Definition: BTD.h:494
RumbleEnum
@@ -782,16 +786,16 @@ $(function() {
@ BluetoothRumble
Definition: PS3Enums.h:137
@ Charging
Definition: PS3Enums.h:119
uint8_t identifier
Definition: BTD.h:655
-
@ aZmove
+
@ aZmove
#define pgm_read_dword(addr)
-
@ gZ
+
@ gZ
StatusEnum
Definition: PS3Enums.h:113
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:175
bool getButtonPress(ButtonEnum b)
Definition: PS3BT.cpp:49
-
float get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:112
+
float get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:115
#define HID_INTR_PSM
Definition: BTD.h:193
const uint8_t PS3_ANALOG_BUTTONS[]
Definition: PS3Enums.h:92
-
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:559
+
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:562
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1541
#define HID_BUFFERSIZE
Definition: PS3BT.h:24
bool pairWithWii
Definition: BTD.h:506
@@ -802,48 +806,48 @@ $(function() {
uint16_t hci_handle
Definition: BTD.h:649
bool checkHciHandle(uint8_t *buf, uint16_t handle)
Definition: BTD.h:638
@ MoveNotCharging
Definition: PS3Enums.h:128
-
void setAllOff()
Definition: PS3BT.cpp:519
+
void setAllOff()
Definition: PS3BT.cpp:522
#define PS3_ENABLE_SIXAXIS
Definition: BTD.h:140
-
@ tempMove
+
@ tempMove
@ MoveCharging
Definition: PS3Enums.h:127
ColorsEnum
uint8_t my_bdaddr[6]
Definition: BTD.h:482
@ OFF
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
Definition: PS3Enums.h:27
Definition: BTD.h:603
-
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:64
+
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
@ Plugged
Definition: PS3Enums.h:116
@ Full
Definition: PS3Enums.h:125
#define PSTR(str)
-
float getAngle(AngleEnum a)
Definition: PS3BT.cpp:85
-
void onInit()
Definition: PS3BT.cpp:628
+
float getAngle(AngleEnum a)
Definition: PS3BT.cpp:88
+
void onInit()
Definition: PS3BT.cpp:631
@ MoveFull
Definition: PS3Enums.h:133
@ RumbleHigh
bool PS3Connected
Definition: PS3BT.h:176
bool l2capConnectionClaimed
Definition: BTD.h:470
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1488
-
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:68
-
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:617
-
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:53
+
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:71
+
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:620
+
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:54
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:176
#define strcpy_P(dest, src)
@ Shutdown
Definition: PS3Enums.h:121
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:178
-
@ aX
+
@ aX
#define L2CAP_CONTROL_DISCONNECT
Definition: BTD.h:120
#define l2cap_set_flag(flag)
Definition: BTD.h:171
uint16_t hci_handle
Definition: BTD.h:484
-
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:540
-
void setRumbleOff()
Definition: PS3BT.cpp:530
+
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:543
+
void setRumbleOff()
Definition: PS3BT.cpp:533
ButtonEnum
#define BULK_MAXPKTSIZE
Definition: BTD.h:37
-
AnalogHatEnum
+
AnalogHatEnum
@ MoveLow
Definition: PS3Enums.h:131
@ Dying
Definition: PS3Enums.h:122
-
@ mYmove
-
void Run()
Definition: PS3BT.cpp:454
-
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:60
+
@ mYmove
+
void Run()
Definition: PS3BT.cpp:457
+
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:62