Cleaned log and converted int ptr to vector.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
REGISTER_LIGHTS_DRIVER_CLASS(HidBlueDot);
|
||||
|
||||
LightsDriver_HidBlueDot::LightsDriver_HidBlueDot() :
|
||||
dev{ VID, pids },
|
||||
dev{ VID, PID },
|
||||
m_iCabData{ 0 },
|
||||
m_iPadData{ 0 }
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#define VID 0x04BD
|
||||
#define PID 0xBD
|
||||
|
||||
static constexpr int pids[] = { PID };
|
||||
|
||||
class LightsDriver_HidBlueDot : public LightsDriver
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -9,7 +9,7 @@ REGISTER_LIGHTS_DRIVER_CLASS(PacDrive);
|
||||
static Preference<RString> g_sPacDriveLightOrdering("PacDriveLightOrdering", "openitg");
|
||||
int iPacDriveLightOrder = 0;
|
||||
|
||||
LightsDriver_PacDrive::LightsDriver_PacDrive() : dev{PACDRIVE_VID, GetPids(), PACDRIVE_INTERFACE}
|
||||
LightsDriver_PacDrive::LightsDriver_PacDrive() : dev{PACDRIVE_VID, make_pids(PACDRIVE_PID, PACDRIVE_PID_MAX), PACDRIVE_INTERFACE}
|
||||
{
|
||||
prev_led_state.raw = 0;
|
||||
memset(state.raw_state, 0x00, sizeof(state.raw_state));
|
||||
|
||||
@@ -28,16 +28,6 @@
|
||||
#define PACDRIVE_PID 0x1500
|
||||
#define PACDRIVE_PID_MAX 8
|
||||
|
||||
static constexpr int* GetPids()
|
||||
{
|
||||
int vec[PACDRIVE_PID]{0};
|
||||
|
||||
for (int i = 0; i < PACDRIVE_PID_MAX; i++)
|
||||
vec[i] = PACDRIVE_PID + i;
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
#define PACDRIVE_INTERFACE 0
|
||||
|
||||
// the first byte of the buffer is a static report id.
|
||||
|
||||
@@ -8,7 +8,7 @@ REGISTER_LIGHTS_DRIVER_CLASS(snek);
|
||||
|
||||
|
||||
LightsDriver_snek::LightsDriver_snek() :
|
||||
dev{ SNEK_VID , pids, SNEK_LIGHTING_INTERFACENUM },
|
||||
dev{ SNEK_VID , SNEK_PID, SNEK_LIGHTING_INTERFACENUM },
|
||||
stateChanged{ false },
|
||||
outputBuffer{0}
|
||||
{
|
||||
|
||||
@@ -95,9 +95,6 @@ enum SnekLightIndex
|
||||
#define SNEK_INDEX_DANCE_P2_LEFT SNEK_LIGHTINDEX_CN11_FL3
|
||||
#define SNEK_INDEX_DANCE_P2_RIGHT SNEK_LIGHTINDEX_CN11_FL4
|
||||
|
||||
static constexpr int pids[] = { SNEK_PID };
|
||||
|
||||
|
||||
class LightsDriver_snek : public LightsDriver
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
REGISTER_LIGHTS_DRIVER_CLASS(stac);
|
||||
|
||||
LightsDriver_stac::LightsDriver_stac() :
|
||||
devs{ {STAC_VID , pids1, STAC_LIGHTING_INTERFACE}, {STAC_VID , pids2, STAC_LIGHTING_INTERFACE } },
|
||||
devs{ {STAC_VID , STAC_PID_P1, STAC_LIGHTING_INTERFACE}, {STAC_VID , STAC_PID_P2, STAC_LIGHTING_INTERFACE } },
|
||||
stateChanged{ false },
|
||||
outputBuffer{ {0} }
|
||||
{
|
||||
|
||||
@@ -47,10 +47,6 @@ enum StacLightIndex
|
||||
STAC_LIGHTINDEX_MAX
|
||||
};
|
||||
|
||||
static constexpr int pids1[] = { STAC_PID_P1 };
|
||||
static constexpr int pids2[] = { STAC_PID_P2 };
|
||||
|
||||
|
||||
class LightsDriver_stac : public LightsDriver
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "HidDevice.h"
|
||||
#include "RageLog.h"
|
||||
|
||||
HidDevice::HidDevice(int vid, const int pids[], int interfaceNum, bool autoReconnection, bool nonBlockingWrite) :
|
||||
HidDevice::HidDevice(int vid, const std::vector<int> pids, int interfaceNum, bool autoReconnection, bool nonBlockingWrite) :
|
||||
vid{ vid },
|
||||
pids{ pids },
|
||||
interfaceNum{ interfaceNum },
|
||||
@@ -13,13 +13,18 @@ HidDevice::HidDevice(int vid, const int pids[], int interfaceNum, bool autoRecon
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG->Warn("HID device with VID/PID %04x/%s not found.", vid, GetPidsString(pids).c_str());
|
||||
LOG->Warn("HidDevice %04x:%s: %d not found", vid, GetPidsString(pids).c_str(), interfaceNum);
|
||||
return;
|
||||
}
|
||||
else
|
||||
foundOnce = true;
|
||||
}
|
||||
|
||||
HidDevice::HidDevice(int vid, int pid, int interfaceNum, bool autoReconnection, bool nonBlockingWrite) :
|
||||
HidDevice(vid, make_pids(pid, 1), interfaceNum, autoReconnection, nonBlockingWrite)
|
||||
{
|
||||
}
|
||||
|
||||
HidDevice::~HidDevice()
|
||||
{
|
||||
Close();
|
||||
@@ -40,7 +45,7 @@ bool HidDevice::Open(const char* path)
|
||||
hid_set_nonblocking(handle, 1);
|
||||
|
||||
if(handle)
|
||||
LOG->Info("HidDevice opened %04x:%04x:%d by path %s", vid, GetPidsString(pids).c_str(), interfaceNum, path);
|
||||
LOG->Info("HidDevice %04x:%s: %d opened by path %s", vid, GetPidsString(pids).c_str(), interfaceNum, path);
|
||||
|
||||
return handle != nullptr;
|
||||
}
|
||||
@@ -80,11 +85,11 @@ bool HidDevice::FoundOnce()
|
||||
return foundOnce;
|
||||
}
|
||||
|
||||
const RString HidDevice::GetPidsString(const int pids[])
|
||||
const RString HidDevice::GetPidsString(const std::vector<int> pids)
|
||||
{
|
||||
RString pidsString;
|
||||
char pid[5] = { 0 };
|
||||
size_t size = sizeof(pids) / sizeof(pids[0]);
|
||||
size_t size = pids.size();
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
@@ -98,10 +103,10 @@ const RString HidDevice::GetPidsString(const int pids[])
|
||||
return pidsString;
|
||||
}
|
||||
|
||||
char* HidDevice::GetPath(int vid, const int pids[], int interfaceNumber)
|
||||
char* HidDevice::GetPath(int vid, const std::vector<int> pids, int interfaceNumber)
|
||||
{
|
||||
struct hid_device_info* devs, * cur_dev;
|
||||
size_t size = sizeof(pids) / sizeof(pids[0]);
|
||||
size_t size = pids.size();
|
||||
|
||||
devs = hid_enumerate(vid, 0);
|
||||
cur_dev = devs;
|
||||
@@ -138,28 +143,30 @@ char* HidDevice::GetPath(int vid, const int pids[], int interfaceNumber)
|
||||
int HidDevice::Read(unsigned char* data, size_t length)
|
||||
{
|
||||
if (!CheckConnection())
|
||||
return -1;
|
||||
return NOT_CONNECTED;
|
||||
|
||||
int result = hid_read(handle, data, length);
|
||||
|
||||
if (result == -1)
|
||||
if (result == FAIL)
|
||||
{
|
||||
LOG->Warn("HID device with VID/PID %04x/%s read failed. Fail reason %ls", vid, GetPidsString(pids).c_str(), GetError());
|
||||
LOG->Warn("HidDevice %04x:%s: %d read failed. Fail reason %ls", vid, GetPidsString(pids).c_str(), interfaceNum, GetError());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void HidDevice::Write(const unsigned char* data, size_t length)
|
||||
int HidDevice::Write(const unsigned char* data, size_t length)
|
||||
{
|
||||
if (!CheckConnection())
|
||||
return;
|
||||
return NOT_CONNECTED;
|
||||
|
||||
int result = hid_write(handle, data, length);
|
||||
|
||||
if (result != length)
|
||||
{
|
||||
LOG->Warn("HID device with VID/PID %04x/%s write failed. Fail reason %ls", vid, GetPidsString(pids).c_str(), GetError());
|
||||
LOG->Warn("HidDevice %04x:%s: %d write failed. Fail reason %ls", vid, GetPidsString(pids).c_str(), interfaceNum, GetError());
|
||||
Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,30 @@
|
||||
#define HidDevice_H
|
||||
|
||||
#include "hidapi.h"
|
||||
#include "vector"
|
||||
|
||||
#define FAIL -1
|
||||
#define NOT_CONNECTED -2
|
||||
|
||||
static std::vector<int> make_pids(int base_pid, int size)
|
||||
{
|
||||
std::vector<int> vec(size);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
vec[i] = base_pid + i;
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
class HidDevice
|
||||
{
|
||||
private:
|
||||
hid_device* handle{nullptr};
|
||||
|
||||
static const RString GetPidsString(const int pids[]);
|
||||
static const RString GetPidsString(const std::vector<int> pids);
|
||||
|
||||
int vid;
|
||||
const int* pids;
|
||||
const std::vector<int> pids;
|
||||
int interfaceNum = -1;
|
||||
bool autoReconnection = true;
|
||||
bool nonBlockingWrite = false;
|
||||
@@ -23,9 +37,10 @@ private:
|
||||
bool CheckConnection();
|
||||
const wchar_t* GetError();
|
||||
public:
|
||||
static char* GetPath(int vid, const int pids[], int interfaceNum = -1);
|
||||
static char* GetPath(int vid, const std::vector<int> pids, int interfaceNum = -1);
|
||||
|
||||
HidDevice(int vid, const int pids[], int interfaceNum = -1, bool autoReconnection = true, bool nonBlockingWrite = false);
|
||||
HidDevice(int vid, const std::vector<int> pids, int interfaceNum = -1, bool autoReconnection = true, bool nonBlockingWrite = false);
|
||||
HidDevice(int vid, int pid, int interfaceNum = -1, bool autoReconnection = true, bool nonBlockingWrite = false);
|
||||
|
||||
virtual ~HidDevice();
|
||||
|
||||
@@ -33,7 +48,7 @@ public:
|
||||
bool FoundOnce();
|
||||
|
||||
int Read(unsigned char* data, size_t length);
|
||||
void Write(const unsigned char* data, size_t length);
|
||||
int Write(const unsigned char* data, size_t length);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user