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