Skip to content

Commit

Permalink
updates:
Browse files Browse the repository at this point in the history
- attempt to add Corsair CUE support (untested)
- update .gitignore
- UpdateColor(): convert COLORREF to RGB once, instead of once per API
  • Loading branch information
HunterZ committed Nov 25, 2017
1 parent a8cbdc9 commit b73d062
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
76 changes: 76 additions & 0 deletions UniLight/CUEUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// UniLight by HunterZ

#include "CUEUtil.h"

#include "CUESDK.h"

#include <vector>

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<CorsairLedColor> 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<CorsairLedId>(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);
}
}
18 changes: 18 additions & 0 deletions UniLight/CUEUtil.h
Original file line number Diff line number Diff line change
@@ -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);
};
}
14 changes: 12 additions & 2 deletions UniLight/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct _iobuf FILE;
#endif
*/
#include "ColorUtil.h"
#include "CUEUtil.h"
#include "LFXUtil.h"
#include "LLEDUtil.h"
#include "resource.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 6 additions & 3 deletions UniLight/UniLight.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="ColorUtil.cpp" />
<ClCompile Include="CUEUtil.cpp" />
<ClCompile Include="LFXUtil.cpp" />
<ClCompile Include="LLEDUtil.cpp" />
<ClCompile Include="Main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ColorUtil.h" />
<ClInclude Include="CUEUtil.h" />
<ClInclude Include="LLEDUtil.h" />
<ClInclude Include="LFXUtil.h" />
<ClInclude Include="resource.h" />
Expand Down Expand Up @@ -111,7 +113,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<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;LogitechLEDLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<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)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -137,13 +139,14 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DebugInformationFormat>None</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<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;LogitechLEDLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>false</GenerateDebugInformation>
<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)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down

0 comments on commit b73d062

Please sign in to comment.