| Last change
 on this file since 21 was             21, checked in by phudelai, 12 years ago | 
        
          | 
New component for the wifibot and the dualshock 3
 | 
        
          | File size:
            2.8 KB | 
      
      
| Line |  | 
|---|
| 1 | #ifndef CONTROLLER_H | 
|---|
| 2 | # define CONTROLLER_H | 
|---|
| 3 |  | 
|---|
| 4 | # include <iostream> | 
|---|
| 5 | # include <stdlib.h> | 
|---|
| 6 | # include <unistd.h> | 
|---|
| 7 | # include <sys/socket.h> | 
|---|
| 8 | # include <bluetooth/bluetooth.h> | 
|---|
| 9 | # include <bluetooth/l2cap.h> | 
|---|
| 10 | # include <QApplication> | 
|---|
| 11 | # include <QThread> | 
|---|
| 12 |  | 
|---|
| 13 | # include "kernel/ComponentBase.h" | 
|---|
| 14 | # include "kernel/DbiteFile.h" | 
|---|
| 15 | # include "kernel/DbiteFileTypes.h" | 
|---|
| 16 | # include "PacpusTools/ShMem.h" | 
|---|
| 17 |  | 
|---|
| 18 | # define L2CAP_PSM_HIDP_CTRL 0x11 | 
|---|
| 19 | # define L2CAP_PSM_HIDP_INTR 0x13 | 
|---|
| 20 |  | 
|---|
| 21 | # define HIDP_TRANS_GET_REPORT    0x40 | 
|---|
| 22 | # define HIDP_TRANS_SET_REPORT    0x50 | 
|---|
| 23 | # define HIDP_DATA_RTYPE_INPUT    0x01 | 
|---|
| 24 | # define HIDP_DATA_RTYPE_OUTPUT   0x02 | 
|---|
| 25 | # define HIDP_DATA_RTYPE_FEATURE  0x03 | 
|---|
| 26 |  | 
|---|
| 27 | namespace pacpus { | 
|---|
| 28 |  | 
|---|
| 29 | struct buttons_s { | 
|---|
| 30 | struct { | 
|---|
| 31 | uint8_t | 
|---|
| 32 | leftStick_x, | 
|---|
| 33 | leftStick_y, | 
|---|
| 34 | rightStick_x, | 
|---|
| 35 | rightStick_y; | 
|---|
| 36 | } stick; | 
|---|
| 37 |  | 
|---|
| 38 | struct { | 
|---|
| 39 | uint8_t | 
|---|
| 40 | select:1, | 
|---|
| 41 | l3:1, | 
|---|
| 42 | r3:1, | 
|---|
| 43 | start:1, | 
|---|
| 44 | up:1, | 
|---|
| 45 | right:1, | 
|---|
| 46 | down:1, | 
|---|
| 47 | left:1, | 
|---|
| 48 | l2:1, | 
|---|
| 49 | r2:1, | 
|---|
| 50 | l1:1, | 
|---|
| 51 | r1:1, | 
|---|
| 52 | triangle:1, | 
|---|
| 53 | circle:1, | 
|---|
| 54 | cross:1, | 
|---|
| 55 | square:1; | 
|---|
| 56 | } digital; | 
|---|
| 57 |  | 
|---|
| 58 | struct { | 
|---|
| 59 | uint8_t l1; | 
|---|
| 60 | uint8_t l2; | 
|---|
| 61 | uint8_t r1; | 
|---|
| 62 | uint8_t r2; | 
|---|
| 63 | uint8_t triangle; | 
|---|
| 64 | uint8_t circle; | 
|---|
| 65 | uint8_t cross; | 
|---|
| 66 | uint8_t square; | 
|---|
| 67 | uint8_t up; | 
|---|
| 68 | uint8_t right; | 
|---|
| 69 | uint8_t down; | 
|---|
| 70 | uint8_t left; | 
|---|
| 71 | } analog; | 
|---|
| 72 |  | 
|---|
| 73 | struct { | 
|---|
| 74 | int8_t x; | 
|---|
| 75 | int8_t y; | 
|---|
| 76 | int8_t z; | 
|---|
| 77 | int8_t gZ; | 
|---|
| 78 | } axis; | 
|---|
| 79 | }; | 
|---|
| 80 |  | 
|---|
| 81 | class Controller { | 
|---|
| 82 | public: | 
|---|
| 83 | struct buttons_s buttons; | 
|---|
| 84 | bdaddr_t addr; | 
|---|
| 85 | int csk; | 
|---|
| 86 | int isk; | 
|---|
| 87 | int paired; | 
|---|
| 88 | unsigned index; | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 | struct dualshockButtons_s { | 
|---|
| 92 | road_time_t       time; | 
|---|
| 93 | struct buttons_s  buttons; | 
|---|
| 94 | int               available; | 
|---|
| 95 | }; | 
|---|
| 96 |  | 
|---|
| 97 | class DualshockAPI: public QThread { | 
|---|
| 98 | Q_OBJECT | 
|---|
| 99 |  | 
|---|
| 100 | public: | 
|---|
| 101 | DualshockAPI(); | 
|---|
| 102 | ~DualshockAPI(); | 
|---|
| 103 | void run(); | 
|---|
| 104 | void stop(); | 
|---|
| 105 |  | 
|---|
| 106 | private: | 
|---|
| 107 | void main_loop(); | 
|---|
| 108 | int l2cap_listen(const bdaddr_t *bdaddr, unsigned short psm); | 
|---|
| 109 | void handle_connection(); | 
|---|
| 110 | void handle_disconnection(); | 
|---|
| 111 | void setup_device(int sk); | 
|---|
| 112 | void handle_report(unsigned char buf[], int len); | 
|---|
| 113 | void update_shared_memory(); | 
|---|
| 114 |  | 
|---|
| 115 | Controller controller; | 
|---|
| 116 | ShMem *shmem; | 
|---|
| 117 | DbiteFile dbtFile; | 
|---|
| 118 | int csk; | 
|---|
| 119 | int isk; | 
|---|
| 120 | int quit; | 
|---|
| 121 | }; | 
|---|
| 122 | } | 
|---|
| 123 | #endif /* CONTROLLER_H */ | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.