diff --git a/.gitignore b/.gitignore index b69c247..f7299c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,18 @@ +*.TMP *.VC.* *.aps *.dll +*.lib *.obj *.tlog *.user .vs +CUESDK* +Corsair*.h Debug/ LFX2.h LogitechLEDLib.* Release/ -ipch/ -UniLight.exe UniLight*.zip +UniLight.exe +ipch/ diff --git a/UniLight/CUEUtil.cpp b/UniLight/CUEUtil.cpp new file mode 100644 index 0000000..75dd9ae --- /dev/null +++ b/UniLight/CUEUtil.cpp @@ -0,0 +1,76 @@ +// UniLight by HunterZ + +#include "CUEUtil.h" + +#include "CUESDK.h" + +#include + +namespace CUEUtil +{ + CUEUtilC::CUEUtilC() + { + CorsairProtocolDetails cpd(CorsairPerformProtocolHandshake()); + // bool CorsairSetLayerPriority(int priority) + } + + CUEUtilC::~CUEUtilC() + { + } + + bool CUEUtilC::SetCUEColor(unsigned char red, unsigned char green, unsigned char blue) + { + // scoop up desired LED IDs and associated colors into a vector + std::vector ledVector; + + // try adding all CorsairLedId types, since they're not in the context + // of a specific device anyway + for (int i(1); i < CLI_Last; ++i) + { + ledVector.push_back(CorsairLedColor{ static_cast(i), red, green, blue }); + } + + /* + // get number of Corsair devices + // need to enumerate devices on every call, in case of hot swapping + const int deviceCount(CorsairGetDeviceCount()); + // loop over list of devices + for (int i(0); i < deviceCount; ++i) + { + CorsairDeviceInfo* deviceInfoPtr(CorsairGetDeviceInfo(i)); + switch (deviceInfoPtr->type) + { + case CDT_Unknown: + // obviously this is unsupported + break; + + case CDT_Mouse: + break; + + case CDT_Keyboard: + case CDT_MouseMat: + { + // keyboards and mousemats support CorsairGetLedPositionsByDeviceIndex() + CorsairLedPositions* ledPositionsPtr(CorsairGetLedPositionsByDeviceIndex(i)); + for (int j(0); j < ledPositionsPtr->numberOfLed; ++j) + { + ledVector.push_back(CorsairLedColor{ ledPositionsPtr->pLedPosition[j].ledId, red, green, blue }); + } + } + break; + + case CDT_Headset: + break; + + case CDT_HeadsetStand: + break; + } + } + */ + + if (ledVector.empty()) return false; + + // don't really care if it fully succeeds, so call async with NULL + return CorsairSetLedsColorsAsync(ledVector.size(), ledVector.data(), 0, 0); + } +} diff --git a/UniLight/CUEUtil.h b/UniLight/CUEUtil.h new file mode 100644 index 0000000..cacad8d --- /dev/null +++ b/UniLight/CUEUtil.h @@ -0,0 +1,18 @@ +// UniLight by HunterZ + +#pragma once + +// utilities for working with Corsair Utility Engine (CUE) API +namespace CUEUtil +{ + class CUEUtilC + { + public: + + explicit CUEUtilC(); + + virtual ~CUEUtilC(); + + bool SetCUEColor(unsigned char red, unsigned char green, unsigned char blue); + }; +} diff --git a/UniLight/Main.cpp b/UniLight/Main.cpp index 36bfe5d..17dc97c 100644 --- a/UniLight/Main.cpp +++ b/UniLight/Main.cpp @@ -16,6 +16,7 @@ typedef struct _iobuf FILE; #endif */ #include "ColorUtil.h" +#include "CUEUtil.h" #include "LFXUtil.h" #include "LLEDUtil.h" #include "resource.h" @@ -44,6 +45,7 @@ namespace NOTIFYICONDATA notifyIconData; const LPCWSTR szTIP(_T("UniLight")); const LPCWSTR szClassName(_T("UniLight")); + CUEUtil::CUEUtilC cueUtil; LFXUtil::LFXUtilC lfxUtil; LLEDUtil::LLEDUtilC llledUtil; COLORREF lastColor(0); @@ -82,17 +84,25 @@ void ShowAbout(HWND hwnd) void UpdateColor(const COLORREF curColor) { + const unsigned char red(GetRValue(curColor)); + const unsigned char green(GetGValue(curColor)); + const unsigned char blue(GetBValue(curColor)); + + // set Corsair CUE color + const bool cueStatus(cueUtil.SetCUEColor(red, green, blue)); + // set AlienFX/LightFX color - const bool lfxStatus(lfxUtil.SetLFXColor(GetRValue(curColor), GetGValue(curColor), GetBValue(curColor))); + const bool lfxStatus(lfxUtil.SetLFXColor(red, green, blue)); // set Logitech LED color - const bool lledStatus(llledUtil.SetLLEDColor(GetRValue(curColor), GetGValue(curColor), GetBValue(curColor))); + const bool lledStatus(llledUtil.SetLLEDColor(red, green, blue)); // set tooltip std::wstringstream s; s << "UniLight status:"; s << "\nCurrent color: 0x" << std::setfill(L'0') << std::setw(8) << std::hex << curColor; s << "\nPrevious color: 0x" << std::setfill(L'0') << std::setw(8) << std::hex << lastColor; + s << "\nCorsCUE: " << (cueStatus ? "active" : "inactive"); s << "\nLightFX: " << (lfxStatus ? "active" : "inactive"); s << "\nLogiLED: " << (lledStatus ? "active" : "inactive"); StringCchCopy(notifyIconData.szTip, 128, s.str().c_str()); diff --git a/UniLight/UniLight.vcxproj b/UniLight/UniLight.vcxproj index f23539c..a325b83 100644 --- a/UniLight/UniLight.vcxproj +++ b/UniLight/UniLight.vcxproj @@ -20,12 +20,14 @@ + + @@ -111,7 +113,7 @@ Windows true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwmapi.lib;Wtsapi32.lib;LogitechLEDLib.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwmapi.lib;Wtsapi32.lib;CUESDK_2015.lib;LogitechLEDLib.lib;%(AdditionalDependencies) @@ -137,13 +139,14 @@ WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true MultiThreaded + None Windows true true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwmapi.lib;Wtsapi32.lib;LogitechLEDLib.lib;%(AdditionalDependencies) + false + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwmapi.lib;Wtsapi32.lib;CUESDK_2015.lib;LogitechLEDLib.lib;%(AdditionalDependencies)