Modifying find_usb_serial_port() to return a vector
This commit is contained in:
parent
00cc6978a2
commit
1457831840
4 changed files with 42 additions and 34 deletions
|
|
@ -17,16 +17,21 @@
|
||||||
|
|
||||||
void DetectHuePlusControllers(std::vector<RGBController*> &rgb_controllers)
|
void DetectHuePlusControllers(std::vector<RGBController*> &rgb_controllers)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
HuePlusController* new_hueplus;
|
HuePlusController* new_hueplus;
|
||||||
RGBController_HuePlus* new_controller;
|
RGBController_HuePlus* new_controller;
|
||||||
|
|
||||||
std::string portname = find_usb_serial_port(NZXT_HUE_PLUS_VID, NZXT_HUE_PLUS_PID);
|
std::vector<std::string *> ports = find_usb_serial_port(NZXT_HUE_PLUS_VID, NZXT_HUE_PLUS_PID);
|
||||||
if( portname != "" )
|
|
||||||
{
|
|
||||||
new_hueplus = new HuePlusController();
|
|
||||||
new_hueplus->Initialize((char *)portname.c_str());
|
|
||||||
|
|
||||||
new_controller = new RGBController_HuePlus(new_hueplus);
|
for (i = 0; i < ports.size(); i++)
|
||||||
rgb_controllers.push_back(new_controller);
|
{
|
||||||
|
if( *ports[i] != "" )
|
||||||
|
{
|
||||||
|
new_hueplus = new HuePlusController();
|
||||||
|
new_hueplus->Initialize((char *)ports[i]->c_str());
|
||||||
|
|
||||||
|
new_controller = new RGBController_HuePlus(new_hueplus);
|
||||||
|
rgb_controllers.push_back(new_controller);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} /* DetectHuePlusControllers() */
|
} /* DetectHuePlusControllers() */
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
std::string find_usb_serial_port(unsigned short vid, unsigned short pid);
|
std::vector<std::string *> find_usb_serial_port(unsigned short vid, unsigned short pid);
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,14 @@
|
||||||
| |
|
| |
|
||||||
\*---------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
std::vector<std::string *> find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
{
|
{
|
||||||
std::string ret_string = "";
|
std::vector<std::string *> ret_vector;
|
||||||
DIR* dir;
|
std::string * tmp_string;
|
||||||
char symlink_path[1024] = {0};
|
DIR* dir;
|
||||||
struct dirent* ent;
|
char symlink_path[1024] = {0};
|
||||||
char vid_pid[10] = {0}; //Store VID/PID
|
struct dirent* ent;
|
||||||
|
char vid_pid[10] = {0}; //Store VID/PID
|
||||||
|
|
||||||
/*-----------------------------------------------------------------*\
|
/*-----------------------------------------------------------------*\
|
||||||
| Open /sys/class/tty |
|
| Open /sys/class/tty |
|
||||||
|
|
@ -32,7 +33,7 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
|
|
||||||
if(dir == NULL)
|
if(dir == NULL)
|
||||||
{
|
{
|
||||||
return ret_string;
|
return ret_vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------*\
|
/*-----------------------------------------------------------------*\
|
||||||
|
|
@ -109,10 +110,10 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret_string.append("/dev/");
|
tmp_string = new std::string("/dev/");
|
||||||
ret_string.append(port_string);
|
tmp_string->append(port_string);
|
||||||
|
|
||||||
return ret_string;
|
ret_vector.push_back(tmp_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,6 +122,6 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
ent = readdir(dir);
|
ent = readdir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_string;
|
return ret_vector;
|
||||||
|
|
||||||
} /* find_usb_serial_port() */
|
} /* find_usb_serial_port() */
|
||||||
|
|
|
||||||
|
|
@ -24,18 +24,19 @@
|
||||||
| |
|
| |
|
||||||
\*---------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
std::vector<std::string *> find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
{
|
{
|
||||||
std::string ret_str = "";
|
std::vector<std::string *> ret_vector;
|
||||||
HDEVINFO DeviceInfoSet;
|
std::string * tmp_string;
|
||||||
DWORD DeviceIndex = 0;
|
HDEVINFO DeviceInfoSet;
|
||||||
SP_DEVINFO_DATA DeviceInfoData;
|
DWORD DeviceIndex = 0;
|
||||||
const char * DevEnum = "USB";
|
SP_DEVINFO_DATA DeviceInfoData;
|
||||||
char ExpectedDeviceId[80] = {0}; //Store hardware id
|
const char * DevEnum = "USB";
|
||||||
char vid_pid[10] = {0}; //Store VID/PID
|
char ExpectedDeviceId[80] = {0}; //Store hardware id
|
||||||
char szBuffer[1024] = {0};
|
char vid_pid[10] = {0}; //Store VID/PID
|
||||||
DEVPROPTYPE ulPropertyType;
|
char szBuffer[1024] = {0};
|
||||||
DWORD dwSize = 0;
|
DEVPROPTYPE ulPropertyType;
|
||||||
|
DWORD dwSize = 0;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------*\
|
/*-----------------------------------------------------------------*\
|
||||||
| Create device hardware id |
|
| Create device hardware id |
|
||||||
|
|
@ -55,7 +56,7 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
|
|
||||||
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
|
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
return false;
|
return ret_vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------*\
|
/*-----------------------------------------------------------------*\
|
||||||
|
|
@ -102,8 +103,8 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
{
|
{
|
||||||
if(strncmp(pszPortName, "COM", 3) == 0)
|
if(strncmp(pszPortName, "COM", 3) == 0)
|
||||||
{
|
{
|
||||||
ret_str.append(pszPortName);
|
tmp_string = new std::string(pszPortName);
|
||||||
return ret_str;
|
ret_vector.push_back(tmp_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,6 +120,6 @@ std::string find_usb_serial_port(unsigned short vid, unsigned short pid)
|
||||||
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
|
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_str;
|
return ret_vector;
|
||||||
|
|
||||||
} /* find_usb_serial_port() */
|
} /* find_usb_serial_port() */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue