c
Fork of MyLib by
PS3/PS3.h@8:dd476889a42e, 2017-05-11 (annotated)
- Committer:
- gaku_sigu
- Date:
- Thu May 11 10:58:25 2017 +0000
- Revision:
- 8:dd476889a42e
- Parent:
- 1:c75100913a65
remove error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gaku_sigu | 1:c75100913a65 | 1 | #ifndef PS3_H |
gaku_sigu | 1:c75100913a65 | 2 | #define PS3_H |
gaku_sigu | 1:c75100913a65 | 3 | #include "mbed.h" |
gaku_sigu | 1:c75100913a65 | 4 | |
gaku_sigu | 1:c75100913a65 | 5 | #define MARU 64 |
gaku_sigu | 1:c75100913a65 | 6 | #define BATU 32 |
gaku_sigu | 1:c75100913a65 | 7 | #define SIKAKU 1 |
gaku_sigu | 1:c75100913a65 | 8 | #define SANKAKU 16 |
gaku_sigu | 1:c75100913a65 | 9 | #define UE 1 |
gaku_sigu | 1:c75100913a65 | 10 | #define SITA 2 |
gaku_sigu | 1:c75100913a65 | 11 | #define MIGI 4 |
gaku_sigu | 1:c75100913a65 | 12 | #define HIDARI 8 |
gaku_sigu | 1:c75100913a65 | 13 | #define LEFT1 2 |
gaku_sigu | 1:c75100913a65 | 14 | #define LEFT2 4 |
gaku_sigu | 1:c75100913a65 | 15 | #define RIGHT1 8 |
gaku_sigu | 1:c75100913a65 | 16 | #define RIGHT2 16 |
gaku_sigu | 1:c75100913a65 | 17 | |
gaku_sigu | 1:c75100913a65 | 18 | class PS3 : public Serial |
gaku_sigu | 1:c75100913a65 | 19 | { |
gaku_sigu | 1:c75100913a65 | 20 | public: |
gaku_sigu | 1:c75100913a65 | 21 | PS3(PinName TX, PinName RX); |
gaku_sigu | 1:c75100913a65 | 22 | /*{ |
gaku_sigu | 1:c75100913a65 | 23 | PS3Data[0] = 128; |
gaku_sigu | 1:c75100913a65 | 24 | PS3Data[1] = 0; |
gaku_sigu | 1:c75100913a65 | 25 | PS3Data[2] = 0; |
gaku_sigu | 1:c75100913a65 | 26 | PS3Data[3] = 64; |
gaku_sigu | 1:c75100913a65 | 27 | PS3Data[4] = 64; |
gaku_sigu | 1:c75100913a65 | 28 | PS3Data[5] = 64; |
gaku_sigu | 1:c75100913a65 | 29 | PS3Data[6] = 64; |
gaku_sigu | 1:c75100913a65 | 30 | PS3Data[7] = 0; |
gaku_sigu | 1:c75100913a65 | 31 | baud(2400); |
gaku_sigu | 1:c75100913a65 | 32 | Serial::attach(this, &PS3::getdata, Serial::RxIrq); |
gaku_sigu | 1:c75100913a65 | 33 | }*/ |
gaku_sigu | 1:c75100913a65 | 34 | |
gaku_sigu | 1:c75100913a65 | 35 | bool maru(); |
gaku_sigu | 1:c75100913a65 | 36 | /*{ |
gaku_sigu | 1:c75100913a65 | 37 | return PS3Data[2] & MARU; |
gaku_sigu | 1:c75100913a65 | 38 | }*/ |
gaku_sigu | 1:c75100913a65 | 39 | |
gaku_sigu | 1:c75100913a65 | 40 | bool batu(); |
gaku_sigu | 1:c75100913a65 | 41 | /*{ |
gaku_sigu | 1:c75100913a65 | 42 | return PS3Data[2] & BATU; |
gaku_sigu | 1:c75100913a65 | 43 | }*/ |
gaku_sigu | 1:c75100913a65 | 44 | |
gaku_sigu | 1:c75100913a65 | 45 | bool sikaku(); |
gaku_sigu | 1:c75100913a65 | 46 | /*{ |
gaku_sigu | 1:c75100913a65 | 47 | return PS3Data[1] & SIKAKU; |
gaku_sigu | 1:c75100913a65 | 48 | }*/ |
gaku_sigu | 1:c75100913a65 | 49 | |
gaku_sigu | 1:c75100913a65 | 50 | bool sankaku(); |
gaku_sigu | 1:c75100913a65 | 51 | /*{ |
gaku_sigu | 1:c75100913a65 | 52 | return PS3Data[2] & SANKAKU; |
gaku_sigu | 1:c75100913a65 | 53 | }*/ |
gaku_sigu | 1:c75100913a65 | 54 | |
gaku_sigu | 1:c75100913a65 | 55 | bool ue(); |
gaku_sigu | 1:c75100913a65 | 56 | /*{ |
gaku_sigu | 1:c75100913a65 | 57 | return PS3Data[2] & UE && !(PS3Data[2] & SITA); |
gaku_sigu | 1:c75100913a65 | 58 | }*/ |
gaku_sigu | 1:c75100913a65 | 59 | |
gaku_sigu | 1:c75100913a65 | 60 | bool sita(); |
gaku_sigu | 1:c75100913a65 | 61 | /*{ |
gaku_sigu | 1:c75100913a65 | 62 | return PS3Data[2] & SITA && !(PS3Data[2] & UE); |
gaku_sigu | 1:c75100913a65 | 63 | }*/ |
gaku_sigu | 1:c75100913a65 | 64 | |
gaku_sigu | 1:c75100913a65 | 65 | bool start(); |
gaku_sigu | 1:c75100913a65 | 66 | /*{ |
gaku_sigu | 1:c75100913a65 | 67 | return PS3Data[2] & UE && PS3Data[2] & SITA; |
gaku_sigu | 1:c75100913a65 | 68 | }*/ |
gaku_sigu | 1:c75100913a65 | 69 | |
gaku_sigu | 1:c75100913a65 | 70 | bool migi(); |
gaku_sigu | 1:c75100913a65 | 71 | /*{ |
gaku_sigu | 1:c75100913a65 | 72 | return PS3Data[2] & MIGI && !(PS3Data[2] & HIDARI); |
gaku_sigu | 1:c75100913a65 | 73 | }*/ |
gaku_sigu | 1:c75100913a65 | 74 | |
gaku_sigu | 1:c75100913a65 | 75 | bool hidari(); |
gaku_sigu | 1:c75100913a65 | 76 | /*{ |
gaku_sigu | 1:c75100913a65 | 77 | return PS3Data[2] & HIDARI && !(PS3Data[2] & MIGI); |
gaku_sigu | 1:c75100913a65 | 78 | }*/ |
gaku_sigu | 1:c75100913a65 | 79 | |
gaku_sigu | 1:c75100913a65 | 80 | bool select(); |
gaku_sigu | 1:c75100913a65 | 81 | /*{ |
gaku_sigu | 1:c75100913a65 | 82 | return PS3Data[2] & MIGI && PS3Data[2] & HIDARI; |
gaku_sigu | 1:c75100913a65 | 83 | }*/ |
gaku_sigu | 1:c75100913a65 | 84 | |
gaku_sigu | 1:c75100913a65 | 85 | bool L1(); |
gaku_sigu | 1:c75100913a65 | 86 | /*{ |
gaku_sigu | 1:c75100913a65 | 87 | return PS3Data[1] & LEFT1; |
gaku_sigu | 1:c75100913a65 | 88 | }*/ |
gaku_sigu | 1:c75100913a65 | 89 | |
gaku_sigu | 1:c75100913a65 | 90 | bool L2(); |
gaku_sigu | 1:c75100913a65 | 91 | /*{ |
gaku_sigu | 1:c75100913a65 | 92 | return PS3Data[1] & LEFT2; |
gaku_sigu | 1:c75100913a65 | 93 | }*/ |
gaku_sigu | 1:c75100913a65 | 94 | |
gaku_sigu | 1:c75100913a65 | 95 | bool R1(); |
gaku_sigu | 1:c75100913a65 | 96 | /*{ |
gaku_sigu | 1:c75100913a65 | 97 | return PS3Data[1] & RIGHT1; |
gaku_sigu | 1:c75100913a65 | 98 | }*/ |
gaku_sigu | 1:c75100913a65 | 99 | |
gaku_sigu | 1:c75100913a65 | 100 | bool R2(); |
gaku_sigu | 1:c75100913a65 | 101 | /*{ |
gaku_sigu | 1:c75100913a65 | 102 | return PS3Data[1] & RIGHT2; |
gaku_sigu | 1:c75100913a65 | 103 | }*/ |
gaku_sigu | 1:c75100913a65 | 104 | |
gaku_sigu | 1:c75100913a65 | 105 | int8_t analogLX(); |
gaku_sigu | 1:c75100913a65 | 106 | /*{ |
gaku_sigu | 1:c75100913a65 | 107 | if(PS3Data[3] == 0) |
gaku_sigu | 1:c75100913a65 | 108 | PS3Data[3]=1; |
gaku_sigu | 1:c75100913a65 | 109 | return PS3Data[3]-64; |
gaku_sigu | 1:c75100913a65 | 110 | }*/ |
gaku_sigu | 1:c75100913a65 | 111 | |
gaku_sigu | 1:c75100913a65 | 112 | int8_t analogLY(); |
gaku_sigu | 1:c75100913a65 | 113 | /*{ |
gaku_sigu | 1:c75100913a65 | 114 | if(PS3Data[4] == 0) |
gaku_sigu | 1:c75100913a65 | 115 | PS3Data[4]=1; |
gaku_sigu | 1:c75100913a65 | 116 | return (PS3Data[4]-64)*(-1); |
gaku_sigu | 1:c75100913a65 | 117 | }*/ |
gaku_sigu | 1:c75100913a65 | 118 | |
gaku_sigu | 1:c75100913a65 | 119 | int8_t analogRX(); |
gaku_sigu | 1:c75100913a65 | 120 | /*{ |
gaku_sigu | 1:c75100913a65 | 121 | if(PS3Data[5] == 0) |
gaku_sigu | 1:c75100913a65 | 122 | PS3Data[5]=1; |
gaku_sigu | 1:c75100913a65 | 123 | return PS3Data[5]-64; |
gaku_sigu | 1:c75100913a65 | 124 | }*/ |
gaku_sigu | 1:c75100913a65 | 125 | |
gaku_sigu | 1:c75100913a65 | 126 | int8_t analogRY(); |
gaku_sigu | 1:c75100913a65 | 127 | /*{ |
gaku_sigu | 1:c75100913a65 | 128 | if(PS3Data[6] == 0) |
gaku_sigu | 1:c75100913a65 | 129 | PS3Data[6]=1; |
gaku_sigu | 1:c75100913a65 | 130 | return (PS3Data[6]-64)*(-1); |
gaku_sigu | 1:c75100913a65 | 131 | }*/ |
gaku_sigu | 1:c75100913a65 | 132 | |
gaku_sigu | 1:c75100913a65 | 133 | |
gaku_sigu | 1:c75100913a65 | 134 | |
gaku_sigu | 1:c75100913a65 | 135 | private: |
gaku_sigu | 1:c75100913a65 | 136 | |
gaku_sigu | 1:c75100913a65 | 137 | int8_t sum; |
gaku_sigu | 8:dd476889a42e | 138 | uint8_t PS3Data[8]; |
gaku_sigu | 8:dd476889a42e | 139 | uint8_t GetData[8]; |
gaku_sigu | 1:c75100913a65 | 140 | |
gaku_sigu | 1:c75100913a65 | 141 | void getdata(); |
gaku_sigu | 1:c75100913a65 | 142 | /*{ |
gaku_sigu | 1:c75100913a65 | 143 | while(Serial::getc() != 128) |
gaku_sigu | 1:c75100913a65 | 144 | { |
gaku_sigu | 1:c75100913a65 | 145 | } |
gaku_sigu | 1:c75100913a65 | 146 | for(int i = 1;i < 8;i++) |
gaku_sigu | 1:c75100913a65 | 147 | { |
gaku_sigu | 1:c75100913a65 | 148 | GetData[i] = Serial::getc(); |
gaku_sigu | 1:c75100913a65 | 149 | } |
gaku_sigu | 1:c75100913a65 | 150 | |
gaku_sigu | 1:c75100913a65 | 151 | sum = GetData[1] + GetData[2]; |
gaku_sigu | 1:c75100913a65 | 152 | for(int i = 3;i < 7;i++) |
gaku_sigu | 1:c75100913a65 | 153 | { |
gaku_sigu | 1:c75100913a65 | 154 | sum += GetData[i] - 64; |
gaku_sigu | 1:c75100913a65 | 155 | } |
gaku_sigu | 1:c75100913a65 | 156 | |
gaku_sigu | 1:c75100913a65 | 157 | if(sum < 0) |
gaku_sigu | 1:c75100913a65 | 158 | sum+=128; |
gaku_sigu | 1:c75100913a65 | 159 | |
gaku_sigu | 1:c75100913a65 | 160 | if(sum == GetData[7]) |
gaku_sigu | 1:c75100913a65 | 161 | { |
gaku_sigu | 1:c75100913a65 | 162 | for(int i = 0;i < 8;i++) |
gaku_sigu | 1:c75100913a65 | 163 | { |
gaku_sigu | 1:c75100913a65 | 164 | PS3Data[i]=GetData[i]; |
gaku_sigu | 1:c75100913a65 | 165 | } |
gaku_sigu | 1:c75100913a65 | 166 | } |
gaku_sigu | 1:c75100913a65 | 167 | }*/ |
gaku_sigu | 1:c75100913a65 | 168 | |
gaku_sigu | 1:c75100913a65 | 169 | }; |
gaku_sigu | 1:c75100913a65 | 170 | |
gaku_sigu | 1:c75100913a65 | 171 | #endif |
gaku_sigu | 1:c75100913a65 | 172 | |
gaku_sigu | 1:c75100913a65 | 173 |