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