3/5
Dependencies: mbed
AutoEvents.cpp@1:530908de68c6, 2019-03-05 (annotated)
- Committer:
- yuki0701
- Date:
- Tue Mar 05 04:30:35 2019 +0000
- Revision:
- 1:530908de68c6
- Parent:
- 0:a56be39653d0
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
la00noix | 0:a56be39653d0 | 1 | /* |
la00noix | 0:a56be39653d0 | 2 | Copyright (c) 2010 Peter Barrett |
la00noix | 0:a56be39653d0 | 3 | |
la00noix | 0:a56be39653d0 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
la00noix | 0:a56be39653d0 | 5 | of this software and associated documentation files (the "Software"), to deal |
la00noix | 0:a56be39653d0 | 6 | in the Software without restriction, including without limitation the rights |
la00noix | 0:a56be39653d0 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
la00noix | 0:a56be39653d0 | 8 | copies of the Software, and to permit persons to whom the Software is |
la00noix | 0:a56be39653d0 | 9 | furnished to do so, subject to the following conditions: |
la00noix | 0:a56be39653d0 | 10 | |
la00noix | 0:a56be39653d0 | 11 | The above copyright notice and this permission notice shall be included in |
la00noix | 0:a56be39653d0 | 12 | all copies or substantial portions of the Software. |
la00noix | 0:a56be39653d0 | 13 | |
la00noix | 0:a56be39653d0 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
la00noix | 0:a56be39653d0 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
la00noix | 0:a56be39653d0 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
la00noix | 0:a56be39653d0 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
la00noix | 0:a56be39653d0 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
la00noix | 0:a56be39653d0 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
la00noix | 0:a56be39653d0 | 20 | THE SOFTWARE. |
la00noix | 0:a56be39653d0 | 21 | */ |
la00noix | 0:a56be39653d0 | 22 | |
la00noix | 0:a56be39653d0 | 23 | /* |
la00noix | 0:a56be39653d0 | 24 | Tue Apr 26 2011 Bart Janssens: added PS3 USB support |
la00noix | 0:a56be39653d0 | 25 | */ |
la00noix | 0:a56be39653d0 | 26 | |
la00noix | 0:a56be39653d0 | 27 | #include <stdio.h> |
la00noix | 0:a56be39653d0 | 28 | #include <stdlib.h> |
la00noix | 0:a56be39653d0 | 29 | #include <stdio.h> |
la00noix | 0:a56be39653d0 | 30 | #include <string.h> |
la00noix | 0:a56be39653d0 | 31 | #include <mbed.h> |
la00noix | 0:a56be39653d0 | 32 | |
la00noix | 0:a56be39653d0 | 33 | #include "USBHost.h" |
la00noix | 0:a56be39653d0 | 34 | #include "Utils.h" |
la00noix | 0:a56be39653d0 | 35 | #include "ps3.h" |
la00noix | 0:a56be39653d0 | 36 | |
la00noix | 0:a56be39653d0 | 37 | #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol) |
la00noix | 0:a56be39653d0 | 38 | #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1) |
la00noix | 0:a56be39653d0 | 39 | #define AUTO_MOUSE AUTOEVT(CLASS_HID,1,2) |
la00noix | 0:a56be39653d0 | 40 | //#define AUTO_PS3 AUTOEVT(CLASS_HID,0,0) |
la00noix | 0:a56be39653d0 | 41 | |
la00noix | 0:a56be39653d0 | 42 | u8 auto_mouse[4]; // buttons,dx,dy,scroll |
la00noix | 0:a56be39653d0 | 43 | u8 auto_keyboard[8]; // modifiers,reserved,keycode1..keycode6 |
la00noix | 0:a56be39653d0 | 44 | u8 auto_joystick[4]; // x,y,buttons,throttle |
la00noix | 0:a56be39653d0 | 45 | //u8 auto_ps3[48]; |
la00noix | 0:a56be39653d0 | 46 | |
la00noix | 0:a56be39653d0 | 47 | |
la00noix | 0:a56be39653d0 | 48 | |
la00noix | 0:a56be39653d0 | 49 | |
la00noix | 0:a56be39653d0 | 50 | void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData) |
la00noix | 0:a56be39653d0 | 51 | { |
la00noix | 0:a56be39653d0 | 52 | int evt = (int)userData; |
la00noix | 0:a56be39653d0 | 53 | switch (evt) |
la00noix | 0:a56be39653d0 | 54 | { |
la00noix | 0:a56be39653d0 | 55 | case AUTO_KEYBOARD: |
la00noix | 0:a56be39653d0 | 56 | printf("AUTO_KEYBOARD "); |
la00noix | 0:a56be39653d0 | 57 | break; |
la00noix | 0:a56be39653d0 | 58 | case AUTO_MOUSE: |
la00noix | 0:a56be39653d0 | 59 | printf("AUTO_MOUSE "); |
la00noix | 0:a56be39653d0 | 60 | break; |
la00noix | 0:a56be39653d0 | 61 | // case AUTO_PS3: |
la00noix | 0:a56be39653d0 | 62 | // printf("AUTO_PS3 "); |
la00noix | 0:a56be39653d0 | 63 | // ParsePs3Report(data,len); |
la00noix | 0:a56be39653d0 | 64 | // break; |
la00noix | 0:a56be39653d0 | 65 | default: |
la00noix | 0:a56be39653d0 | 66 | printf("HUH "); |
la00noix | 0:a56be39653d0 | 67 | } |
la00noix | 0:a56be39653d0 | 68 | //printfBytes("data",data,len); |
la00noix | 0:a56be39653d0 | 69 | USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData); |
la00noix | 0:a56be39653d0 | 70 | } |
la00noix | 0:a56be39653d0 | 71 | |
la00noix | 0:a56be39653d0 | 72 | // Establish transfers for interrupt events |
la00noix | 0:a56be39653d0 | 73 | void AddAutoEvent(int device, InterfaceDescriptor* id, EndpointDescriptor* ed) |
la00noix | 0:a56be39653d0 | 74 | { |
la00noix | 0:a56be39653d0 | 75 | printf("message from endpoint %02X\r\n",ed->bEndpointAddress); |
la00noix | 0:a56be39653d0 | 76 | printf("Class Sub Proto: %02X %02X %02X\r\n",id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol); |
la00noix | 0:a56be39653d0 | 77 | //if ((ed->bmAttributes & 3) != ENDPOINT_INTERRUPT || !(ed->bEndpointAddress & 0x80)) |
la00noix | 0:a56be39653d0 | 78 | // return; |
la00noix | 0:a56be39653d0 | 79 | |
la00noix | 0:a56be39653d0 | 80 | // Make automatic interrupt enpoints for known devices |
la00noix | 0:a56be39653d0 | 81 | u32 evt = AUTOEVT(id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol); |
la00noix | 0:a56be39653d0 | 82 | printf("Evt: %08X \r\n",evt); |
la00noix | 0:a56be39653d0 | 83 | u8* dst = 0; |
la00noix | 0:a56be39653d0 | 84 | int len; |
la00noix | 0:a56be39653d0 | 85 | switch (evt) |
la00noix | 0:a56be39653d0 | 86 | { |
la00noix | 0:a56be39653d0 | 87 | case AUTO_MOUSE: |
la00noix | 0:a56be39653d0 | 88 | dst = auto_mouse; |
la00noix | 0:a56be39653d0 | 89 | len = sizeof(auto_mouse); |
la00noix | 0:a56be39653d0 | 90 | break; |
la00noix | 0:a56be39653d0 | 91 | case AUTO_KEYBOARD: |
la00noix | 0:a56be39653d0 | 92 | dst = auto_keyboard; |
la00noix | 0:a56be39653d0 | 93 | len = sizeof(auto_keyboard); |
la00noix | 0:a56be39653d0 | 94 | break; |
la00noix | 0:a56be39653d0 | 95 | // case AUTO_PS3: |
la00noix | 0:a56be39653d0 | 96 | // printf("PS3 event ? \r\n"); |
la00noix | 0:a56be39653d0 | 97 | // dst = auto_ps3; |
la00noix | 0:a56be39653d0 | 98 | // len = sizeof(auto_ps3); |
la00noix | 0:a56be39653d0 | 99 | default: |
la00noix | 0:a56be39653d0 | 100 | printf("Interrupt endpoint %02X %08X\r\n",ed->bEndpointAddress,evt); |
la00noix | 0:a56be39653d0 | 101 | break; |
la00noix | 0:a56be39653d0 | 102 | } |
la00noix | 0:a56be39653d0 | 103 | if (dst) |
la00noix | 0:a56be39653d0 | 104 | { |
la00noix | 0:a56be39653d0 | 105 | printf("Auto Event for %02X %08X\r\n",ed->bEndpointAddress,evt); |
la00noix | 0:a56be39653d0 | 106 | USBInterruptTransfer(device,ed->bEndpointAddress,dst,len,AutoEventCallback,(void*)evt); |
la00noix | 0:a56be39653d0 | 107 | } |
la00noix | 0:a56be39653d0 | 108 | } |
la00noix | 0:a56be39653d0 | 109 | |
la00noix | 0:a56be39653d0 | 110 | void PrintString(int device, int i) |
la00noix | 0:a56be39653d0 | 111 | { |
la00noix | 0:a56be39653d0 | 112 | u8 buffer[256]; |
la00noix | 0:a56be39653d0 | 113 | int le = GetDescriptor(device,DESCRIPTOR_TYPE_STRING,i,buffer,255); |
la00noix | 0:a56be39653d0 | 114 | if (le < 0) |
la00noix | 0:a56be39653d0 | 115 | return; |
la00noix | 0:a56be39653d0 | 116 | char* dst = (char*)buffer; |
la00noix | 0:a56be39653d0 | 117 | for (int j = 2; j < le; j += 2) |
la00noix | 0:a56be39653d0 | 118 | *dst++ = buffer[j]; |
la00noix | 0:a56be39653d0 | 119 | *dst = 0; |
la00noix | 0:a56be39653d0 | 120 | printf("%d:%s\r\n",i,(const char*)buffer); |
la00noix | 0:a56be39653d0 | 121 | } |
la00noix | 0:a56be39653d0 | 122 | |
la00noix | 0:a56be39653d0 | 123 | // Walk descriptors and create endpoints for a given device |
la00noix | 0:a56be39653d0 | 124 | int StartAutoEvent(int device, int configuration, int interfaceNumber) |
la00noix | 0:a56be39653d0 | 125 | { |
la00noix | 0:a56be39653d0 | 126 | |
la00noix | 0:a56be39653d0 | 127 | printf("StartAutoEvent \r\n"); |
la00noix | 0:a56be39653d0 | 128 | |
la00noix | 0:a56be39653d0 | 129 | u8 buffer[255]; |
la00noix | 0:a56be39653d0 | 130 | int err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255); |
la00noix | 0:a56be39653d0 | 131 | if (err < 0) |
la00noix | 0:a56be39653d0 | 132 | return err; |
la00noix | 0:a56be39653d0 | 133 | |
la00noix | 0:a56be39653d0 | 134 | int len = buffer[2] | (buffer[3] << 8); |
la00noix | 0:a56be39653d0 | 135 | u8* d = buffer; |
la00noix | 0:a56be39653d0 | 136 | u8* end = d + len; |
la00noix | 0:a56be39653d0 | 137 | while (d < end) |
la00noix | 0:a56be39653d0 | 138 | { |
la00noix | 0:a56be39653d0 | 139 | if (d[1] == DESCRIPTOR_TYPE_INTERFACE) |
la00noix | 0:a56be39653d0 | 140 | { |
la00noix | 0:a56be39653d0 | 141 | InterfaceDescriptor* id = (InterfaceDescriptor*)d; |
la00noix | 0:a56be39653d0 | 142 | if (id->bInterfaceNumber == interfaceNumber) |
la00noix | 0:a56be39653d0 | 143 | { |
la00noix | 0:a56be39653d0 | 144 | d += d[0]; |
la00noix | 0:a56be39653d0 | 145 | while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE) |
la00noix | 0:a56be39653d0 | 146 | { |
la00noix | 0:a56be39653d0 | 147 | if (d[1] == DESCRIPTOR_TYPE_ENDPOINT) |
la00noix | 0:a56be39653d0 | 148 | AddAutoEvent(device,id,(EndpointDescriptor*)d); |
la00noix | 0:a56be39653d0 | 149 | d += d[0]; |
la00noix | 0:a56be39653d0 | 150 | } |
la00noix | 0:a56be39653d0 | 151 | } |
la00noix | 0:a56be39653d0 | 152 | } |
la00noix | 0:a56be39653d0 | 153 | d += d[0]; |
la00noix | 0:a56be39653d0 | 154 | } |
la00noix | 0:a56be39653d0 | 155 | return 0; |
la00noix | 0:a56be39653d0 | 156 | } |
la00noix | 0:a56be39653d0 | 157 | |
la00noix | 0:a56be39653d0 | 158 | /* |
la00noix | 0:a56be39653d0 | 159 | int StartPS3Event(int device, int configuration, int interfaceNumber) |
la00noix | 0:a56be39653d0 | 160 | { |
la00noix | 0:a56be39653d0 | 161 | |
la00noix | 0:a56be39653d0 | 162 | printf("StartPS3Event \r\n"); |
la00noix | 0:a56be39653d0 | 163 | |
la00noix | 0:a56be39653d0 | 164 | EndpointDescriptor* ep; |
la00noix | 0:a56be39653d0 | 165 | |
la00noix | 0:a56be39653d0 | 166 | u8 buf[4]; |
la00noix | 0:a56be39653d0 | 167 | buf[0] = 0x42; |
la00noix | 0:a56be39653d0 | 168 | buf[1] = 0x0c; |
la00noix | 0:a56be39653d0 | 169 | buf[2] = 0x00; |
la00noix | 0:a56be39653d0 | 170 | buf[3] = 0x00; |
la00noix | 0:a56be39653d0 | 171 | |
la00noix | 0:a56be39653d0 | 172 | u8 buf2[8]; |
la00noix | 0:a56be39653d0 | 173 | u8 buf3[8]; |
la00noix | 0:a56be39653d0 | 174 | |
la00noix | 0:a56be39653d0 | 175 | buf2[0] = 0x01; |
la00noix | 0:a56be39653d0 | 176 | buf2[1] = 0x00; |
la00noix | 0:a56be39653d0 | 177 | buf2[2] = 0x00; |
la00noix | 0:a56be39653d0 | 178 | buf2[3] = 0x02; |
la00noix | 0:a56be39653d0 | 179 | buf2[4] = 0x72; |
la00noix | 0:a56be39653d0 | 180 | buf2[5] = 0xAD; |
la00noix | 0:a56be39653d0 | 181 | buf2[6] = 0xF3; |
la00noix | 0:a56be39653d0 | 182 | buf2[7] = 0x5B; |
la00noix | 0:a56be39653d0 | 183 | |
la00noix | 0:a56be39653d0 | 184 | |
la00noix | 0:a56be39653d0 | 185 | |
la00noix | 0:a56be39653d0 | 186 | |
la00noix | 0:a56be39653d0 | 187 | int result; |
la00noix | 0:a56be39653d0 | 188 | int err; |
la00noix | 0:a56be39653d0 | 189 | |
la00noix | 0:a56be39653d0 | 190 | u8 buffer[255]; |
la00noix | 0:a56be39653d0 | 191 | err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255); |
la00noix | 0:a56be39653d0 | 192 | if (err < 0) |
la00noix | 0:a56be39653d0 | 193 | return err; |
la00noix | 0:a56be39653d0 | 194 | |
la00noix | 0:a56be39653d0 | 195 | |
la00noix | 0:a56be39653d0 | 196 | |
la00noix | 0:a56be39653d0 | 197 | //configure the device |
la00noix | 0:a56be39653d0 | 198 | //err = USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_STANDARD|RECIPIENT_DEVICE, SET_CONFIGURATION, 1, 0, 0, 0, 0, 0 ); |
la00noix | 0:a56be39653d0 | 199 | err = SetConfiguration(device,1); |
la00noix | 0:a56be39653d0 | 200 | printf("set config result = %d\r\n", err); |
la00noix | 0:a56be39653d0 | 201 | |
la00noix | 0:a56be39653d0 | 202 | // get Mac address |
la00noix | 0:a56be39653d0 | 203 | //err = USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_DEVICE, HID_REQUEST_GET_REPORT, 0x03f5, 0, buf3, sizeof(buf3), 0, 0 ); |
la00noix | 0:a56be39653d0 | 204 | //printf("get Mac to %02X:%02X:%02X:%02X:%02X:%02X , result = %d\r\n", buf3[2], buf3[3], buf3[4], buf3[5], buf3[6], buf3[7], err); |
la00noix | 0:a56be39653d0 | 205 | |
la00noix | 0:a56be39653d0 | 206 | // set Mac address |
la00noix | 0:a56be39653d0 | 207 | err = USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_SET_REPORT, 0x03f5, 0, buf2, sizeof(buf2), 0, 0 ); |
la00noix | 0:a56be39653d0 | 208 | printf("set Mac to %02X:%02X:%02X:%02X:%02X:%02X , result = %d\r\n", buf2[2], buf2[3], buf2[4], buf2[5], buf2[6], buf2[7], err); |
la00noix | 0:a56be39653d0 | 209 | |
la00noix | 0:a56be39653d0 | 210 | // get Mac address |
la00noix | 0:a56be39653d0 | 211 | //err = USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_DEVICE, HID_REQUEST_GET_REPORT, 0x03f5, 0, buf3, sizeof(buf3), 0, 0 ); |
la00noix | 0:a56be39653d0 | 212 | //printf("get Mac to %02X:%02X:%02X:%02X:%02X:%02X , result = %d\r\n", buf3[2], buf3[3], buf3[4], buf3[5], buf3[6], buf3[7], err); |
la00noix | 0:a56be39653d0 | 213 | |
la00noix | 0:a56be39653d0 | 214 | err = USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_SET_REPORT, 0x03f4,0, buf, sizeof(buf), 0, 0 ); |
la00noix | 0:a56be39653d0 | 215 | printf("set report result = %d\r\n", err); |
la00noix | 0:a56be39653d0 | 216 | //USBTransfer(device,0,DEVICE_TO_HOST,buf,sizeof(buf),0,0); |
la00noix | 0:a56be39653d0 | 217 | |
la00noix | 0:a56be39653d0 | 218 | int len = buffer[2] | (buffer[3] << 8); |
la00noix | 0:a56be39653d0 | 219 | u8* d = buffer; |
la00noix | 0:a56be39653d0 | 220 | u8* end = d + len; |
la00noix | 0:a56be39653d0 | 221 | while (d < end) |
la00noix | 0:a56be39653d0 | 222 | { |
la00noix | 0:a56be39653d0 | 223 | if (d[1] == DESCRIPTOR_TYPE_INTERFACE) |
la00noix | 0:a56be39653d0 | 224 | { |
la00noix | 0:a56be39653d0 | 225 | InterfaceDescriptor* id = (InterfaceDescriptor*)d; |
la00noix | 0:a56be39653d0 | 226 | if (id->bInterfaceNumber == interfaceNumber) |
la00noix | 0:a56be39653d0 | 227 | { |
la00noix | 0:a56be39653d0 | 228 | d += d[0]; |
la00noix | 0:a56be39653d0 | 229 | while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE) |
la00noix | 0:a56be39653d0 | 230 | { |
la00noix | 0:a56be39653d0 | 231 | if (d[1] == DESCRIPTOR_TYPE_ENDPOINT) |
la00noix | 0:a56be39653d0 | 232 | ep = (EndpointDescriptor*)d; |
la00noix | 0:a56be39653d0 | 233 | |
la00noix | 0:a56be39653d0 | 234 | if (ep->bEndpointAddress == 0x02) { |
la00noix | 0:a56be39653d0 | 235 | printf("PS3 input endpoint (0x02) found\r\n"); |
la00noix | 0:a56be39653d0 | 236 | |
la00noix | 0:a56be39653d0 | 237 | } |
la00noix | 0:a56be39653d0 | 238 | if (ep->bEndpointAddress == 0x81) { |
la00noix | 0:a56be39653d0 | 239 | printf("PS3 output endpoint (0x81) found\r\n"); |
la00noix | 0:a56be39653d0 | 240 | AddAutoEvent(device,id,(EndpointDescriptor*)d); |
la00noix | 0:a56be39653d0 | 241 | } |
la00noix | 0:a56be39653d0 | 242 | d += d[0]; |
la00noix | 0:a56be39653d0 | 243 | } |
la00noix | 0:a56be39653d0 | 244 | } |
la00noix | 0:a56be39653d0 | 245 | } |
la00noix | 0:a56be39653d0 | 246 | d += d[0]; |
la00noix | 0:a56be39653d0 | 247 | } |
la00noix | 0:a56be39653d0 | 248 | return 0; |
la00noix | 0:a56be39653d0 | 249 | } |
la00noix | 0:a56be39653d0 | 250 | */ |
la00noix | 0:a56be39653d0 | 251 | |
la00noix | 0:a56be39653d0 | 252 | // Implemented in main.cpp |
la00noix | 0:a56be39653d0 | 253 | int OnDiskInsert(int device); |
la00noix | 0:a56be39653d0 | 254 | |
la00noix | 0:a56be39653d0 | 255 | // Implemented in TestShell.cpp |
la00noix | 0:a56be39653d0 | 256 | int OnBluetoothInsert(int device); |
la00noix | 0:a56be39653d0 | 257 | void convert(u8 *mac){ |
la00noix | 0:a56be39653d0 | 258 | LocalFileSystem local("local"); |
la00noix | 0:a56be39653d0 | 259 | FILE *fp; |
la00noix | 0:a56be39653d0 | 260 | fp = fopen("/local/data.p3b", "r"); |
la00noix | 0:a56be39653d0 | 261 | if(fp==NULL){ |
la00noix | 0:a56be39653d0 | 262 | fp = fopen("/local/data.p3b", "w"); |
la00noix | 0:a56be39653d0 | 263 | fprintf(fp,"00:1B:DC:06:C7:C7"); |
la00noix | 0:a56be39653d0 | 264 | fclose(fp); |
la00noix | 0:a56be39653d0 | 265 | fp = fopen("/local/data.p3b", "r"); |
la00noix | 0:a56be39653d0 | 266 | } |
la00noix | 0:a56be39653d0 | 267 | char a[20]; |
la00noix | 0:a56be39653d0 | 268 | fgets(a,sizeof(a),fp); |
la00noix | 0:a56be39653d0 | 269 | char b[6][5]; |
la00noix | 0:a56be39653d0 | 270 | char *end; |
la00noix | 0:a56be39653d0 | 271 | for(int i=0;i<6;i++){ |
la00noix | 0:a56be39653d0 | 272 | b[i][0]='0'; |
la00noix | 0:a56be39653d0 | 273 | b[i][1]='x'; |
la00noix | 0:a56be39653d0 | 274 | b[i][2]=a[i*3]; |
la00noix | 0:a56be39653d0 | 275 | b[i][3]=a[1+i*3]; |
la00noix | 0:a56be39653d0 | 276 | b[i][4]='\n'; |
la00noix | 0:a56be39653d0 | 277 | mac[i]=(u8)strtol(b[i],&end,0); |
la00noix | 0:a56be39653d0 | 278 | } |
la00noix | 0:a56be39653d0 | 279 | fclose(fp); |
la00noix | 0:a56be39653d0 | 280 | } |
la00noix | 0:a56be39653d0 | 281 | |
la00noix | 0:a56be39653d0 | 282 | |
la00noix | 0:a56be39653d0 | 283 | void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc) |
la00noix | 0:a56be39653d0 | 284 | { |
la00noix | 0:a56be39653d0 | 285 | printf("LoadDevice %d %02X:%02X:%02X\r\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol); |
la00noix | 0:a56be39653d0 | 286 | char s[128]; |
la00noix | 0:a56be39653d0 | 287 | //u8 my_mac[6] = {0x00, 0x02, 0x72, 0xD0, 0x82, 0xF7}; // mac address of my Bluetooth device |
la00noix | 0:a56be39653d0 | 288 | u8 my_mac[6]; |
la00noix | 0:a56be39653d0 | 289 | convert(my_mac); |
la00noix | 0:a56be39653d0 | 290 | |
la00noix | 0:a56be39653d0 | 291 | u8 buf2[6]; |
la00noix | 0:a56be39653d0 | 292 | |
la00noix | 0:a56be39653d0 | 293 | buf2[0] = 0x00; |
la00noix | 0:a56be39653d0 | 294 | buf2[1] = 0x02; |
la00noix | 0:a56be39653d0 | 295 | buf2[2] = 0x72; |
la00noix | 0:a56be39653d0 | 296 | buf2[3] = 0xAD; |
la00noix | 0:a56be39653d0 | 297 | buf2[4] = 0xF3; |
la00noix | 0:a56be39653d0 | 298 | buf2[5] = 0x5B; |
la00noix | 0:a56be39653d0 | 299 | |
la00noix | 0:a56be39653d0 | 300 | |
la00noix | 0:a56be39653d0 | 301 | for (int i = 1; i < 3; i++) |
la00noix | 0:a56be39653d0 | 302 | { |
la00noix | 0:a56be39653d0 | 303 | if (GetString(device,i,s,sizeof(s)) < 0) |
la00noix | 0:a56be39653d0 | 304 | break; |
la00noix | 0:a56be39653d0 | 305 | printf("%d: %s\r\n",i,s); |
la00noix | 0:a56be39653d0 | 306 | } |
la00noix | 0:a56be39653d0 | 307 | |
la00noix | 0:a56be39653d0 | 308 | switch (interfaceDesc->bInterfaceClass) |
la00noix | 0:a56be39653d0 | 309 | { |
la00noix | 0:a56be39653d0 | 310 | case CLASS_MASS_STORAGE: |
la00noix | 0:a56be39653d0 | 311 | if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50) |
la00noix | 0:a56be39653d0 | 312 | OnDiskInsert(device); // it's SCSI! |
la00noix | 0:a56be39653d0 | 313 | break; |
la00noix | 0:a56be39653d0 | 314 | case CLASS_WIRELESS_CONTROLLER: |
la00noix | 0:a56be39653d0 | 315 | if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01) |
la00noix | 0:a56be39653d0 | 316 | OnBluetoothInsert(device); // it's bluetooth! |
la00noix | 0:a56be39653d0 | 317 | break; |
la00noix | 0:a56be39653d0 | 318 | case CLASS_HID: |
la00noix | 0:a56be39653d0 | 319 | //追加部分 |
la00noix | 0:a56be39653d0 | 320 | /*if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01) |
la00noix | 0:a56be39653d0 | 321 | OnBluetoothInsert(device); // it's bluetooth! |
la00noix | 0:a56be39653d0 | 322 | break; |
la00noix | 0:a56be39653d0 | 323 | *///追加部分ここまで |
la00noix | 0:a56be39653d0 | 324 | printf("idVendor = %04X idProduct = %04X \r\n",deviceDesc->idVendor,deviceDesc->idProduct); |
la00noix | 0:a56be39653d0 | 325 | //printf("device = %d configuration = %d interfaceNumber = %d\r\n", device, configuration, interfaceNumber); |
la00noix | 0:a56be39653d0 | 326 | //if (deviceDesc->idVendor == 0x054C && deviceDesc->idProduct == 0x0268) StartPS3Event(device,1,0); |
la00noix | 0:a56be39653d0 | 327 | if (deviceDesc->idVendor == 0x054C && deviceDesc->idProduct == 0x0268) { |
la00noix | 0:a56be39653d0 | 328 | Ps3USB _Ps3USB(device,1,0); |
la00noix | 0:a56be39653d0 | 329 | |
la00noix | 0:a56be39653d0 | 330 | _Ps3USB.SetPair(my_mac); |
la00noix | 0:a56be39653d0 | 331 | _Ps3USB.Enable(); |
la00noix | 0:a56be39653d0 | 332 | _Ps3USB.Led(1); |
la00noix | 0:a56be39653d0 | 333 | _Ps3USB.Rumble(0x20,0xff,0x20,0xff); |
la00noix | 0:a56be39653d0 | 334 | _Ps3USB.ShowPair(); |
la00noix | 0:a56be39653d0 | 335 | |
la00noix | 0:a56be39653d0 | 336 | } |
la00noix | 0:a56be39653d0 | 337 | else StartAutoEvent(device,1,0); |
la00noix | 0:a56be39653d0 | 338 | break; |
la00noix | 0:a56be39653d0 | 339 | default: |
la00noix | 0:a56be39653d0 | 340 | printf("Not yet supported \r\n"); |
la00noix | 0:a56be39653d0 | 341 | //StartAutoEvent(device,1,0); |
la00noix | 0:a56be39653d0 | 342 | break; |
la00noix | 0:a56be39653d0 | 343 | } |
la00noix | 0:a56be39653d0 | 344 | } |