[22] | 1 | /*********************************************************************
|
---|
| 2 | // created: 2012/03/01 - 14:06
|
---|
| 3 | // filename: controller.cpp
|
---|
| 4 | //
|
---|
| 5 | // author: Pierre Hudelaine
|
---|
| 6 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 7 | //
|
---|
| 8 | // version: $Id: $
|
---|
| 9 | //
|
---|
| 10 | // purpose: Read the dualshock 3 button using bluetooth
|
---|
| 11 | //
|
---|
| 12 | *********************************************************************/
|
---|
| 13 |
|
---|
[21] | 14 | #ifndef CONTROLLER_H
|
---|
| 15 | # define CONTROLLER_H
|
---|
| 16 |
|
---|
| 17 | # include <iostream>
|
---|
| 18 | # include <stdlib.h>
|
---|
| 19 | # include <unistd.h>
|
---|
| 20 | # include <sys/socket.h>
|
---|
| 21 | # include <bluetooth/bluetooth.h>
|
---|
| 22 | # include <bluetooth/l2cap.h>
|
---|
| 23 | # include <QApplication>
|
---|
| 24 | # include <QThread>
|
---|
| 25 |
|
---|
| 26 | # include "kernel/ComponentBase.h"
|
---|
| 27 | # include "kernel/DbiteFile.h"
|
---|
| 28 | # include "kernel/DbiteFileTypes.h"
|
---|
| 29 | # include "PacpusTools/ShMem.h"
|
---|
| 30 |
|
---|
| 31 | # define L2CAP_PSM_HIDP_CTRL 0x11
|
---|
| 32 | # define L2CAP_PSM_HIDP_INTR 0x13
|
---|
| 33 |
|
---|
| 34 | # define HIDP_TRANS_GET_REPORT 0x40
|
---|
| 35 | # define HIDP_TRANS_SET_REPORT 0x50
|
---|
| 36 | # define HIDP_DATA_RTYPE_INPUT 0x01
|
---|
| 37 | # define HIDP_DATA_RTYPE_OUTPUT 0x02
|
---|
| 38 | # define HIDP_DATA_RTYPE_FEATURE 0x03
|
---|
| 39 |
|
---|
| 40 | namespace pacpus {
|
---|
| 41 |
|
---|
| 42 | struct buttons_s {
|
---|
| 43 | struct {
|
---|
| 44 | uint8_t
|
---|
| 45 | leftStick_x,
|
---|
| 46 | leftStick_y,
|
---|
| 47 | rightStick_x,
|
---|
| 48 | rightStick_y;
|
---|
| 49 | } stick;
|
---|
| 50 |
|
---|
| 51 | struct {
|
---|
| 52 | uint8_t
|
---|
| 53 | select:1,
|
---|
| 54 | l3:1,
|
---|
| 55 | r3:1,
|
---|
| 56 | start:1,
|
---|
| 57 | up:1,
|
---|
| 58 | right:1,
|
---|
| 59 | down:1,
|
---|
| 60 | left:1,
|
---|
| 61 | l2:1,
|
---|
| 62 | r2:1,
|
---|
| 63 | l1:1,
|
---|
| 64 | r1:1,
|
---|
| 65 | triangle:1,
|
---|
| 66 | circle:1,
|
---|
| 67 | cross:1,
|
---|
| 68 | square:1;
|
---|
| 69 | } digital;
|
---|
| 70 |
|
---|
| 71 | struct {
|
---|
| 72 | uint8_t l1;
|
---|
| 73 | uint8_t l2;
|
---|
| 74 | uint8_t r1;
|
---|
| 75 | uint8_t r2;
|
---|
| 76 | uint8_t triangle;
|
---|
| 77 | uint8_t circle;
|
---|
| 78 | uint8_t cross;
|
---|
| 79 | uint8_t square;
|
---|
| 80 | uint8_t up;
|
---|
| 81 | uint8_t right;
|
---|
| 82 | uint8_t down;
|
---|
| 83 | uint8_t left;
|
---|
| 84 | } analog;
|
---|
| 85 |
|
---|
| 86 | struct {
|
---|
| 87 | int8_t x;
|
---|
| 88 | int8_t y;
|
---|
| 89 | int8_t z;
|
---|
| 90 | int8_t gZ;
|
---|
| 91 | } axis;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
| 94 | class Controller {
|
---|
| 95 | public:
|
---|
| 96 | struct buttons_s buttons;
|
---|
| 97 | bdaddr_t addr;
|
---|
| 98 | int csk;
|
---|
| 99 | int isk;
|
---|
| 100 | int paired;
|
---|
[22] | 101 | int timeout;
|
---|
[21] | 102 | unsigned index;
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | struct dualshockButtons_s {
|
---|
| 106 | road_time_t time;
|
---|
| 107 | struct buttons_s buttons;
|
---|
| 108 | int available;
|
---|
[22] | 109 | int timeout;
|
---|
[21] | 110 | };
|
---|
| 111 |
|
---|
| 112 | class DualshockAPI: public QThread {
|
---|
| 113 | Q_OBJECT
|
---|
| 114 |
|
---|
| 115 | public:
|
---|
| 116 | DualshockAPI();
|
---|
| 117 | ~DualshockAPI();
|
---|
| 118 | void run();
|
---|
| 119 | void stop();
|
---|
| 120 |
|
---|
| 121 | private:
|
---|
| 122 | void main_loop();
|
---|
| 123 | int l2cap_listen(const bdaddr_t *bdaddr, unsigned short psm);
|
---|
| 124 | void handle_connection();
|
---|
| 125 | void handle_disconnection();
|
---|
| 126 | void setup_device(int sk);
|
---|
| 127 | void handle_report(unsigned char buf[], int len);
|
---|
| 128 | void update_shared_memory();
|
---|
| 129 |
|
---|
| 130 | Controller controller;
|
---|
| 131 | ShMem *shmem;
|
---|
| 132 | DbiteFile dbtFile;
|
---|
| 133 | int csk;
|
---|
| 134 | int isk;
|
---|
| 135 | int quit;
|
---|
| 136 | };
|
---|
| 137 | }
|
---|
| 138 | #endif /* CONTROLLER_H */
|
---|