USB Host Shield 2.0
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 
45  void disconnect();
59  bool getButtonPress(ButtonEnum b);
60  bool getButtonClick(ButtonEnum b);
71  uint8_t getAnalogButton(ButtonEnum a);
77  uint8_t getAnalogHat(AnalogHatEnum a);
86  int16_t getSensor(SensorEnum a);
92  float getAngle(AngleEnum a);
98  float get9DOFValues(SensorEnum a);
104  bool getStatus(StatusEnum c);
106  void printStatusString();
111  String getTemperature();
112 
114  void setAllOff();
116  void setRumbleOff();
121  void setRumbleOn(RumbleEnum mode);
129  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
130 
135  void setLedRaw(uint8_t value);
136 
138  void setLedOff() {
139  setLedRaw(0);
140  };
145  void setLedOff(LEDEnum a);
150  void setLedOn(LEDEnum a);
155  void setLedToggle(LEDEnum a);
156 
161  void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
166  void moveSetBulb(ColorsEnum color);
171  void moveSetRumble(uint8_t rumble);
172 
174  uint32_t getLastMessageTime() {
175  return lastMessageTime;
176  };
185 
186 protected:
192  void ACLData(uint8_t* ACLData);
194  void Run();
196  void Reset();
202  void onInit();
205 private:
206 
207  void L2CAP_task(); // L2CAP state machine
208 
209  /* Variables filled from HCI event management */
210  char remote_name_first; // First letter in remote name
211  bool activeConnection; // Used to indicate if it's already has established a connection
212 
213  /* Variables used by high level L2CAP task */
214  uint8_t l2cap_state;
215 
216  uint32_t lastMessageTime; // Variable used to store the millis value of the last message.
217 
218  uint32_t ButtonState;
219  uint32_t OldButtonState;
220  uint32_t ButtonClickState;
221 
222  uint32_t timer; // Timer used to limit time between messages and also used to continuously set PS3 Move controller Bulb and rumble values
223  uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command
224 
225  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
226  uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands
227  uint8_t HIDMoveBuffer[HID_BUFFERSIZE]; // Used to store HID commands for the Move controller
228 
229  /* L2CAP Channels */
230  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
231  uint8_t control_dcid[2]; // 0x0040
232  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
233  uint8_t interrupt_dcid[2]; // 0x0041
234 
235  /* HID Commands */
236  void HID_Command(uint8_t* data, uint8_t nbytes);
237  void HIDMove_Command(uint8_t* data, uint8_t nbytes);
238  void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
239 };
240 #endif
#define BULK_MAXPKTSIZE
Definition: BTD.h:37
#define HID_BUFFERSIZE
Definition: PS3BT.h:24
StatusEnum
Definition: PS3Enums.h:113
Definition: BTD.h:222
BTD * pBtd
Definition: BTD.h:647
Definition: PS3BT.h:32
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:71
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:562
float get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:115
bool PS3Connected
Definition: PS3BT.h:176
void setLedOff()
Definition: PS3BT.h:138
void disconnect()
Definition: PS3BT.cpp:220
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:54
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:572
void onInit()
Definition: PS3BT.cpp:631
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
void Reset()
Definition: PS3BT.cpp:207
void setRumbleOff()
Definition: PS3BT.cpp:533
bool getButtonPress(ButtonEnum b)
Definition: PS3BT.cpp:49
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:62
void setAllOff()
Definition: PS3BT.cpp:522
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:543
void printStatusString()
Definition: PS3BT.cpp:163
bool PS3MoveConnected
Definition: PS3BT.h:182
void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
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
bool PS3NavigationConnected
Definition: PS3BT.h:184
void Run()
Definition: PS3BT.cpp:457
String getTemperature()
Definition: PS3BT.cpp:144
float getAngle(AngleEnum a)
Definition: PS3BT.cpp:88
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:620
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:607
uint32_t getLastMessageTime()
Definition: PS3BT.h:174
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:581
SensorEnum
AnalogHatEnum
LEDEnum
AngleEnum
ButtonEnum
ColorsEnum
RumbleEnum