USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PS3BT.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Lauszus, TKJ Electronics
14  Web : http://www.tkjelectronics.com
15  e-mail : kristianl@tkjelectronics.com
16  */
17 
18 #ifndef _ps3bt_h_
19 #define _ps3bt_h_
20 
21 #include "BTD.h"
22 #include "PS3Enums.h"
23 
24 #define HID_BUFFERSIZE 50 // Size of the buffer for the Playstation Motion Controller
25 
32 class PS3BT : public BluetoothService {
33 public:
41  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);
42 
48  virtual void ACLData(uint8_t* ACLData);
50  virtual void Run();
52  virtual void Reset();
54  virtual void disconnect();
68  bool getButtonPress(ButtonEnum b);
69  bool getButtonClick(ButtonEnum b);
80  uint8_t getAnalogButton(ButtonEnum a);
86  uint8_t getAnalogHat(AnalogHatEnum a);
95  int16_t getSensor(SensorEnum a);
101  double getAngle(AngleEnum a);
107  double get9DOFValues(SensorEnum a);
113  bool getStatus(StatusEnum c);
115  void printStatusString();
120  String getTemperature();
121 
123  void setAllOff();
125  void setRumbleOff();
130  void setRumbleOn(RumbleEnum mode);
138  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
139 
144  void setLedRaw(uint8_t value);
145 
147  void setLedOff() {
148  setLedRaw(0);
149  };
154  void setLedOff(LEDEnum a);
159  void setLedOn(LEDEnum a);
164  void setLedToggle(LEDEnum a);
165 
170  void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
175  void moveSetBulb(ColorsEnum color);
180  void moveSetRumble(uint8_t rumble);
181 
183  uint32_t getLastMessageTime() {
184  return lastMessageTime;
185  };
186 
191  void attachOnInit(void (*funcOnInit)(void)) {
192  pFuncOnInit = funcOnInit;
193  };
197  bool PS3Connected;
202 
203 private:
204  /* Mandatory members */
205  BTD *pBtd;
206 
212  void onInit();
213  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
214 
215  void L2CAP_task(); // L2CAP state machine
216 
217  /* Variables filled from HCI event management */
218  int16_t hci_handle;
219  uint8_t remote_name[30]; // First 30 chars of remote name
220  bool activeConnection; // Used to indicate if it's already has established a connection
221 
222  /* Variables used by high level L2CAP task */
223  uint8_t l2cap_state;
224  uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
225 
226  uint32_t lastMessageTime; // Variable used to store the millis value of the last message.
227 
228  unsigned long timer;
229 
230  uint32_t ButtonState;
231  uint32_t OldButtonState;
232  uint32_t ButtonClickState;
233 
234  uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command
235  uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values
236 
237  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
238  uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands
239  uint8_t HIDMoveBuffer[HID_BUFFERSIZE]; // Used to store HID commands for the Move controller
240 
241  /* L2CAP Channels */
242  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
243  uint8_t control_dcid[2]; // 0x0040
244  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
245  uint8_t interrupt_dcid[2]; // 0x0041
246  uint8_t identifier; // Identifier for connection
247 
248  /* HID Commands */
249  void HID_Command(uint8_t* data, uint8_t nbytes);
250  void HIDMove_Command(uint8_t* data, uint8_t nbytes);
251  void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
252 };
253 #endif
bool PS3NavigationConnected
Definition: PS3BT.h:201
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
virtual void Run()
Definition: PS3BT.cpp:458
Definition: BTD.h:230
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:570
String getTemperature()
Definition: PS3BT.cpp:144
AnalogHatEnum
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:618
void printStatusString()
Definition: PS3BT.cpp:163
void setAllOff()
Definition: PS3BT.cpp:523
StatusEnum
Definition: PS3Enums.h:113
#define HID_BUFFERSIZE
Definition: PS3BT.h:24
virtual void Reset()
Definition: PS3BT.cpp:207
bool getButtonPress(ButtonEnum b)
Definition: PS3BT.cpp:52
LEDEnum
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:71
double getAngle(AngleEnum a)
Definition: PS3BT.cpp:88
RumbleEnum
Definition: PS3BT.h:32
void attachOnInit(void(*funcOnInit)(void))
Definition: PS3BT.h:191
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
bool PS3Connected
Definition: PS3BT.h:193
ButtonEnum
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:605
bool PS3MoveConnected
Definition: PS3BT.h:199
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:543
ColorsEnum
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
AngleEnum
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
void setLedOff()
Definition: PS3BT.h:147
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:579
virtual void disconnect()
Definition: PS3BT.cpp:220
SensorEnum
double get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:115
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:63
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:560
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
uint32_t getLastMessageTime()
Definition: PS3BT.h:183
void setRumbleOff()
Definition: PS3BT.cpp:534
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:56