I2CピンでPS4の情報を読む
I2CPS4.cpp@0:23682bb56485, 2022-10-20 (annotated)
- Committer:
- m2130
- Date:
- Thu Oct 20 01:30:27 2022 +0000
- Revision:
- 0:23682bb56485
DS4 I2C library; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m2130 | 0:23682bb56485 | 1 | #include "I2CPS4.hpp" |
m2130 | 0:23682bb56485 | 2 | |
m2130 | 0:23682bb56485 | 3 | I2CPS4::I2CPS4(PinName SDA, PinName SCL, uint8_t ID) : _i2c(SDA, SCL){ |
m2130 | 0:23682bb56485 | 4 | _i2c.frequency(400000); |
m2130 | 0:23682bb56485 | 5 | id = ID << 1; |
m2130 | 0:23682bb56485 | 6 | } |
m2130 | 0:23682bb56485 | 7 | |
m2130 | 0:23682bb56485 | 8 | void I2CPS4::Data_Send(uint8_t name){ |
m2130 | 0:23682bb56485 | 9 | _i2c.write(id, (char *)&name, 1, true); |
m2130 | 0:23682bb56485 | 10 | _i2c.read(id, (char *)&data, 1); |
m2130 | 0:23682bb56485 | 11 | } |
m2130 | 0:23682bb56485 | 12 | |
m2130 | 0:23682bb56485 | 13 | void I2CPS4::button_state(){ |
m2130 | 0:23682bb56485 | 14 | if(up()) printf("Up "); |
m2130 | 0:23682bb56485 | 15 | if(right()) printf("Right "); |
m2130 | 0:23682bb56485 | 16 | if(left()) printf("Left "); |
m2130 | 0:23682bb56485 | 17 | if(down()) printf("Down "); |
m2130 | 0:23682bb56485 | 18 | if(triangle()) printf("Triangle "); |
m2130 | 0:23682bb56485 | 19 | if(circle()) printf("Circle "); |
m2130 | 0:23682bb56485 | 20 | if(square()) printf("Square "); |
m2130 | 0:23682bb56485 | 21 | if(cross()) printf("Cross "); |
m2130 | 0:23682bb56485 | 22 | if(l1()) printf("L1 "); |
m2130 | 0:23682bb56485 | 23 | if(l2() != 0) printf("L2:%2x ", l2()); |
m2130 | 0:23682bb56485 | 24 | if(l3()) printf("L3 "); |
m2130 | 0:23682bb56485 | 25 | if(r1()) printf("R1 "); |
m2130 | 0:23682bb56485 | 26 | if(r2() != 0) printf("R2:%2x ", r2()); |
m2130 | 0:23682bb56485 | 27 | if(r3()) printf("R3 "); |
m2130 | 0:23682bb56485 | 28 | if(options()) printf("OPTIONS "); |
m2130 | 0:23682bb56485 | 29 | if(share()) printf("SHARE "); |
m2130 | 0:23682bb56485 | 30 | if(ps()) printf("PS "); |
m2130 | 0:23682bb56485 | 31 | if(touchpad()) printf("TOUCHPAD "); |
m2130 | 0:23682bb56485 | 32 | if(lsx() != 127) printf("LSX:%3d ", lsx()); |
m2130 | 0:23682bb56485 | 33 | if(lsy() != 127) printf("LSY:%3d ", lsy()); |
m2130 | 0:23682bb56485 | 34 | if(rsx() != 127) printf("RSX:%3d ", rsx()); |
m2130 | 0:23682bb56485 | 35 | if(rsy() != 127) printf("RSY:%3d ", rsy()); |
m2130 | 0:23682bb56485 | 36 | printf("\n"); |
m2130 | 0:23682bb56485 | 37 | } |
m2130 | 0:23682bb56485 | 38 | |
m2130 | 0:23682bb56485 | 39 | bool I2CPS4::available(){ |
m2130 | 0:23682bb56485 | 40 | data = 0; |
m2130 | 0:23682bb56485 | 41 | Data_Send(255); |
m2130 | 0:23682bb56485 | 42 | return data; |
m2130 | 0:23682bb56485 | 43 | } |
m2130 | 0:23682bb56485 | 44 | bool I2CPS4::up(){ |
m2130 | 0:23682bb56485 | 45 | data = 0; |
m2130 | 0:23682bb56485 | 46 | Data_Send(UP); |
m2130 | 0:23682bb56485 | 47 | return data; |
m2130 | 0:23682bb56485 | 48 | } |
m2130 | 0:23682bb56485 | 49 | |
m2130 | 0:23682bb56485 | 50 | bool I2CPS4::right(){ |
m2130 | 0:23682bb56485 | 51 | data = 0; |
m2130 | 0:23682bb56485 | 52 | Data_Send(RIGHT); |
m2130 | 0:23682bb56485 | 53 | return data; |
m2130 | 0:23682bb56485 | 54 | } |
m2130 | 0:23682bb56485 | 55 | |
m2130 | 0:23682bb56485 | 56 | bool I2CPS4::left(){ |
m2130 | 0:23682bb56485 | 57 | data = 0; |
m2130 | 0:23682bb56485 | 58 | Data_Send(LEFT); |
m2130 | 0:23682bb56485 | 59 | return data; |
m2130 | 0:23682bb56485 | 60 | } |
m2130 | 0:23682bb56485 | 61 | |
m2130 | 0:23682bb56485 | 62 | bool I2CPS4::down(){ |
m2130 | 0:23682bb56485 | 63 | data = 0; |
m2130 | 0:23682bb56485 | 64 | Data_Send(DOWN); |
m2130 | 0:23682bb56485 | 65 | return data; |
m2130 | 0:23682bb56485 | 66 | } |
m2130 | 0:23682bb56485 | 67 | |
m2130 | 0:23682bb56485 | 68 | bool I2CPS4::triangle(){ |
m2130 | 0:23682bb56485 | 69 | data = 0; |
m2130 | 0:23682bb56485 | 70 | Data_Send(TRIANGLE); |
m2130 | 0:23682bb56485 | 71 | return data; |
m2130 | 0:23682bb56485 | 72 | } |
m2130 | 0:23682bb56485 | 73 | |
m2130 | 0:23682bb56485 | 74 | bool I2CPS4::circle(){ |
m2130 | 0:23682bb56485 | 75 | data = 0; |
m2130 | 0:23682bb56485 | 76 | Data_Send(CIRCLE); |
m2130 | 0:23682bb56485 | 77 | return data; |
m2130 | 0:23682bb56485 | 78 | } |
m2130 | 0:23682bb56485 | 79 | |
m2130 | 0:23682bb56485 | 80 | bool I2CPS4::square(){ |
m2130 | 0:23682bb56485 | 81 | data = 0; |
m2130 | 0:23682bb56485 | 82 | Data_Send(SQUARE); |
m2130 | 0:23682bb56485 | 83 | return data; |
m2130 | 0:23682bb56485 | 84 | } |
m2130 | 0:23682bb56485 | 85 | |
m2130 | 0:23682bb56485 | 86 | bool I2CPS4::cross(){ |
m2130 | 0:23682bb56485 | 87 | data = 0; |
m2130 | 0:23682bb56485 | 88 | Data_Send(CROSS); |
m2130 | 0:23682bb56485 | 89 | return data; |
m2130 | 0:23682bb56485 | 90 | } |
m2130 | 0:23682bb56485 | 91 | |
m2130 | 0:23682bb56485 | 92 | bool I2CPS4::touchpad(){ |
m2130 | 0:23682bb56485 | 93 | data = 0; |
m2130 | 0:23682bb56485 | 94 | Data_Send(TOUCHPAD); |
m2130 | 0:23682bb56485 | 95 | return data; |
m2130 | 0:23682bb56485 | 96 | } |
m2130 | 0:23682bb56485 | 97 | |
m2130 | 0:23682bb56485 | 98 | bool I2CPS4::ps(){ |
m2130 | 0:23682bb56485 | 99 | data = 0; |
m2130 | 0:23682bb56485 | 100 | Data_Send(PS); |
m2130 | 0:23682bb56485 | 101 | return data; |
m2130 | 0:23682bb56485 | 102 | } |
m2130 | 0:23682bb56485 | 103 | |
m2130 | 0:23682bb56485 | 104 | bool I2CPS4::l1(){ |
m2130 | 0:23682bb56485 | 105 | data = 0; |
m2130 | 0:23682bb56485 | 106 | Data_Send(L1); |
m2130 | 0:23682bb56485 | 107 | return data; |
m2130 | 0:23682bb56485 | 108 | } |
m2130 | 0:23682bb56485 | 109 | |
m2130 | 0:23682bb56485 | 110 | bool I2CPS4::r1(){ |
m2130 | 0:23682bb56485 | 111 | data = 0; |
m2130 | 0:23682bb56485 | 112 | Data_Send(R1); |
m2130 | 0:23682bb56485 | 113 | return data; |
m2130 | 0:23682bb56485 | 114 | } |
m2130 | 0:23682bb56485 | 115 | |
m2130 | 0:23682bb56485 | 116 | bool I2CPS4::options(){ |
m2130 | 0:23682bb56485 | 117 | data = 0; |
m2130 | 0:23682bb56485 | 118 | Data_Send(OPTIONS); |
m2130 | 0:23682bb56485 | 119 | return data; |
m2130 | 0:23682bb56485 | 120 | } |
m2130 | 0:23682bb56485 | 121 | |
m2130 | 0:23682bb56485 | 122 | bool I2CPS4::share(){ |
m2130 | 0:23682bb56485 | 123 | data = 0; |
m2130 | 0:23682bb56485 | 124 | Data_Send(SHARE); |
m2130 | 0:23682bb56485 | 125 | return data; |
m2130 | 0:23682bb56485 | 126 | } |
m2130 | 0:23682bb56485 | 127 | |
m2130 | 0:23682bb56485 | 128 | bool I2CPS4::l3(){ |
m2130 | 0:23682bb56485 | 129 | data = 0; |
m2130 | 0:23682bb56485 | 130 | Data_Send(L3); |
m2130 | 0:23682bb56485 | 131 | return data; |
m2130 | 0:23682bb56485 | 132 | } |
m2130 | 0:23682bb56485 | 133 | |
m2130 | 0:23682bb56485 | 134 | bool I2CPS4::r3(){ |
m2130 | 0:23682bb56485 | 135 | data = 0; |
m2130 | 0:23682bb56485 | 136 | Data_Send(R3); |
m2130 | 0:23682bb56485 | 137 | return data; |
m2130 | 0:23682bb56485 | 138 | } |
m2130 | 0:23682bb56485 | 139 | |
m2130 | 0:23682bb56485 | 140 | uint8_t I2CPS4::l2(){ |
m2130 | 0:23682bb56485 | 141 | data = 0; |
m2130 | 0:23682bb56485 | 142 | Data_Send(L2); |
m2130 | 0:23682bb56485 | 143 | return data; |
m2130 | 0:23682bb56485 | 144 | } |
m2130 | 0:23682bb56485 | 145 | |
m2130 | 0:23682bb56485 | 146 | uint8_t I2CPS4::r2(){ |
m2130 | 0:23682bb56485 | 147 | data = 0; |
m2130 | 0:23682bb56485 | 148 | Data_Send(R2); |
m2130 | 0:23682bb56485 | 149 | return data; |
m2130 | 0:23682bb56485 | 150 | } |
m2130 | 0:23682bb56485 | 151 | |
m2130 | 0:23682bb56485 | 152 | uint8_t I2CPS4::lsx(){ |
m2130 | 0:23682bb56485 | 153 | data = 0; |
m2130 | 0:23682bb56485 | 154 | Data_Send(LSX); |
m2130 | 0:23682bb56485 | 155 | return data; |
m2130 | 0:23682bb56485 | 156 | } |
m2130 | 0:23682bb56485 | 157 | |
m2130 | 0:23682bb56485 | 158 | uint8_t I2CPS4::lsy(){ |
m2130 | 0:23682bb56485 | 159 | data = 0; |
m2130 | 0:23682bb56485 | 160 | Data_Send(LSY); |
m2130 | 0:23682bb56485 | 161 | return data; |
m2130 | 0:23682bb56485 | 162 | } |
m2130 | 0:23682bb56485 | 163 | |
m2130 | 0:23682bb56485 | 164 | uint8_t I2CPS4::rsx(){ |
m2130 | 0:23682bb56485 | 165 | data = 0; |
m2130 | 0:23682bb56485 | 166 | Data_Send(RSX); |
m2130 | 0:23682bb56485 | 167 | return data; |
m2130 | 0:23682bb56485 | 168 | } |
m2130 | 0:23682bb56485 | 169 | |
m2130 | 0:23682bb56485 | 170 | uint8_t I2CPS4::rsy(){ |
m2130 | 0:23682bb56485 | 171 | data = 0; |
m2130 | 0:23682bb56485 | 172 | Data_Send(RSY); |
m2130 | 0:23682bb56485 | 173 | return data; |
m2130 | 0:23682bb56485 | 174 | } |