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 
186  void attachOnInit(void (*funcOnInit)(void)) {
187  pFuncOnInit = funcOnInit;
188  };
192  bool PS3Connected;
197 
198 private:
199  /* Mandatory members */
200  BTD *pBtd;
201 
207  void onInit();
208  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
209 
210  void L2CAP_task(); // L2CAP state machine
211 
212  /* Variables filled from HCI event management */
213  int16_t hci_handle;
214  uint8_t remote_name[30]; // First 30 chars of remote name
215  bool activeConnection; // Used to indicate if it's already has established a connection
216 
217  /* variables used by high level L2CAP task */
218  uint8_t l2cap_state;
219  uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
220 
221  unsigned long timer;
222 
223  uint32_t ButtonState;
224  uint32_t OldButtonState;
225  uint32_t ButtonClickState;
226 
227  uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command
228  uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values
229 
230  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
231  uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands
232  uint8_t HIDMoveBuffer[HID_BUFFERSIZE]; // Used to store HID commands for the Move controller
233 
234  /* L2CAP Channels */
235  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
236  uint8_t control_dcid[2]; // 0x0040
237  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
238  uint8_t interrupt_dcid[2]; // 0x0041
239  uint8_t identifier; // Identifier for connection
240 
241  /* HID Commands */
242  void HID_Command(uint8_t* data, uint8_t nbytes);
243  void HIDMove_Command(uint8_t* data, uint8_t nbytes);
244  void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
245 };
246 #endif
RumbleEnum
Definition: PS3Enums.h:163
bool PS3NavigationConnected
Definition: PS3BT.h:196
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
virtual void Run()
Definition: PS3BT.cpp:456
Definition: BTD.h:230
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:568
String getTemperature()
Definition: PS3BT.cpp:144
AnalogHatEnum
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:616
void printStatusString()
Definition: PS3BT.cpp:163
void setAllOff()
Definition: PS3BT.cpp:521
StatusEnum
Definition: PS3Enums.h:135
#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
Definition: PS3BT.h:32
void attachOnInit(void(*funcOnInit)(void))
Definition: PS3BT.h:186
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
bool PS3Connected
Definition: PS3BT.h:188
ButtonEnum
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:603
bool PS3MoveConnected
Definition: PS3BT.h:194
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:541
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
ColorsEnum
Definition: PS3Enums.h:114
AngleEnum
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
void setLedOff()
Definition: PS3BT.h:147
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:577
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:558
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
void setRumbleOff()
Definition: PS3BT.cpp:532
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:56