This commit is contained in:
CrazyRedMachine
2020-06-13 00:10:56 +02:00
parent b2d21d7f99
commit d7260edda8
13 changed files with 1596 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.14)
project(popn_modeswitch)
set(CMAKE_CXX_STANDARD 14)
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)
+78
View File
@@ -0,0 +1,78 @@
/* TO BE COMPILED WITH MINGW */
/* Visual C++ compilation didn't work for me on the BemaniPC (invalid win32 application) */
#include <windows.h>
#include <fstream>
int main(int argc, char* argv[])
{
FILE *file;
char path[256];
HANDLE hidHandle;
char OutputReport[5];
int res;
int mode;
DWORD BytesWritten = 0;
if ( argc < 2 )
{
printf("Usage: %s mode\r\n",argv[0]);
return 1;
}
mode = atoi(argv[1]);
if ( mode < 0 || mode > 3 )
{
printf("Invalid mode value %d\r\n", mode);
return 2;
}
file = fopen("devicepath.dat", "r");
while ( fgets(path,256,file) != NULL )
{
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 )
{
printf("Couldn't open device. Make sure devicepath.dat contains the correct path.\r\n");
return 3;
}
OutputReport[0] = 0x05; //report ID
OutputReport[1] = 0x00;
OutputReport[2] = 0x00;
OutputReport[3] = 0x00;
OutputReport[4] = mode+16; //mode+magicbit
WriteFile(hidHandle, OutputReport, 5, &BytesWritten, NULL);
if ( BytesWritten == 5 )
{
res = 0;
printf("Succesfully switched to mode %u ", mode);
switch(mode)
{
case 0:
printf("(reactive)\r\n");
break;
case 1:
printf("(HID)\r\n");
break;
case 2:
printf("(mixed)\r\n");
break;
case 3:
printf("(invert)\r\n");
}
}
else
{
printf("Error sending HID report (%u bytes written)\r\n",BytesWritten);
res = 4;
}
CloseHandle(hidHandle);
return res;
}