Commit 638d273a authored by Pila's avatar Pila

Added wait before closing on error

parent 03461513
Pipeline #582010 skipped
...@@ -55,16 +55,18 @@ int playNoteOnSteamController(libusb_device_handle *dev_handle, unsigned int not ...@@ -55,16 +55,18 @@ int playNoteOnSteamController(libusb_device_handle *dev_handle, unsigned int not
dataBlob[8] = repeatCount / 0xff; dataBlob[8] = repeatCount / 0xff;
int r; int r;
r = libusb_control_transfer(dev_handle,0x21,9,0x0300,2,dataBlob,64,1000); r = libusb_control_transfer(dev_handle,0x21,9,0x0300,2,dataBlob,64,1000); //Right haptic
if(r < 0) { if(r < 0) {
cout<<"Command Error "<<r<<endl; cout<<"Command Error "<<r<<endl;
std::cin.ignore();
return 1; return 1;
} }
dataBlob[2] = 0x01; dataBlob[2] = 0x01;
r = libusb_control_transfer(dev_handle,0x21,9,0x0300,2,dataBlob,64,1000); r = libusb_control_transfer(dev_handle,0x21,9,0x0300,2,dataBlob,64,1000); //Left haptic
if(r < 0) { if(r < 0) {
cout<<"Command Error "<<r<<endl; cout<<"Command Error "<<r<<endl;
std::cin.ignore();
return 1; return 1;
} }
return 0; return 0;
...@@ -77,30 +79,36 @@ int main() ...@@ -77,30 +79,36 @@ int main()
int r; //for return values int r; //for return values
unsigned int i; unsigned int i;
r = libusb_init(&ctx); //initialize the library for the session we just declared //Initializing LIBUSB
r = libusb_init(&ctx);
if(r < 0) { if(r < 0) {
cout<<"Init Error "<<r<<endl; cout<<"Init Error "<<r<<endl;
std::cin.ignore();
return 1; return 1;
} }
libusb_set_debug(ctx, 3); libusb_set_debug(ctx, 3);
//Open Steam Controller device
dev_handle = libusb_open_device_with_vid_pid(ctx, 0x28DE, 0x1102); // Wired Steam Controller VID & PID dev_handle = libusb_open_device_with_vid_pid(ctx, 0x28DE, 0x1102); // Wired Steam Controller VID & PID
if(dev_handle == NULL){ if(dev_handle == NULL){
cout<<"Cannot open device"<<endl; cout<<"Cannot open device"<<endl;
std::cin.ignore();
return 1; return 1;
} }
//Claim the USB interface controlling the haptic actuators
r = libusb_claim_interface(dev_handle,2); r = libusb_claim_interface(dev_handle,2);
if(r < 0) { if(r < 0) {
cout<<"Claim Error "<<r<<endl; cout<<"Claim Error "<<r<<endl;
std::cin.ignore();
return 1; return 1;
} }
cout<<"Ready \n"; cout<<"Steam Controller Singer by Pila\nReady. Press Enter to start \n";
std::cin.ignore(); std::cin.ignore();
//Play
for(i = 0 ; i < (sizeof(noteArray0) / sizeof(noteStruct)) ; i++){ for(i = 0 ; i < (sizeof(noteArray0) / sizeof(noteStruct)) ; i++){
unsigned int note = noteArray0[i].note; unsigned int note = noteArray0[i].note;
unsigned int delay = noteArray0[i].delay; unsigned int delay = noteArray0[i].delay;
...@@ -110,35 +118,8 @@ int main() ...@@ -110,35 +118,8 @@ int main()
if(r != 0) if(r != 0)
return 1; return 1;
} }
cout << "Playing : "<<note<<"\n"; cout << "Playing note " << note << " for "<< delay <<" ms \n";
delay_ms(delay); delay_ms(delay);
} }
/*unsigned char data[64] = {0x8f,
0x07,
0x01, //Trackpad select : 0x01 = left, 0x00 = right
0xff, //LSB Pulse High Duration
0xff, //MSB Pulse High Duration
0xff, //LSB Pulse Low Duration
0xff, //MSB Pulse Low Duration
0xff, //LSB Pulse repeat count
0x04, //MSB Pulse repeat count
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
while(1){
r = libusb_control_transfer(dev_handle,0x21,9,0x0300,2,data,64,1000);
if(r < 0) {
cout<<"Command Error "<<r<<endl;
return 1;
}
else {
cout<<"Command Success "<<r<<endl;
}
std::cin.ignore();
}
*/
return 0; return 0;
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.0, 2015-12-16T23:16:51. --> <!-- Written by QtCreator 3.6.0, 2015-12-19T00:58:27. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.5.1 MinGW 32bit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.5.1 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.5.1 MinGW 32bit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.5.1 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.55.win32_mingw492_kit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.55.win32_mingw492_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
...@@ -283,8 +283,8 @@ ...@@ -283,8 +283,8 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">steamcontrollersinger</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">steamcontrollersinger</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">steamcontrollersinger2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Users/Pila/Desktop/Steam Controller reverse Engineering/POC software/libusbtest/steamcontrollersinger.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Users/Pila/Desktop/Steam Controller reverse Engineering/POC software/steamcontrollersinger/steamcontrollersinger.pro</value>
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">steamcontrollersinger.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">steamcontrollersinger.pro</value>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment