1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2015/03/31
|
---|
6 | // filename: DualShock3.h
|
---|
7 | //
|
---|
8 | // authors: pabr.org, Gildas Bayard
|
---|
9 | // Copyright (c) 2010 pabr@pabr.org
|
---|
10 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
11 | //
|
---|
12 | // version: $Id: $
|
---|
13 | //
|
---|
14 | // purpose: Sony DualShock3 host side driver class. Talks to target side through ethernet.
|
---|
15 | //
|
---|
16 | //
|
---|
17 | /*********************************************************************/
|
---|
18 |
|
---|
19 | #ifndef DUALSHOCK3_H
|
---|
20 | #define DUALSHOCK3_H
|
---|
21 |
|
---|
22 | #include <HostEthController.h>
|
---|
23 |
|
---|
24 | #include <stdint.h>
|
---|
25 | #include <bluetooth/bluetooth.h>
|
---|
26 | #include <bluetooth/l2cap.h>
|
---|
27 | #include <usb.h>
|
---|
28 |
|
---|
29 | namespace flair {
|
---|
30 | namespace core {
|
---|
31 | class FrameworkManager;
|
---|
32 | }
|
---|
33 | namespace gui {
|
---|
34 | class SpinBox;
|
---|
35 | class Label;
|
---|
36 | class CheckBox;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | struct motion_dev;
|
---|
41 |
|
---|
42 | namespace flair { namespace sensor {
|
---|
43 | /*! \class DualShock3
|
---|
44 | *
|
---|
45 | * \brief Sony DualShock3 host side driver class. Talks to target side through ethernet.
|
---|
46 | */
|
---|
47 | class DualShock3 : public HostEthController {
|
---|
48 | public:
|
---|
49 | typedef enum {
|
---|
50 | Usb,
|
---|
51 | Bluetooth
|
---|
52 | } ConnectionType_t;
|
---|
53 |
|
---|
54 | DualShock3(const core::FrameworkManager* parent,std::string name,std::string receiverAddress,int receiverPort,ConnectionType_t connectionType,uint32_t period=10,uint32_t bitsPerAxis=7,uint8_t priority=0);
|
---|
55 | ~DualShock3();
|
---|
56 | private:
|
---|
57 | gui::SpinBox* deadZone;
|
---|
58 | gui::CheckBox* enabled;
|
---|
59 | gui::Label *batteryChargeLevel;
|
---|
60 | ConnectionType_t connectionType;
|
---|
61 | core::Time now;
|
---|
62 |
|
---|
63 | std::string GetAxisDescription(unsigned int axis);
|
---|
64 | std::string GetButtonDescription(unsigned int button);
|
---|
65 | void GetAxisData();
|
---|
66 | void GetButtonData();
|
---|
67 | bool IsDataFrameReady();
|
---|
68 | void ProcessMessage(core::Message *controllerAction);
|
---|
69 |
|
---|
70 | void UpdateFrom(const core::io_data *data) {};
|
---|
71 | void fatal(const char *msg);
|
---|
72 | int l2cap_listen(const bdaddr_t *bdaddr, unsigned short psm);
|
---|
73 | struct motion_dev *accept_device(int csk, int isk);
|
---|
74 | void hidp_trans(int csk, char *buf, int len);
|
---|
75 | void setup_device(struct motion_dev *dev);
|
---|
76 | bool parse_report_sixaxis_ds3(unsigned char *r, int len);
|
---|
77 | int mystr2ba(const char *s, bdaddr_t *ba);
|
---|
78 | char *myba2str(const bdaddr_t *ba);
|
---|
79 | int8_t compute_dead_zone(int axis,unsigned char value);
|
---|
80 | struct motion_dev *dev;
|
---|
81 | int usb_fd;
|
---|
82 | int isk;
|
---|
83 | core::Time last_voltage_time;
|
---|
84 |
|
---|
85 | int8_t *datas;
|
---|
86 | uint8_t dataSize;
|
---|
87 |
|
---|
88 | void usb_scan();
|
---|
89 | void usb_pair_device(struct usb_device *dev, int itfnum);
|
---|
90 |
|
---|
91 | void rumble(uint8_t left_force,uint8_t left_timeout,uint8_t right_force,uint8_t right_timeout);
|
---|
92 | void set_led(uint8_t led,uint8_t on_timeout,uint8_t off_timeout);
|
---|
93 | char ledmask;
|
---|
94 | uint8_t led1_on,led1_off,led2_on,led2_off,led3_on,led3_off,led4_on,led4_off;
|
---|
95 |
|
---|
96 | };
|
---|
97 | }}
|
---|
98 |
|
---|
99 | #endif // DUALSHOCK3_H
|
---|