ezusb driver and optional devicepath.dat
This commit is contained in:
Binary file not shown.
@@ -7,11 +7,4 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
|
||||
include_directories(${popn_modeswitch_SOURCE_DIR})
|
||||
link_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
# STATIC LINK HID
|
||||
find_library(HIDDLL NAMES hid PATHS ${CMAKE_SOURCE_DIR}/lib)
|
||||
message(STATUS "find_library for hid returned ${HIDDLL}")
|
||||
add_library(hid MODULE IMPORTED)
|
||||
set_property(TARGET hid PROPERTY IMPORTED_LOCATION "${HIDDLL}")
|
||||
|
||||
add_executable(modeswitch modeswitch.cpp)
|
||||
target_link_libraries(modeswitch hid)
|
||||
add_executable(modeswitch modeswitch.cpp)
|
||||
@@ -1,13 +1,61 @@
|
||||
/* TO BE COMPILED WITH MINGW */
|
||||
/* Visual C++ compilation didn't work for me on the BemaniPC (invalid win32 application) */
|
||||
#define WINVER 0x0500
|
||||
#include <windows.h>
|
||||
#include <fstream>
|
||||
|
||||
HANDLE g_hidHandle;
|
||||
|
||||
/**
|
||||
* Initialize the g_hidHandle global variable
|
||||
* It will attempt to read paths from devicepath.dat file if it exists until it finds one which works.
|
||||
* If nothing is found, as a last resort it will try the two default paths from the Due and Leonardo
|
||||
* versions of the firmware.
|
||||
*
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
static int controller_init(){
|
||||
FILE *file;
|
||||
char path[256];
|
||||
|
||||
file = fopen("devicepath.dat", "r");
|
||||
if (file == NULL)
|
||||
{
|
||||
goto last_resort;
|
||||
}
|
||||
|
||||
while ( fgets(path,256,file) != NULL )
|
||||
{
|
||||
path[strcspn(path, "\r\n")] = 0;
|
||||
g_hidHandle = CreateFile(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if ( g_hidHandle != INVALID_HANDLE_VALUE )
|
||||
break;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
if ( g_hidHandle == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
goto last_resort;
|
||||
}
|
||||
return 0;
|
||||
|
||||
last_resort:
|
||||
g_hidHandle = CreateFile("\\\\?\\HID#VID_2341&PID_003E&MI_02#7&3156e204&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}",
|
||||
GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if ( g_hidHandle != INVALID_HANDLE_VALUE )
|
||||
return 0;
|
||||
|
||||
g_hidHandle = CreateFile("\\\\?\\HID#VID_2341&PID_8036&MI_02#7&63200bf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}",
|
||||
GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if ( g_hidHandle != INVALID_HANDLE_VALUE )
|
||||
return 0;
|
||||
|
||||
printf("Couldn't open device. Make sure devicepath.dat exists and contains the correct path.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE *file;
|
||||
char path[256];
|
||||
HANDLE hidHandle;
|
||||
char OutputReport[5];
|
||||
int res;
|
||||
int mode;
|
||||
@@ -25,18 +73,8 @@ int main(int argc, char* argv[])
|
||||
printf("Invalid mode value %d\r\n", mode);
|
||||
return 2;
|
||||
}
|
||||
|
||||
file = fopen("devicepath.dat", "r");
|
||||
while ( fgets(path,256,file) != NULL )
|
||||
{
|
||||
path[strcspn(path, "\r\n")] = 0;
|
||||
hidHandle = CreateFile(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if ( hidHandle != INVALID_HANDLE_VALUE )
|
||||
break;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
if ( hidHandle == INVALID_HANDLE_VALUE )
|
||||
|
||||
if ( controller_init() == -1 )
|
||||
{
|
||||
printf("Couldn't open device. Make sure devicepath.dat contains the correct path.\r\n");
|
||||
return 3;
|
||||
@@ -48,7 +86,7 @@ int main(int argc, char* argv[])
|
||||
OutputReport[3] = 0x00;
|
||||
OutputReport[4] = mode+16; //mode+magicbit
|
||||
|
||||
WriteFile(hidHandle, OutputReport, 5, &BytesWritten, NULL);
|
||||
WriteFile(g_hidHandle, OutputReport, 5, &BytesWritten, NULL);
|
||||
if ( BytesWritten == 5 )
|
||||
{
|
||||
res = 0;
|
||||
@@ -74,6 +112,6 @@ int main(int argc, char* argv[])
|
||||
res = 4;
|
||||
}
|
||||
|
||||
CloseHandle(hidHandle);
|
||||
CloseHandle(g_hidHandle);
|
||||
return res;
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -38,6 +38,8 @@ The included devicepath.dat should work with both Due and Leonardo versions out
|
||||
|
||||
devicepath.dat file should contain the device path on its own on a single line. Multiple paths on multiple lines should work too in which case it will open the first valid path it finds.
|
||||
|
||||
If no valid path is found or if there is no `devicepath.dat` file, it will attempt to open the default paths from the Due and Leonardo versions (same as the ones found in this included devicepath file).
|
||||
|
||||
### spicetools
|
||||
|
||||
open ```%appdata%/spicetools.xml```, look for a "devid" value starting with ```\\?\HID#VID_2341&PID_003E``` (Due) or ```\\?\HID#VID_2341&PID_8036``` (Leonardo)
|
||||
|
||||
Reference in New Issue
Block a user