Should build for both Windows and Linux now

This commit is contained in:
Adam Honse
2021-11-16 22:21:49 -06:00
parent fef63b4626
commit e700dbd003
4 changed files with 87 additions and 93 deletions

View File

@@ -12,33 +12,35 @@
#include <cstring>
#include "LogManager.h"
#ifdef _WIN32
#include <windows.h>
#include <fileapi.h>
#include <winioctl.h>
#include <nvme.h>
#else
#include <windows.h>
#include <fileapi.h>
#include <winioctl.h>
#include <nvme.h>
#endif
int XPGSpectrixS40GController::SetHandle(wchar_t buff[MAX_PATH])
{
wchar_t path[MAX_PATH];
#ifdef _WIN32
int XPGSpectrixS40GController::SetHandle(wchar_t buff[MAX_PATH]) {
wchar_t path[MAX_PATH];
wcscpy(path, L"\\\\?\\");
wcsncat(path, buff, MAX_PATH - 4);
for (size_t i = 0; i < MAX_PATH && path[i] != '\0'; i++) {
path[i] = tolower(path[i]);
}
wprintf(L"%s\n", path);
hDevice = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)0x0, OPEN_EXISTING, 0x0, (HANDLE)0x0);
if (hDevice == INVALID_HANDLE_VALUE) {
return 0;
}
return 1;
wcscpy(path, L"\\\\?\\");
wcsncat(path, buff, MAX_PATH - 4);
for(size_t i = 0; i < MAX_PATH && path[i] != '\0'; i++)
{
path[i] = tolower(path[i]);
}
#else
#endif
wprintf(L"%s\n", path);
hDevice = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)0x0, OPEN_EXISTING, 0x0, (HANDLE)0x0);
if(hDevice == INVALID_HANDLE_VALUE)
{
return 0;
}
return 1;
}
/*-----------------------------------------*\
| AsusAuraSMBusController.cpp |

View File

@@ -16,12 +16,8 @@
#define XPG_SPECTRIX_LED_COUNT ( 8 )
#ifdef _WIN32
#include <windows.h>
#include <fileapi.h>
#else
#endif
#include <windows.h>
#include <fileapi.h>
/*-----------------------------------------*\
| AsusAuraSMBusController.h |
@@ -33,7 +29,6 @@
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
@@ -123,15 +118,11 @@ public:
XPGSpectrixS40GController(aura_dev_id dev);
~XPGSpectrixS40GController();
#ifdef _WIN32
/*-----------------------------------------------------*\
| Windows specific function that allows the devices |
| handle to be passed from elsewhere once detected |
\*-----------------------------------------------------*/
int SetHandle(wchar_t dev_name[MAX_PATH]);
#else
#endif
std::string GetDeviceName();
std::string GetDeviceLocation();
@@ -156,18 +147,13 @@ public:
void AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz);
private:
#ifdef _WIN32
HANDLE hDevice;
#else
#endif
char device_name[16];
unsigned char config_table[64];
unsigned int led_count;
aura_register direct_reg;
aura_register effect_reg;
unsigned char channel_cfg;
i2c_smbus_interface * bus;
aura_dev_id dev;
};

View File

@@ -14,13 +14,36 @@
#include <vector>
#include <hidapi/hidapi.h>
#ifdef _WIN32
#define DEVBUFSIZE (128 * 1024)
#include <windows.h>
#include <fileapi.h>
#else
// TODO
#endif
#define DEVBUFSIZE (128 * 1024)
#include <windows.h>
#include <fileapi.h>
int Search(wchar_t *dev_name)
{
wchar_t buff[DEVBUFSIZE] = L"";
int wchar_count;
wchar_count = QueryDosDeviceW(NULL, buff, DEVBUFSIZE);
if(wchar_count == 0)
{
return 0;
}
for(int i = 0; i < wchar_count; i++)
{
if(wcsstr(buff + i, L"SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S40#"))
{
wcsncpy(dev_name, buff + i, MAX_PATH);
(dev_name)[MAX_PATH - 1] = '\0';
return 1;
}
i += wcslen(buff + i);
}
return 0;
}
/******************************************************************************************\
* *
@@ -31,52 +54,29 @@
* *
\******************************************************************************************/
#ifdef _WIN32
int Search(wchar_t *dev_name) {
wchar_t buff[DEVBUFSIZE] = L"";
int wchar_count;
wchar_count = QueryDosDeviceW(NULL, buff, DEVBUFSIZE);
if (wchar_count == 0) {
return 0;
}
for (int i = 0; i < wchar_count; i++) {
if (wcsstr(buff + i, L"SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S40#")) {
wcsncpy(dev_name, buff + i, MAX_PATH);
(dev_name)[MAX_PATH - 1] = '\0';
return 1;
}
i += wcslen(buff + i);
}
return 0;
}
#else
int Search() {
return 0;
}
#endif /* Search() */
void DetectSpectrixS40GControllers(std::vector<RGBController*>& rgb_controllers)
{
XPGSpectrixS40GController* new_xpg_s40g;
RGBController_XPGSpectrixS40G* new_controller;
#ifdef _WIN32
// https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices
wchar_t dev_name[MAX_PATH];
if (Search(dev_name)) {
new_xpg_s40g = new XPGSpectrixS40GController(0x67);
int result = new_xpg_s40g->SetHandle(dev_name);
if (result) {
new_controller = new RGBController_XPGSpectrixS40G(new_xpg_s40g);
rgb_controllers.push_back(new_controller);
} else {
delete new_xpg_s40g;
}
// https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices
wchar_t dev_name[MAX_PATH];
if(Search(dev_name))
{
new_xpg_s40g = new XPGSpectrixS40GController(0x67);
int result = new_xpg_s40g->SetHandle(dev_name);
if(result)
{
new_controller = new RGBController_XPGSpectrixS40G(new_xpg_s40g);
rgb_controllers.push_back(new_controller);
}
#else
// TODO
#endif
else
{
delete new_xpg_s40g;
}
}
} /* DetectSpectrixS40GControllers() */
REGISTER_DETECTOR("XPG Spectrix S40G NVMe", DetectSpectrixS40GControllers);

View File

@@ -142,7 +142,6 @@ INCLUDEPATH +=
Controllers/ThermaltakePoseidonZRGBController/ \
Controllers/ThermaltakeRiingController/ \
Controllers/WootingKeyboardController/ \
Controllers/XPGSpectrixS40GControllerLinux/ \
Controllers/YeelightController/ \
Controllers/ZalmanZSyncController/ \
RGBController/ \
@@ -462,8 +461,6 @@ HEADERS +=
Controllers/WootingKeyboardController/WootingTwoKeyboardController.h \
Controllers/WootingKeyboardController/RGBController_WootingKeyboard.h \
Controllers/ThermaltakeRiingController/RGBController_ThermaltakeRiingQuad.h \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GController.h \
Controllers/XPGSpectrixS40GControllerLinux/RGBController_XPGSpectrixS40G.h \
Controllers/YeelightController/YeelightController.h \
Controllers/YeelightController/RGBController_Yeelight.h \
Controllers/ZalmanZSyncController/ZalmanZSyncController.h \
@@ -877,9 +874,6 @@ SOURCES +=
Controllers/WootingKeyboardController/WootingTwoKeyboardController.cpp \
Controllers/WootingKeyboardController/RGBController_WootingKeyboard.cpp \
Controllers/ThermaltakeRiingController/RGBController_ThermaltakeRiingQuad.cpp \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GController.cpp \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GControllerDetect.cpp \
Controllers/XPGSpectrixS40GControllerLinux/RGBController_XPGSpectrixS40G.cpp \
Controllers/YeelightController/YeelightController.cpp \
Controllers/YeelightController/YeelightControllerDetect.cpp \
Controllers/YeelightController/RGBController_Yeelight.cpp \
@@ -938,6 +932,7 @@ win32:INCLUDEPATH +=
dependencies/openrazer-win32 \
wmi/ \
Controllers/AsusTUFLaptopController \
Controllers/XPGSpectrixS40GControllerWindows/ \
win32:SOURCES += \
# dependencies/hidapi/hidapi.c \
@@ -1040,6 +1035,9 @@ win32:SOURCES +=
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopWMI.cpp \
Controllers/OpenRazerController/OpenRazerWindowsDetect.cpp \
Controllers/OpenRazerController/RGBController_OpenRazerWindows.cpp \
Controllers/XPGSpectrixS40GControllerWindows/XPGSpectrixS40GController.cpp \
Controllers/XPGSpectrixS40GControllerWindows/XPGSpectrixS40GControllerDetect.cpp \
Controllers/XPGSpectrixS40GControllerWindows/RGBController_XPGSpectrixS40G.cpp \
win32:HEADERS += \
dependencies/display-library/include/adl_defines.h \
@@ -1056,6 +1054,8 @@ win32:HEADERS +=
AutoStart/AutoStart-Windows.h \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopWMI.h \
Controllers/OpenRazerController/RGBController_OpenRazerWindows.h \
Controllers/XPGSpectrixS40GControllerWindows/XPGSpectrixS40GController.h \
Controllers/XPGSpectrixS40GControllerWindows/RGBController_XPGSpectrixS40G.h \
win32:contains(QMAKE_TARGET.arch, x86_64) {
LIBS += \
@@ -1139,6 +1139,7 @@ unix:!macx {
INCLUDEPATH += \
Controllers/FaustusController \
Controllers/LinuxLEDController \
Controllers/XPGSpectrixS40GControllerWindows/ \
HEADERS += \
i2c_smbus/i2c_smbus_linux.h \
@@ -1147,6 +1148,8 @@ unix:!macx {
Controllers/LinuxLEDController/LinuxLEDController.h \
Controllers/LinuxLEDController/RGBController_LinuxLED.h \
Controllers/OpenRazerController/RGBController_OpenRazer.h \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GController.h \
Controllers/XPGSpectrixS40GControllerLinux/RGBController_XPGSpectrixS40G.h \
LIBS += \
-lusb-1.0 \
@@ -1194,6 +1197,9 @@ unix:!macx {
Controllers/LinuxLEDController/RGBController_LinuxLED.cpp \
Controllers/OpenRazerController/OpenRazerDetect.cpp \
Controllers/OpenRazerController/RGBController_OpenRazer.cpp \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GController.cpp \
Controllers/XPGSpectrixS40GControllerLinux/XPGSpectrixS40GControllerDetect.cpp \
Controllers/XPGSpectrixS40GControllerLinux/RGBController_XPGSpectrixS40G.cpp \
#-------------------------------------------------------------------------------------------#
# Set up install paths #