├── .gitattributes
├── .gitignore
├── Color-Scale.jpg
├── Common
├── Common.vcxitems
├── Common.vcxitems.filters
├── CoreTempPlugin.h
├── EventLog.cpp
├── EventLog.h
├── LaunchApp.cpp
├── LaunchApp.h
├── Settings.cpp
├── Settings.h
├── mapping.cpp
└── mapping.h
├── Hue-Scale.jpg
├── LICENSE
├── MysticLightPlugin
├── CMysticLightCtrl.cpp
├── CMysticLightCtrl.h
├── MysticLightPlugin.cpp
├── MysticLightPlugin.def
├── MysticLightPlugin.vcxproj
├── MysticLightPlugin.vcxproj.filters
├── MysticLightPluginClass.cpp
├── MysticLightPluginClass.h
└── MysticLight_SDK.h
├── OpenRGBPlugin
├── NetworkClient.cpp
├── NetworkClient.h
├── NetworkProtocol.cpp
├── NetworkProtocol.h
├── OpenRGBPlugin.cpp
├── OpenRGBPlugin.def
├── OpenRGBPlugin.vcxproj
├── OpenRGBPlugin.vcxproj.filters
├── OpenRGBPluginClass.cpp
├── OpenRGBPluginClass.h
├── OpenRGBSettings.cpp
├── OpenRGBSettings.h
├── RGBController.cpp
├── RGBController.h
├── RGBController_Network.cpp
├── RGBController_Network.h
├── net_port.cpp
└── net_port.h
├── RGBLightPlugin.sln
└── readme.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/Color-Scale.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erkr/RGBLightPlugins/6b39820691a5b3dabb535bfd2d2c55e49206a040/Color-Scale.jpg
--------------------------------------------------------------------------------
/Common/Common.vcxitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | {86a4b606-80fc-4d9f-bd44-7af927ab2de9}
7 |
8 |
9 |
10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Common/Common.vcxitems.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {716901d9-3e1e-4c13-85e4-cc4a9b164e9a}
6 |
7 |
8 | {3cd30984-6cb5-420c-97f2-8b37deb820b6}
9 |
10 |
11 |
12 |
13 | Header Files
14 |
15 |
16 | Header Files
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 | Source Files
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Common/CoreTempPlugin.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | //Plugin types
5 | #define General_Type 1
6 |
7 | //Errors
8 | #define USER 0x20000000
9 |
10 | typedef struct core_temp_shared_data
11 | {
12 | unsigned int uiLoad[256];
13 | unsigned int uiTjMax[128];
14 | unsigned int uiCoreCnt;
15 | unsigned int uiCPUCnt;
16 | float fTemp[256];
17 | float fVID;
18 | float fCPUSpeed;
19 | float fFSBSpeed;
20 | float fMultiplier;
21 | char sCPUName[100];
22 | unsigned char ucFahrenheit;
23 | unsigned char ucDeltaToTjMax;
24 | }CoreTempSharedData,*LPCoreTempSharedData,**PPCoreTempSharedData;
25 |
26 | typedef struct CoreTempPluginInfo CoreTempPluginInfo, *LPCoreTempPluginInfo;
27 | typedef struct CoreTempPlugin CoreTempPlugin, *LPCoreTempPlugin;
28 | typedef void (*RemotePluginStop)(LPCoreTempPlugin);
29 | struct CoreTempPluginInfo
30 | {
31 | wchar_t *version;
32 | wchar_t *name;
33 | wchar_t *description;
34 | HWND hwndParent;
35 | HINSTANCE dllInstance;
36 | RemotePluginStop remoteStopProc;
37 | };
38 |
39 | struct CoreTempPlugin
40 | {
41 | int interfaceVersion;
42 | int type;
43 | LPCoreTempPluginInfo pluginInfo;
44 |
45 | // interfaceVersion = 1
46 | int (*Start)();
47 | void (*Update)(const LPCoreTempSharedData data);
48 | void (*Stop)();
49 | int (*Configure)();
50 | void (*Remove)(const wchar_t *path);
51 | };
52 |
53 | typedef LPCoreTempPlugin (WINAPI *fnGetPlugin)(HMODULE hModule);
54 | typedef void (WINAPI *fnReleasePlugin)();
--------------------------------------------------------------------------------
/Common/EventLog.cpp:
--------------------------------------------------------------------------------
1 | #include "EventLog.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 | namespace filesys = std::filesystem; // searchFile() requires language standard C++17
9 |
10 | std::wstring searchFile(const std::wstring& rootPath, const std::wstring& fileName)
11 | {
12 | // Check if given path exists and points to a directory
13 | if (filesys::exists(rootPath) && filesys::is_directory(rootPath))
14 | {
15 | // Create a Recursive Directory Iterator object and points to the starting of directory
16 | filesys::recursive_directory_iterator iter(rootPath);
17 | // Create a Recursive Directory Iterator object pointing to end.
18 | filesys::recursive_directory_iterator end;
19 | // Iterate till end
20 | while (iter != end)
21 | {
22 | // Check if current entry matches the file searched for
23 | if (iter->path().filename() == fileName)
24 | {
25 | //std::cout << "Found: " << iter->path().string() << '\n';
26 | return iter->path().wstring();
27 | }
28 | error_code ec;
29 | // Increment the iterator to point to next entry in recursive iteration
30 | iter.increment(ec);
31 | if (ec) {
32 | //std::cerr << "Error While Accessing : " << iter->path().string() << " :: " << ec.message() << '\n';
33 | }
34 | }
35 | }
36 | else
37 | {
38 | //std::wcerr << "Cant open directory: " << rootPath << '\n';
39 | }
40 | return std::wstring();
41 | }
42 |
43 |
44 | EventLog::EventLog(void)
45 | {
46 | event_log = NULL;
47 | }
48 |
49 |
50 | EventLog::~EventLog()
51 | {
52 | if (event_log != NULL)
53 | DeregisterEventSource(event_log);
54 | }
55 |
56 | bool EventLog::Initialize(LPCWSTR log_name)
57 | {
58 | if (event_log != NULL)
59 | return false;
60 |
61 | CString strReg = L"SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\";
62 | strReg += log_name;
63 | // create/open the registry event source key
64 | DWORD dwResult = 0;
65 | HKEY hKey = NULL;
66 | if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_LOCAL_MACHINE, strReg, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwResult))
67 | {
68 | return false;
69 | }
70 | // create/set the value EventMessageFile
71 | WCHAR searchRoot[MAX_PATH];
72 | GetEnvironmentVariable(L"windir", searchRoot, MAX_PATH);
73 | wcscat_s(searchRoot, MAX_PATH, L"\\Microsoft.NET");
74 | std::wstring szPathName = searchFile(searchRoot, L"EventLogMessages.dll"); // this standard .NET dll is used as event log message file
75 | if (ERROR_SUCCESS != RegSetValueExW(hKey, L"EventMessageFile", 0, REG_SZ, (BYTE *)szPathName.c_str(), (DWORD)(wcslen(szPathName.c_str()) + 1) * sizeof(WCHAR)) )
76 | {
77 | return false;
78 | }
79 | // register the event source
80 | event_log = RegisterEventSource(NULL, log_name);
81 | return (event_log != NULL);
82 | }
83 |
84 |
85 |
86 | void EventLog::WriteError(LPCWSTR message)
87 | {
88 | if (event_log != NULL)
89 | ReportEvent(event_log, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, &message, NULL);
90 | }
91 |
92 | void EventLog::WriteWarning(LPCWSTR message)
93 | {
94 | if (event_log != NULL)
95 | ReportEvent(event_log, EVENTLOG_WARNING_TYPE, 0, 0, NULL, 1, 0, &message, NULL);
96 | }
97 |
98 | void EventLog::WriteInfo(LPCWSTR message)
99 | {
100 | if (event_log != NULL)
101 | ReportEvent(event_log, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, &message, NULL);
102 | }
103 |
--------------------------------------------------------------------------------
/Common/EventLog.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | class EventLog
5 | {
6 | public:
7 |
8 | EventLog(void);
9 | virtual ~EventLog(void);
10 |
11 | bool Initialize(LPCWSTR log_name);
12 | void WriteError(LPCWSTR message);
13 | void WriteWarning(LPCWSTR message);
14 | void WriteInfo(LPCWSTR message);
15 | private:
16 | HANDLE event_log=NULL;
17 | };
18 |
19 |
--------------------------------------------------------------------------------
/Common/LaunchApp.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int launchApplicationAndWait(LPWSTR commandLine)
8 | {
9 | STARTUPINFO si;
10 | PROCESS_INFORMATION pi;
11 |
12 | ZeroMemory(&si, sizeof(si));
13 | si.cb = sizeof(si);
14 | ZeroMemory(&pi, sizeof(pi));
15 |
16 | // Start the child process.
17 | if (!CreateProcess(NULL, // No module name (use command line)
18 | commandLine, // Command line
19 | NULL, // Process handle not inheritable
20 | NULL, // Thread handle not inheritable
21 | FALSE, // Set handle inheritance to FALSE
22 | 0, // No creation flags
23 | NULL, // Use parent's environment block
24 | NULL, // Use parent's starting directory
25 | &si, // Pointer to STARTUPINFO structure
26 | &pi) // Pointer to PROCESS_INFORMATION structure
27 | )
28 | {
29 | int lastError = GetLastError();
30 | if (lastError == 740)
31 | {
32 | _tprintf(L"CreateProcess failed - The requested operation requires elevation\n");
33 | }
34 | else
35 | {
36 | _tprintf(L"CreateProcess failed (%d).\n", lastError);
37 | }
38 | return lastError;
39 | }
40 |
41 | // Wait until child process exits.
42 | WaitForSingleObject(pi.hProcess, INFINITE);
43 |
44 | // Close process and thread handles.
45 | CloseHandle(pi.hProcess);
46 | CloseHandle(pi.hThread);
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/Common/LaunchApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | int launchApplicationAndWait(LPWSTR commandLine);
--------------------------------------------------------------------------------
/Common/Settings.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "settings.h"
5 |
6 |
7 |
8 | CString GetFullINIFilePath()
9 | {
10 | WCHAR thisModulePath[MAX_PATH];
11 | HMODULE hModule = NULL;
12 | //retrieve the module handle where this function is running in: EXE or DLL
13 | if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
14 | (LPWSTR)&GetFullINIFilePath, &hModule) == 0)
15 | {
16 | return L"";
17 | }
18 | GetModuleFileName(hModule, thisModulePath, sizeof(thisModulePath) - 1);
19 | PathRenameExtension(thisModulePath, L".ini");
20 | CString Result(thisModulePath);
21 | return Result;
22 | }
23 |
24 | void PluginSettings::SaveSettings()
25 | {
26 | CString FullIniName = GetFullINIFilePath();
27 | CString stringValue;
28 |
29 | // General
30 | stringValue.Format(L"%d", doBeepForExceptions);
31 | WritePrivateProfileString(L"General_Settings", L"doBeepForExceptions", stringValue, FullIniName);
32 | stringValue.Format(L"%d", ControlIdx);
33 | WritePrivateProfileString(L"General_Settings", L"ControlIdx", stringValue, FullIniName);
34 | // Core Temp mappings
35 | stringValue.Format(L"%d", TCold);
36 | WritePrivateProfileString(L"Core_Temp_Mappings", L"TColdBelow", stringValue, FullIniName);
37 | stringValue.Format(L"%d", TWarm);
38 | WritePrivateProfileString(L"Core_Temp_Mappings", L"TWarm", stringValue, FullIniName);
39 | stringValue.Format(L"%d", THot);
40 | WritePrivateProfileString(L"Core_Temp_Mappings", L"THot", stringValue, FullIniName);
41 | stringValue.Format(L"%d", TCritical);
42 | WritePrivateProfileString(L"Core_Temp_Mappings", L"TCriticalAbove", stringValue, FullIniName);
43 | // Core Load mapping
44 | stringValue.Format(L"%d", LoadBasedIntensity);
45 | WritePrivateProfileString(L"Core_Load_Mappings", L"LoadBasedIntensity", stringValue, FullIniName);
46 | stringValue.Format(L"%d", ILowPct);
47 | WritePrivateProfileString(L"Core_Load_Mappings", L"ILowPct", stringValue, FullIniName);
48 | stringValue.Format(L"%d", IHighPct);
49 | WritePrivateProfileString(L"Core_Load_Mappings", L"IHighPct", stringValue, FullIniName);
50 | // color mappings HUE 360 degrees circle (0=RED, 120=Green, 240=Blue)
51 | stringValue.Format(L"%d", HUECold);
52 | WritePrivateProfileString(L"Color_HUE360_Mappings", L"HUECold", stringValue, FullIniName);
53 | stringValue.Format(L"%d", HRangeC2W);
54 | WritePrivateProfileString(L"Color_HUE360_Mappings", L"HRangeCold2Warm", stringValue, FullIniName);
55 | stringValue.Format(L"%d", HRangeW2H);
56 | WritePrivateProfileString(L"Color_HUE360_Mappings", L"HRangeWarm2Hot", stringValue, FullIniName);
57 | stringValue.Format(L"%d", HRangeH2C);
58 | WritePrivateProfileString(L"Color_HUE360_Mappings", L"HRangeHot2Critical", stringValue, FullIniName);
59 | }
60 |
61 | bool PluginSettings::ReadSettings()
62 | {
63 | CString FullIniName = GetFullINIFilePath();
64 | if (!PathFileExists(FullIniName)) {
65 | SaveSettings(); // create default file
66 | return false;
67 | }
68 | // General
69 | doBeepForExceptions = GetPrivateProfileInt(L"General_Settings", L"doBeepForExceptions", doBeepForExceptions, FullIniName);
70 | ControlIdx = GetPrivateProfileInt(L"General_Settings", L"ControlIdx", ControlIdx, FullIniName);
71 | // Core Temp mappings
72 | TCold = GetPrivateProfileInt(L"Core_Temp_Mappings", L"TColdBelow", TCold, FullIniName);
73 | TWarm = GetPrivateProfileInt(L"Core_Temp_Mappings", L"TWarm", TWarm, FullIniName);
74 | THot = GetPrivateProfileInt(L"Core_Temp_Mappings", L"THot", THot, FullIniName);
75 | TCritical = GetPrivateProfileInt(L"Core_Temp_Mappings", L"TCriticalAbove", TCritical, FullIniName);
76 | // Core Load mapping
77 | LoadBasedIntensity = GetPrivateProfileInt(L"Core_Load_Mappings", L"LoadBasedIntensity", LoadBasedIntensity, FullIniName);
78 | ILowPct = GetPrivateProfileInt(L"Core_Load_Mappings", L"ILowPct", ILowPct, FullIniName);
79 | IHighPct = GetPrivateProfileInt(L"Core_Load_Mappings", L"IHighPct", IHighPct, FullIniName);
80 | // color mappings HUE 360 degrees circle (0=RED, 120=Green, 240=Blue)
81 | HUECold = GetPrivateProfileInt(L"Color_HUE360_Mappings", L"HUECold", HUECold, FullIniName);
82 | HRangeC2W = GetPrivateProfileInt(L"Color_HUE360_Mappings", L"HRangeCold2Warm", HRangeC2W, FullIniName);
83 | HRangeW2H = GetPrivateProfileInt(L"Color_HUE360_Mappings", L"HRangeWarm2Hot", HRangeW2H, FullIniName);
84 | HRangeH2C = GetPrivateProfileInt(L"Color_HUE360_Mappings", L"HRangeHot2Critical", HRangeH2C, FullIniName);
85 |
86 | return true;
87 | }
88 |
--------------------------------------------------------------------------------
/Common/Settings.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | class PluginSettings {
5 | public:
6 | virtual void SaveSettings();
7 | virtual bool ReadSettings();
8 | int doBeepForExceptions = 0;
9 | int ControlIdx = 0;
10 | int TCold = 25;
11 | int TWarm = 55;
12 | int THot = 60;
13 | int TCritical = 80;
14 | int LoadBasedIntensity = 1; // true
15 | int ILowPct = 20; // 0-100
16 | int IHighPct = 100; // 0-100
17 | int HUECold = 240; /*BLUE*/
18 | int HRangeC2W = -240; /* towards RED*/
19 | int HRangeW2H = 0; /*whole range RED */
20 | int HRangeH2C = -20; /* towards violet-red */
21 | private:
22 | } ;
23 |
24 | CString GetFullINIFilePath();
25 |
26 |
--------------------------------------------------------------------------------
/Common/mapping.cpp:
--------------------------------------------------------------------------------
1 | // Routine to map Temperature on a HUE value
2 | #include "CoreTempPlugin.h"
3 | #include "Settings.h"
4 | #include "mapping.h"
5 |
6 | int mapCPUTempOnHUE(int Temp, int TCold, int TWarm, int THot, int TCritical,
7 | int HUECold /*20=BLUE*/,
8 | int HRangeC2W /*60=RED*/,
9 | int HRangeW2H /*60-70=RED */,
10 | int HRangeH2C ) /* above 80 is violet-red */
11 | {
12 | // Temps below TCold will set HUECold, and Temps above TCritical will return HUE for TCritical.
13 | // Three temp ranges, to support differnet slopes. These ranges are expected to be continues
14 | // HRanges can be positive or negative to determine the direction starting from HUECold
15 | // The defaults for HUE vary from Blue (cold) to VioletRed (hot)
16 | // Returns: HUE based on 0-360 degrees
17 | int HUE = HUECold;
18 | if (Temp >= TCritical)
19 | {
20 | HUE = HUECold + HRangeC2W + HRangeW2H + HRangeH2C;
21 | }
22 | else if (Temp >= THot)
23 | {
24 | int TRange = TCritical - THot;
25 | HUE = HUECold + HRangeC2W + HRangeW2H + ((Temp - THot)*HRangeH2C) / TRange;
26 | }
27 | else if (Temp >= TWarm)
28 | {
29 | int TRange = THot - TWarm;
30 | HUE = HUECold + HRangeC2W + ((Temp - TWarm)*HRangeW2H) / TRange;
31 | }
32 | else if (Temp >= TCold)
33 | {
34 | int TRange = TWarm - TCold;
35 | HUE = HUECold + ((Temp - TCold)*HRangeC2W) / TRange;
36 | }
37 |
38 | // assure the returned HUE is mapped in the 0-360 range
39 | HUE %= 360;
40 | if (HUE < 0)
41 | HUE += 360;
42 |
43 | return HUE;
44 | }
45 |
46 | float mapCPULoadOnIntensity(int CPULoad, float IMin, float IMax)
47 | {
48 | // Returns an Intensity that scales with the CPULoad (0-100) between IMin and IMax
49 | return IMin + ((IMax - IMin) * CPULoad) / 100;
50 | }
51 |
52 | cHSV ProcessCoreTempData(const LPCoreTempSharedData data, const PluginSettings Settings)
53 | {
54 | unsigned int AvgLoad = 0;
55 | double AvgTemp = 0;
56 | cHSV Result = { 0, 1.0, 1.0 };
57 | for (unsigned int i = 0; i < data->uiCoreCnt; i++)
58 | {
59 | AvgLoad += data->uiLoad[i];
60 | AvgTemp += data->fTemp[i];
61 | }
62 | AvgLoad /= data->uiCoreCnt;
63 | AvgTemp /= data->uiCoreCnt;
64 | Result.H = mapCPUTempOnHUE((int)AvgTemp, Settings.TCold, Settings.TWarm, Settings.THot, Settings.TCritical,
65 | Settings.HUECold, Settings.HRangeC2W, Settings.HRangeW2H, Settings.HRangeH2C);
66 | if (Settings.LoadBasedIntensity != 0)
67 | {
68 | Result.V = mapCPULoadOnIntensity(AvgLoad, (float)(Settings.ILowPct) / 100.0F, (float)(Settings.IHighPct) / 100.0F);
69 | }
70 | return Result;
71 | }
--------------------------------------------------------------------------------
/Common/mapping.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | int mapCPUTempOnHUE(int Temp, int TCold = 25, int TWarm = 55, int THot = 60, int TCritical = 85,
3 | int HUECold = 240 /*20=BLUE*/,
4 | int HRangeC2W = -240 /*60=RED*/,
5 | int HRangeW2H = 0, /*60-70=RED */
6 | int HRangeH2C = -20); /* above 80 is violet-red */
7 |
8 | float mapCPULoadOnIntensity(int CPULoad, float IMin = 0.20, float IMax = 1.0);
9 |
10 | typedef struct cHSV_ST
11 | {
12 | int H;
13 | float S;
14 | float V;
15 | } cHSV;
16 |
17 | cHSV ProcessCoreTempData(const LPCoreTempSharedData data, const PluginSettings Settings);
18 |
--------------------------------------------------------------------------------
/Hue-Scale.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erkr/RGBLightPlugins/6b39820691a5b3dabb535bfd2d2c55e49206a040/Hue-Scale.jpg
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/MysticLightPlugin/CMysticLightCtrl.cpp:
--------------------------------------------------------------------------------
1 | //#include "pch.h"
2 | #include "CMysticLightCtrl.h"
3 | #define MLAPI_OK 0 // Request is completed.
4 | #define MLAPI_ERROR -1 // Generic error.
5 | #define MLAPI_TIMEOUT -2 // Request is timeout.
6 | #define MLAPI_NO_IMPLEMENTED -3 // MSI application not found or installed version not supported.
7 | #define MLAPI_NOT_INITIALIZED -4 // MLAPI_Initialize has not been called successful.
8 | #define MLAPI_INVALID_ARGUMENT -101 // The parameter value is not valid.
9 | #define MLAPI_DEVICE_NOT_FOUND -102 // The device is not found.
10 | #define MLAPI_NOT_SUPPORTED -103 // Requested feature is not supported in the selected LED
11 |
12 | #include
13 | #include
14 |
15 | HINSTANCE Load_MSI_SDK_Dll() // don't put this method in a class as GetModuleHandleEx will fail then
16 | {
17 | WCHAR thisDllDirPath[MAX_PATH];
18 | HMODULE hModule = NULL;
19 | //retrieve the module handle where this function is running in: EXE or DLL
20 | if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
21 | (LPWSTR)&Load_MSI_SDK_Dll, &hModule) == 0)
22 | {
23 | return NULL;
24 | }
25 | GetModuleFileName(hModule, thisDllDirPath, sizeof(thisDllDirPath) - 1);
26 | PathRemoveFileSpecW(thisDllDirPath);
27 | CString dllName(thisDllDirPath);
28 | #ifdef _M_X64
29 | dllName += "\\MysticLight_SDK_x64.dll";
30 | #else
31 | dllName += "\\MysticLight_SDK.dll";
32 | #endif
33 | //Beep(1000, 10);
34 |
35 | return LoadLibrary(dllName);
36 | }
37 |
38 |
39 | /*
40 | Two generic helper macros to convert HSV to RGB or back
41 | */
42 | #define min_f(a, b, c) (fminf(a, fminf(b, c)))
43 | #define max_f(a, b, c) (fmaxf(a, fmaxf(b, c)))
44 |
45 | /*
46 | rgb2hsv is Based on the example of GitHub author yoggy. Source: https://gist.github.com/yoggy/8999625
47 | in:
48 | RGB: 0-255
49 | out:
50 | H: 0-360
51 | S: 0-1.0
52 | V: 0-1.0
53 | */
54 | // void rgb2hsv(const unsigned char &src_g, const unsigned char &src_b, unsigned char &dst_h, unsigned char &dst_s, unsigned char &dst_v)
55 | void CMysticLightCtrl::rgb2hsv(DWORD R, DWORD G, DWORD B, int *H, double *S, double *V)
56 | {
57 | float r = R / 255.0f;
58 | float g = G / 255.0f;
59 | float b = B / 255.0f;
60 |
61 | float h, s, v; // h:0-360.0, s:0.0-1.0, v:0.0-1.0
62 |
63 | float max = max_f(r, g, b);
64 | float min = min_f(r, g, b);
65 |
66 | v = max;
67 |
68 | if (max == 0.0f) {
69 | s = 0;
70 | h = 0;
71 | }
72 | else if (max - min == 0.0f) {
73 | s = 0;
74 | h = 0;
75 | }
76 | else {
77 | s = (max - min) / max;
78 |
79 | if (max == r) {
80 | h = 60 * ((g - b) / (max - min)) + 0;
81 | }
82 | else if (max == g) {
83 | h = 60 * ((b - r) / (max - min)) + 120;
84 | }
85 | else {
86 | h = 60 * ((r - g) / (max - min)) + 240;
87 | }
88 | }
89 |
90 | if (h < 0) h += 360.0f;
91 |
92 | *H = (int)(h); // 0-360
93 | *S = s; // 0.0-1.0
94 | *V = v; // 0.0-1.0
95 | }
96 |
97 | /* HSV2RGB code is inspired by hsvtorgb.cpp from Kuat Hadianto on GitHub: https://gist.github.com/kuathadianto/200148f53616cbd226d993b400214a7f
98 | * H(Hue): 0 - 360 degree (integer); other angles (even when negative) will be mapped on the 0-360 range
99 | * S(Saturation): 0 - 1.00 (double)
100 | * V(Value): 0 - 1.00 (double)
101 | * output: R,G,B: 0-255
102 | */
103 |
104 | void CMysticLightCtrl::hsv2rgb(int H, double S, double V, DWORD *R, DWORD *G, DWORD *B)
105 | {
106 | double C = S * V;
107 | double X = C * (1 - abs(fmod(H / 60.0, 2) - 1));
108 | double m = V - C;
109 | double Rs, Gs, Bs;
110 |
111 | // ERKR added full range for H, so e.g. -40 -> 320, 400 -> 40 etc
112 | H %= 360;
113 | if (H < 0) {
114 | H += 360;
115 | }
116 |
117 | if (H >= 0 && H < 60) {
118 | Rs = C;
119 | Gs = X;
120 | Bs = 0;
121 | }
122 | else if (H >= 60 && H < 120) {
123 | Rs = X;
124 | Gs = C;
125 | Bs = 0;
126 | }
127 | else if (H >= 120 && H < 180) {
128 | Rs = 0;
129 | Gs = C;
130 | Bs = X;
131 | }
132 | else if (H >= 180 && H < 240) {
133 | Rs = 0;
134 | Gs = X;
135 | Bs = C;
136 | }
137 | else if (H >= 240 && H < 300) {
138 | Rs = X;
139 | Gs = 0;
140 | Bs = C;
141 | }
142 | else {
143 | Rs = C;
144 | Gs = 0;
145 | Bs = X;
146 | }
147 | *R = (DWORD)((Rs + m) * 255);
148 | *G = (DWORD)((Gs + m) * 255);
149 | *B = (DWORD)((Bs + m) * 255);
150 | }
151 |
152 | void CMysticLightCtrl::SetLastError(CString msg, int status)
153 | {
154 | BSTR errStr;
155 | _GetErrorMessage(status, &errStr);
156 | lastError = msg+errStr;
157 | ::SysFreeString(errStr);
158 | }
159 |
160 | void CMysticLightCtrl::SetLastError(CString msg)
161 | {
162 | lastError = msg;
163 | }
164 |
165 | CString CMysticLightCtrl::GetLastError()
166 | {
167 | return lastError;
168 | }
169 |
170 | int CMysticLightCtrl::NrOfLEDS() {
171 | return nrOfLEDs;
172 | }
173 |
174 |
175 |
176 | bool CMysticLightCtrl::Connect(unsigned int deviceIdx)
177 | {
178 |
179 | //Beep(1500, 10);
180 | if (MLinstance != NULL)
181 | {
182 | SetLastError(L"Start already called. ");
183 | return false;
184 | }
185 |
186 | MLinstance = Load_MSI_SDK_Dll();
187 | if (MLinstance == NULL)
188 | {
189 | #ifdef _M_X64
190 | SetLastError(L"MysticLight_SDK_x64.dll not found. ");
191 | #else
192 | SetLastError(L"MysticLight_SDK.dll not found. ");
193 | #endif
194 | return false;
195 | }
196 | //Beep(1500, 10);
197 | //initialise the method fields with the methods offerd by the SDK
198 | _Initialize = (LPMLAPI_Initialize)GetProcAddress(MLinstance, "MLAPI_Initialize");
199 | _GetErrorMessage = (LPMLAPI_GetErrorMessage)GetProcAddress(MLinstance, "MLAPI_GetErrorMessage");
200 | _GetDeviceInfo = (LPMLAPI_GetDeviceInfo)GetProcAddress(MLinstance, "MLAPI_GetDeviceInfo");
201 | _GetLedInfo = (LPMLAPI_GetLedInfo)GetProcAddress(MLinstance, "MLAPI_GetLedInfo");
202 | _GetLedColor = (LPMLAPI_GetLedColor)GetProcAddress(MLinstance, "MLAPI_GetLedColor");
203 | _GetLedStyle = (LPMLAPI_GetLedStyle)GetProcAddress(MLinstance, "MLAPI_GetLedStyle");
204 | _GetLedMaxBright = (LPMLAPI_GetLedMaxBright)GetProcAddress(MLinstance, "MLAPI_GetLedMaxBright");
205 | _GetLedBright = (LPMLAPI_GetLedBright)GetProcAddress(MLinstance, "MLAPI_GetLedBright");
206 | _GetLedMaxSpeed = (LPMLAPI_GetLedMaxSpeed)GetProcAddress(MLinstance, "MLAPI_GetLedMaxSpeed");
207 | _GetLedSpeed = (LPMLAPI_GetLedSpeed)GetProcAddress(MLinstance, "MLAPI_GetLedSpeed");
208 | _SetLedColor = (LPMLAPI_SetLedColor)GetProcAddress(MLinstance, "MLAPI_SetLedColor");
209 | _SetLedStyle = (LPMLAPI_SetLedStyle)GetProcAddress(MLinstance, "MLAPI_SetLedStyle");
210 | _SetLedBright = (LPMLAPI_SetLedBright)GetProcAddress(MLinstance, "MLAPI_SetLedBright");
211 | _SetLedSpeed = (LPMLAPI_SetLedSpeed)GetProcAddress(MLinstance, "MLAPI_SetLedSpeed");
212 |
213 | int status = _Initialize(); //initialise the sdk
214 | if (status == MLAPI_OK)
215 | {
216 | SAFEARRAY *psad = NULL, *psal = NULL;
217 | status = _GetDeviceInfo(&(psad), &(psal));
218 | if (status == MLAPI_OK)
219 | {
220 | //Beep(1000, 10);
221 | devices.Attach(psad);
222 | ledCount.Attach(psal);
223 | if (devices.GetCount() > deviceIdx && ledCount.GetCount() > 0)
224 | {
225 | deviceName = devices.GetAt(deviceIdx);
226 | nrOfLEDs = _wtol(ledCount.GetAt(deviceIdx));
227 | return true;
228 | }
229 | else
230 | {
231 | SetLastError(L"No MSI Compatible Devices or LEDs found: ");
232 | }
233 | }
234 | else
235 | {
236 | SetLastError(L"SDK call GetDeviceInfo failed: ",status);
237 | #if 0
238 | // Work around for buggy GetDeviceInfo; use defauls
239 | deviceName = ::SysAllocString(L"MSI_MB");
240 | nrOfLEDs = 1;
241 | return true;
242 | #endif
243 | }
244 | }
245 | else
246 | {
247 | SetLastError(L"SDK call Initialize failed: ", status);
248 | }
249 | FreeLibrary(MLinstance);
250 | MLinstance = NULL;
251 | return false;
252 | }
253 |
254 | void CMysticLightCtrl::Disconnect()
255 | {
256 | if (MLinstance != NULL)
257 | {
258 | SafeArrayDestroy(devices);
259 | devices.m_psa = NULL;
260 | SafeArrayDestroy(ledCount);
261 | ledCount.m_psa = NULL;
262 | ::SysFreeString(deviceName);
263 | FreeLibrary(MLinstance);
264 | MLinstance = NULL;
265 | }
266 | }
267 |
268 | bool CMysticLightCtrl::SetLedStyle(CString Style, int LedIdx)
269 | {
270 | if (MLinstance == NULL)
271 | {
272 | SetLastError(L"SDK not connected. ");
273 | return false;
274 | }
275 | BSTR newStyle = ::SysAllocString(Style);
276 | int status = _SetLedStyle(deviceName, LedIdx, newStyle);
277 | ::SysFreeString(newStyle);
278 | if (status != MLAPI_OK)
279 | {
280 | SetLastError(L"SDK call SetLedStyle failed: ", status);
281 | return false;
282 | }
283 | return true;
284 | }
285 |
286 |
287 | bool CMysticLightCtrl::SetLedRGB(DWORD R, DWORD G, DWORD B, int LedIdx)
288 | {
289 | if (MLinstance == NULL)
290 | {
291 | SetLastError(L"SDK not connected. ");
292 | return false;
293 | }
294 | range255(R); range255(G); range255(B);
295 | int status = _SetLedColor(deviceName, LedIdx, R, G, B);
296 | if (status != MLAPI_OK)
297 | {
298 | SetLastError(L"SDK call SetLedColor failed: ", status);
299 | return false;
300 | }
301 | return true;
302 | }
303 |
304 | bool CMysticLightCtrl::GetLedRGB(DWORD *R, DWORD *G, DWORD *B, int LedIdx)
305 | {
306 | if (MLinstance == NULL)
307 | {
308 | SetLastError(L"SDK not connected. ");
309 | return false;
310 | }
311 | int status = _GetLedColor(deviceName, LedIdx, R, G, B);
312 | if (status != MLAPI_OK)
313 | {
314 | SetLastError(L"SDK call GetLedColor failed: ", status);
315 | return false;
316 | }
317 | return true;
318 | }
319 |
320 | bool CMysticLightCtrl::SetLedHSV(int H, double S, double V, int LedIdx)
321 | {
322 | if (MLinstance == NULL)
323 | {
324 | SetLastError(L"SDK not connected. ");
325 | return false;
326 | }
327 | DWORD R, G, B;
328 | range1(S); range1(V);
329 | hsv2rgb(H, S, V, &R, &G, &B);
330 | return SetLedRGB(R, G, B, LedIdx);
331 | }
332 |
333 | bool CMysticLightCtrl::GetLedHSV(int *H, double *S, double *V, int LedIdx)
334 | {
335 | if (MLinstance == NULL)
336 | {
337 | SetLastError(L"SDK not connected. ");
338 | return false;
339 | }
340 | DWORD R, G, B;
341 | if (GetLedRGB(&R, &G, &B, LedIdx))
342 | {
343 | rgb2hsv(R, G, B, H, S, V);
344 | return true;
345 | }
346 | return false;
347 | }
348 |
349 |
350 |
--------------------------------------------------------------------------------
/MysticLightPlugin/CMysticLightCtrl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include "MysticLight_SDK.h"
6 |
7 | /* CMysticLightCtrl
8 | Inspired by example console app from SimoDax on Github: https://github.com/SimoDax/MSI-mystic-light-tool/blob/master/MSI-mystic-light-tool.cpp
9 | Moved everything into a class to properly handle recources
10 | Class also hides the usage of COM related types like BSTR
11 | This Demo uses the fist device, first LED; change it to your needs
12 |
13 | Usage:
14 | // First call
15 | - Connect(optional:style); // this call connects and initializes the SDK dll, stores the current settings, and by default selects a style that allows color changes
16 | // do your stuff using:
17 | Set/Get methods
18 | // Last Call
19 | - Disconnect(optional:restore); // this call optionally restored the original settings and then releases all resources
20 | */
21 |
22 | class CMysticLightCtrl
23 | {
24 | public:
25 | bool Connect(unsigned int deviceIdx=0); // first call.
26 | bool IsConnected() { return MLinstance != NULL; };
27 | void Disconnect(); // last call to cleanup
28 | // these methods default to the first LED on the first device (MotherBoard)
29 | bool SetLedStyle(CString newStyle=L"Steady", int LedIdx=0); // Note that not all styles allow to change colors. The default L"Steady" will do!
30 | bool SetLedRGB(DWORD R, DWORD G, DWORD B, int LedIdx = 0);
31 | bool GetLedRGB(DWORD *R, DWORD *G, DWORD *B, int LedIdx = 0);
32 | bool SetLedHSV(int H, double S, double V, int LedIdx = 0);
33 | bool GetLedHSV(int *H, double *S, double *V, int LedIdx = 0);
34 | // didn't yet need the other methods;
35 |
36 | CString GetLastError();
37 | int NrOfLEDS();
38 |
39 | private:
40 | HINSTANCE MLinstance=NULL;
41 | CString lastError;
42 | BSTR deviceName;
43 | int nrOfLEDs=0;
44 |
45 | protected:
46 | CComSafeArray devices; //Wrapper class to use safearrays in C++ (https://msdn.microsoft.com/en-us/magazine/mt795188.aspx)
47 | //according to MSI docs GetDeviceInfo should return a safearray of BSTR for the devices..
48 | CComSafeArray ledCount; //.. and a safearray of BSTR for the led count in each device
49 |
50 | LPMLAPI_Initialize _Initialize;
51 | LPMLAPI_GetErrorMessage _GetErrorMessage;
52 | LPMLAPI_GetDeviceInfo _GetDeviceInfo;
53 | LPMLAPI_GetLedInfo _GetLedInfo;
54 | LPMLAPI_GetLedColor _GetLedColor; //coloUr is better tbh..
55 | LPMLAPI_GetLedStyle _GetLedStyle;
56 | LPMLAPI_GetLedMaxBright _GetLedMaxBright;
57 | LPMLAPI_GetLedBright _GetLedBright;
58 | LPMLAPI_GetLedMaxSpeed _GetLedMaxSpeed;
59 | LPMLAPI_GetLedSpeed _GetLedSpeed;
60 | LPMLAPI_SetLedColor _SetLedColor;
61 | LPMLAPI_SetLedStyle _SetLedStyle;
62 | LPMLAPI_SetLedBright _SetLedBright;
63 | LPMLAPI_SetLedSpeed _SetLedSpeed;
64 | void rgb2hsv(DWORD R, DWORD G, DWORD B, int *H, double *S, double *V);
65 | void hsv2rgb(int H, double S, double V, DWORD *R, DWORD *G, DWORD *B);
66 | void SetLastError(CString msg, int status);
67 | void SetLastError(CString msg);
68 |
69 | void range255(DWORD &a) { if (a < 0) a = 0; if (a > 255) a = 255; }
70 | void range1(double& a) { if (a < 0.0) a = 0.0; if (a > 1.0) a = 1.0; }
71 | };
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPlugin.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "CoreTempPlugin.h"
8 | #include "MysticLightPluginClass.h"
9 |
10 | MysticLightPluginClass *mysticLightPluginClass = NULL;
11 |
12 | int Start()
13 | {
14 | return mysticLightPluginClass->Start();
15 | }
16 |
17 | void Update(const LPCoreTempSharedData data)
18 | {
19 | mysticLightPluginClass->Update(data);
20 | }
21 |
22 | void Stop()
23 | {
24 | mysticLightPluginClass->Stop();
25 | }
26 |
27 | int Configure()
28 | {
29 | return mysticLightPluginClass->Configure();
30 | }
31 |
32 | void Remove(const wchar_t *path)
33 | {
34 | mysticLightPluginClass->Remove(path);
35 | }
36 |
37 | LPCoreTempPlugin WINAPI GetPlugin(HMODULE hModule)
38 | {
39 | mysticLightPluginClass = new MysticLightPluginClass();
40 | LPCoreTempPlugin plugin = mysticLightPluginClass->GetPluginInstance(hModule);
41 | plugin->Start = Start;
42 | plugin->Update = Update;
43 | plugin->Stop = Stop;
44 | plugin->Configure = Configure;
45 | plugin->Remove = Remove;
46 | return plugin;
47 | }
48 |
49 | void WINAPI ReleasePlugin()
50 | {
51 | if (mysticLightPluginClass)
52 | {
53 | delete mysticLightPluginClass;
54 | mysticLightPluginClass = NULL;
55 | }
56 |
57 |
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPlugin.def:
--------------------------------------------------------------------------------
1 | LIBRARY "MysticLightPlugin"
2 | EXPORTS
3 | GetPlugin @1LIBRARY
4 | ReleasePlugin @2LIBRARY
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPlugin.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}
23 | Win32Proj
24 | MysticLightPlugin
25 | 10.0
26 | MysticLightPlugin
27 |
28 |
29 |
30 | DynamicLibrary
31 | true
32 | Unicode
33 | v142
34 |
35 |
36 | DynamicLibrary
37 | true
38 | Unicode
39 | v142
40 |
41 |
42 | DynamicLibrary
43 | false
44 | true
45 | Unicode
46 | v142
47 |
48 |
49 | DynamicLibrary
50 | false
51 | true
52 | Unicode
53 | v142
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 |
77 |
78 | true
79 |
80 |
81 | false
82 |
83 |
84 | false
85 |
86 |
87 |
88 |
89 |
90 | Level3
91 | Disabled
92 | WIN32;_DEBUG;_WINDOWS;_USRDLL;MYSTICLIGHTPLUGIN_EXPORTS;%(PreprocessorDefinitions)
93 | stdcpp17
94 |
95 |
96 | Windows
97 | true
98 | MysticLightPlugin.def
99 |
100 |
101 |
102 |
103 |
104 |
105 | Level3
106 | Disabled
107 | WIN32;_DEBUG;_WINDOWS;_USRDLL;MYSTICLIGHTPLUGIN_EXPORTS;%(PreprocessorDefinitions)
108 | stdcpp17
109 |
110 |
111 | Windows
112 | true
113 | MysticLightPlugin.def
114 |
115 |
116 |
117 |
118 | Level3
119 |
120 |
121 | MaxSpeed
122 | true
123 | true
124 | WIN32;NDEBUG;_WINDOWS;_USRDLL;MYSTICLIGHTPLUGIN_EXPORTS;%(PreprocessorDefinitions)
125 | stdcpp17
126 |
127 |
128 | Windows
129 | true
130 | true
131 | true
132 | MysticLightPlugin.def
133 |
134 |
135 |
136 |
137 | Level3
138 |
139 |
140 | MaxSpeed
141 | true
142 | true
143 | WIN32;NDEBUG;_WINDOWS;_USRDLL;MYSTICLIGHTPLUGIN_EXPORTS;%(PreprocessorDefinitions)
144 | stdcpp17
145 |
146 |
147 | Windows
148 | true
149 | true
150 | true
151 | MysticLightPlugin.def
152 | RequireAdministrator
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPlugin.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 |
40 |
41 | Source Files
42 |
43 |
44 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPluginClass.cpp:
--------------------------------------------------------------------------------
1 | //#include
2 | #include
3 | #include "MysticLightPluginClass.h"
4 | #include "mapping.h"
5 | #include "LaunchApp.h"
6 | #include "Settings.h"
7 |
8 | using namespace std;
9 |
10 | MysticLightPluginClass::MysticLightPluginClass(void)
11 | {
12 | this->configurePlugin();
13 | }
14 |
15 | MysticLightPluginClass::~MysticLightPluginClass(void)
16 | {
17 | delete m_CoreTempPlugin.pluginInfo;
18 | }
19 |
20 | int MysticLightPluginClass::Start()
21 | {
22 | // Return 0 for success, non-zero for failure.
23 | Settings.ReadSettings();
24 | EL.Initialize(L"MysticLightPlugin");
25 | EL.WriteInfo(L"MysticLightPlugin is Started");
26 | return 0;
27 | }
28 |
29 | void MysticLightPluginClass::Update(const LPCoreTempSharedData data)
30 | {
31 | try {
32 | if (ML.IsConnected() == false)
33 | {
34 | if (ML.Connect(Settings.ControlIdx)) { // give it a try
35 | // switch to Steady style that allow to change colors!
36 | for (int l = 0; l < ML.NrOfLEDS(); l++) {
37 | ML.SetLedStyle(L"Steady", l);
38 | }
39 | EL.WriteInfo(L"MysticLightPlugin Succesfully Connected the MSI SDK");
40 | }
41 | }
42 | else if (data != NULL)
43 | {
44 | cHSV hsv = ProcessCoreTempData(data, Settings);
45 | for (int l = 0; l < ML.NrOfLEDS(); l++) {
46 | if (!ML.SetLedHSV(hsv.H, hsv.S, hsv.V, l)) {
47 | // re-apply Steady style that allow to change colors!
48 | ML.SetLedStyle(L"Steady", l);
49 | // Beep(1000, 10); // unexpected, unless other app changed the ledStyle
50 | }
51 | }
52 | }
53 | }
54 | catch (...) {
55 | if (Settings.doBeepForExceptions != 0) {
56 | Beep(1000, 10); // unexpected
57 | }
58 | EL.WriteError(L"MysticLightPlugin: Exception occured while using the Mysticlight SDK");
59 | }
60 | }
61 |
62 | void MysticLightPluginClass::Stop()
63 | {
64 | ML.Disconnect();
65 | EL.WriteInfo(L"MysticLightPlugin is Stopped");
66 | }
67 |
68 | int MysticLightPluginClass::Configure()
69 | {
70 | // Return 0 for not-implemented, non-zero for "Handled".
71 | Settings.SaveSettings();
72 | CString CommandLine = L"notepad.exe "+GetFullINIFilePath();
73 | if (launchApplicationAndWait((LPWSTR)(LPCWSTR)CommandLine) == 0) // success
74 | {
75 | Settings.ReadSettings();
76 | EL.WriteInfo(L"MysticLightPlugin Configured");
77 | }
78 | return 1;
79 | }
80 |
81 | void MysticLightPluginClass::Remove(const wchar_t *path)
82 | {
83 | }
84 |
85 | LPCoreTempPlugin MysticLightPluginClass::GetPluginInstance(HMODULE hModule)
86 | {
87 | return &this->m_CoreTempPlugin;
88 | }
89 |
90 | void MysticLightPluginClass::configurePlugin()
91 | {
92 | LPCoreTempPluginInfo pluginInfo = new CoreTempPluginInfo;
93 |
94 | m_CoreTempPlugin.pluginInfo = pluginInfo;
95 | pluginInfo->name = L"MSI Mystic Light Plugin";
96 | pluginInfo->description = L"Controls the MainBoard LED's based on CPU temp and CPU load";
97 | pluginInfo->version = L"1.1";
98 |
99 | // Interface version should be 1 for current plugin API.
100 | m_CoreTempPlugin.interfaceVersion = 1;
101 | m_CoreTempPlugin.type = General_Type;
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLightPluginClass.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "CoreTempPlugin.h"
3 | #include "CMysticLightCtrl.h"
4 | #include "Settings.h"
5 | #include "EventLog.h"
6 |
7 | class MysticLightPluginClass
8 | {
9 | public:
10 | MysticLightPluginClass(void);
11 | virtual ~MysticLightPluginClass(void);
12 |
13 | int Start();
14 | void Update(const LPCoreTempSharedData data);
15 | void Stop();
16 | int Configure();
17 | void Remove(const wchar_t *path);
18 |
19 | LPCoreTempPlugin GetPluginInstance(HMODULE hModule);
20 |
21 | protected:
22 | EventLog EL;
23 | CMysticLightCtrl ML;
24 | PluginSettings Settings;
25 | CoreTempPlugin m_CoreTempPlugin;
26 | void configurePlugin();
27 | };
28 |
29 |
--------------------------------------------------------------------------------
/MysticLightPlugin/MysticLight_SDK.h:
--------------------------------------------------------------------------------
1 | // MysticLight_SDK.h : header file
2 | //
3 |
4 | #pragma once
5 |
6 | typedef int (*LPMLAPI_Initialize)();
7 | typedef int (*LPMLAPI_GetDeviceInfo)(SAFEARRAY** pDevType, SAFEARRAY** pLedCount);
8 | typedef int (*LPMLAPI_GetDeviceName)(BSTR type, SAFEARRAY** pDevName);
9 | typedef int (*LPMLAPI_GetDeviceNameEx)(BSTR type, DWORD index, BSTR* pDevName);
10 | typedef int (*LPMLAPI_GetErrorMessage)(int ErrorCode, BSTR* pDesc);
11 | typedef int (*LPMLAPI_GetLedName)(BSTR type, SAFEARRAY** pLedName);
12 | typedef int (*LPMLAPI_GetLedInfo)(BSTR type, DWORD index, BSTR* pName, SAFEARRAY** pLedStyles);
13 | typedef int (*LPMLAPI_GetLedColor)(BSTR type, DWORD index, DWORD* R, DWORD* G, DWORD* B);
14 | typedef int (*LPMLAPI_GetLedStyle)(BSTR type, DWORD index, BSTR* style);
15 | typedef int (*LPMLAPI_GetLedMaxBright)(BSTR type, DWORD index, DWORD* maxLevel);
16 | typedef int (*LPMLAPI_GetLedBright)(BSTR type, DWORD index, DWORD* currentLevel);
17 | typedef int (*LPMLAPI_GetLedMaxSpeed)(BSTR type, DWORD index, DWORD* maxLevel);
18 | typedef int (*LPMLAPI_GetLedSpeed)(BSTR type, DWORD index, DWORD* currentLevel);
19 | typedef int (*LPMLAPI_SetLedColor)(BSTR type, DWORD index, DWORD R, DWORD G, DWORD B);
20 | typedef int (*LPMLAPI_SetLedColors)(BSTR type, DWORD AreaIndex, SAFEARRAY** pLedName, DWORD* R, DWORD* G, DWORD* B);
21 | typedef int (*LPMLAPI_SetLedColorEx)(BSTR type, DWORD AreaIndex, BSTR pLedName, DWORD R, DWORD G, DWORD B, DWORD );
22 | typedef int (*LPMLAPI_SetLedColorSync)(BSTR type, DWORD AreaIndex, BSTR pLedName, DWORD R, DWORD G, DWORD B, DWORD );
23 | typedef int (*LPMLAPI_SetLedStyle)(BSTR type, DWORD index, BSTR style);
24 | typedef int (*LPMLAPI_SetLedBright)(BSTR type, DWORD index, DWORD level);
25 | typedef int (*LPMLAPI_SetLedSpeed)(BSTR type, DWORD index, DWORD level);
--------------------------------------------------------------------------------
/OpenRGBPlugin/NetworkClient.cpp:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | NetworkClient.cpp |
3 | | |
4 | | Client code for OpenRGB SDK |
5 | | |
6 | | Adam Honse (CalcProgrammer1) 5/9/2020 |
7 | \*-----------------------------------------*/
8 |
9 | #include "NetworkClient.h"
10 | #include "RGBController_Network.h"
11 | #include
12 |
13 | #ifdef _WIN32
14 | #include
15 | #define MSG_NOSIGNAL 0
16 | #endif
17 |
18 | #ifdef __APPLE__
19 | #include
20 | #define MSG_NOSIGNAL 0
21 | #endif
22 |
23 | #ifdef __linux__
24 | #include
25 | #include
26 | #endif
27 |
28 | using namespace std::chrono_literals;
29 |
30 | NetworkClient::NetworkClient(std::vector& control) : controllers(control)
31 | {
32 | strcpy(port_ip, "127.0.0.1");
33 | port_num = OPENRGB_SDK_PORT;
34 | client_sock = -1;
35 | server_connected = false;
36 | server_controller_count = 0;
37 | change_in_progress = false;
38 |
39 | ListenThread = NULL;
40 | ConnectionThread = NULL;
41 | }
42 |
43 | NetworkClient::~NetworkClient()
44 | {
45 | delete ConnectionThread;
46 | }
47 |
48 | void NetworkClient::ClientInfoChanged()
49 | {
50 | ClientInfoChangeMutex.lock();
51 | ControllerListMutex.lock();
52 |
53 | /*-------------------------------------------------*\
54 | | Client info has changed, call the callbacks |
55 | \*-------------------------------------------------*/
56 | for(unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size(); callback_idx++)
57 | {
58 | ClientInfoChangeCallbacks[callback_idx](ClientInfoChangeCallbackArgs[callback_idx]);
59 | }
60 |
61 | ControllerListMutex.unlock();
62 | ClientInfoChangeMutex.unlock();
63 | }
64 |
65 | const char * NetworkClient::GetIP()
66 | {
67 | return(port_ip);
68 | }
69 |
70 | unsigned short NetworkClient::GetPort()
71 | {
72 | return port_num;
73 | }
74 |
75 | bool NetworkClient::GetConnected()
76 | {
77 | return(server_connected);
78 | }
79 |
80 | bool NetworkClient::GetOnline()
81 | {
82 | return(server_connected && server_initialized);
83 | }
84 |
85 | void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg)
86 | {
87 | ClientInfoChangeCallbacks.push_back(new_callback);
88 | ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
89 | }
90 |
91 | void NetworkClient::SetIP(const char *new_ip)
92 | {
93 | if(server_connected == false)
94 | {
95 | strcpy(port_ip, new_ip);
96 | }
97 | }
98 |
99 | void NetworkClient::SetName(const char *new_name)
100 | {
101 | client_name = new_name;
102 |
103 | if(server_connected == true)
104 | {
105 | SendData_ClientString();
106 | }
107 | }
108 |
109 | void NetworkClient::SetPort(unsigned short new_port)
110 | {
111 | if(server_connected == false)
112 | {
113 | port_num = new_port;
114 | }
115 | }
116 |
117 | void NetworkClient::StartClient()
118 | {
119 | //Start a TCP server and launch threads
120 | char port_str[6];
121 | snprintf(port_str, 6, "%d", port_num);
122 |
123 | port.tcp_client(port_ip, port_str);
124 |
125 | client_active = true;
126 |
127 | //Start the connection thread
128 | ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
129 |
130 | /*-------------------------------------------------*\
131 | | Client info has changed, call the callbacks |
132 | \*-------------------------------------------------*/
133 | ClientInfoChanged();
134 | }
135 |
136 | void NetworkClient::StopClient()
137 | {
138 | server_connected = false;
139 | client_active = false;
140 |
141 | if (server_connected)
142 | {
143 | shutdown(client_sock, SD_RECEIVE);
144 | closesocket(client_sock);
145 | }
146 |
147 | if(ListenThread)
148 | ListenThread->join();
149 | ConnectionThread->join();
150 |
151 | /*-------------------------------------------------*\
152 | | Client info has changed, call the callbacks |
153 | \*-------------------------------------------------*/
154 | ClientInfoChanged();
155 | }
156 |
157 | void NetworkClient::ConnectionThreadFunction()
158 | {
159 | unsigned int requested_controllers;
160 |
161 | //This thread manages the connection to the server
162 | while(client_active == true)
163 | {
164 | if(server_connected == false)
165 | {
166 | //Connect to server and reconnect if the connection is lost
167 | server_initialized = false;
168 |
169 | //Try to connect to server
170 | if(port.tcp_client_connect() == true)
171 | {
172 | client_sock = port.sock;
173 | printf( "Connected to server\n" );
174 |
175 | //Server is now connected
176 | server_connected = true;
177 |
178 | //Start the listener thread
179 | ListenThread = new std::thread(&NetworkClient::ListenThreadFunction, this);
180 |
181 | //Server is not initialized
182 | server_initialized = false;
183 |
184 | /*-------------------------------------------------*\
185 | | Client info has changed, call the callbacks |
186 | \*-------------------------------------------------*/
187 | ClientInfoChanged();
188 | }
189 | else
190 | {
191 | printf( "Connection attempt failed\n" );
192 | }
193 | }
194 |
195 | if(server_initialized == false && server_connected == true)
196 | {
197 | requested_controllers = 0;
198 | server_controller_count = 0;
199 | server_controller_count_received = false;
200 |
201 | //Wait for server to connect
202 | std::this_thread::sleep_for(100ms);
203 |
204 | //Once server is connected, send client string
205 | SendData_ClientString();
206 |
207 | //Request number of controllers
208 | SendRequest_ControllerCount();
209 |
210 | //Wait for server controller count
211 | while(!server_controller_count_received)
212 | {
213 | std::this_thread::sleep_for(5ms);
214 | }
215 |
216 | printf("Client: Received controller count from server: %d\r\n", server_controller_count);
217 |
218 | //Once count is received, request controllers
219 | while(requested_controllers < server_controller_count)
220 | {
221 | printf("Client: Requesting controller %d\r\n", requested_controllers);
222 |
223 | controller_data_received = false;
224 | SendRequest_ControllerData(requested_controllers);
225 |
226 | //Wait until controller is received
227 | while(controller_data_received == false)
228 | {
229 | std::this_thread::sleep_for(5ms);
230 | }
231 |
232 | requested_controllers++;
233 | }
234 |
235 | ControllerListMutex.lock();
236 |
237 | //All controllers received, add them to master list
238 | printf("Client: All controllers received, adding them to master list\r\n");
239 | for(std::size_t controller_idx = 0; controller_idx < server_controllers.size(); controller_idx++)
240 | {
241 | controllers.push_back(server_controllers[controller_idx]);
242 | }
243 |
244 | ControllerListMutex.unlock();
245 |
246 | server_initialized = true;
247 |
248 | /*-------------------------------------------------*\
249 | | Client info has changed, call the callbacks |
250 | \*-------------------------------------------------*/
251 | ClientInfoChanged();
252 | }
253 |
254 | std::this_thread::sleep_for(1s);
255 | }
256 | }
257 |
258 | int NetworkClient::recv_select(SOCKET s, char *buf, int len, int flags)
259 | {
260 | fd_set set;
261 | struct timeval timeout;
262 |
263 | while(1)
264 | {
265 | timeout.tv_sec = 5;
266 | timeout.tv_usec = 0;
267 |
268 | FD_ZERO(&set); /* clear the set */
269 | FD_SET(s, &set); /* add our file descriptor to the set */
270 |
271 | int rv = select(s + 1, &set, NULL, NULL, &timeout);
272 |
273 | if(rv == SOCKET_ERROR || server_connected == false)
274 | {
275 | return 0;
276 | }
277 | else if(rv == 0)
278 | {
279 | continue;
280 | }
281 | else
282 | {
283 | // socket has something to read
284 | return(recv(s, buf, len, flags));
285 | }
286 |
287 | }
288 | }
289 |
290 | void NetworkClient::ListenThreadFunction()
291 | {
292 | printf("Network client listener started\n");
293 | //This thread handles messages received from the server
294 | while(server_connected == true)
295 | {
296 | NetPacketHeader header;
297 | int bytes_read = 0;
298 | char * data = NULL;
299 |
300 | //Read first byte of magic
301 | bytes_read = recv_select(client_sock, &header.pkt_magic[0], 1, 0);
302 |
303 | if(bytes_read <= 0)
304 | {
305 | goto listen_done;
306 | }
307 |
308 | //Test first character of magic - 'O'
309 | if(header.pkt_magic[0] != 'O')
310 | {
311 | continue;
312 | }
313 |
314 | //Read second byte of magic
315 | bytes_read = recv_select(client_sock, &header.pkt_magic[1], 1, 0);
316 |
317 | if(bytes_read <= 0)
318 | {
319 | goto listen_done;
320 | }
321 |
322 | //Test second character of magic - 'R'
323 | if(header.pkt_magic[1] != 'R')
324 | {
325 | continue;
326 | }
327 |
328 | //Read third byte of magic
329 | bytes_read = recv_select(client_sock, &header.pkt_magic[2], 1, 0);
330 |
331 | if(bytes_read <= 0)
332 | {
333 | goto listen_done;
334 | }
335 |
336 | //Test third character of magic - 'G'
337 | if(header.pkt_magic[2] != 'G')
338 | {
339 | continue;
340 | }
341 |
342 | //Read fourth byte of magic
343 | bytes_read = recv_select(client_sock, &header.pkt_magic[3], 1, 0);
344 |
345 | if(bytes_read <= 0)
346 | {
347 | goto listen_done;
348 | }
349 |
350 | //Test fourth character of magic - 'B'
351 | if(header.pkt_magic[3] != 'B')
352 | {
353 | continue;
354 | }
355 |
356 | //If we get to this point, the magic is correct. Read the rest of the header
357 | bytes_read = 0;
358 | do
359 | {
360 | int tmp_bytes_read = 0;
361 |
362 | tmp_bytes_read = recv_select(client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0);
363 |
364 | bytes_read += tmp_bytes_read;
365 |
366 | if(tmp_bytes_read <= 0)
367 | {
368 | goto listen_done;
369 | }
370 |
371 | } while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
372 |
373 | //Header received, now receive the data
374 | if(header.pkt_size > 0)
375 | {
376 | bytes_read = 0;
377 |
378 | data = new char[header.pkt_size];
379 |
380 | do
381 | {
382 | int tmp_bytes_read = 0;
383 |
384 | tmp_bytes_read = recv_select(client_sock, &data[(unsigned int)bytes_read], header.pkt_size - bytes_read, 0);
385 |
386 | if(tmp_bytes_read <= 0)
387 | {
388 | goto listen_done;
389 | }
390 | bytes_read += tmp_bytes_read;
391 |
392 | } while ((unsigned int)bytes_read < header.pkt_size);
393 | }
394 |
395 | //Entire request received, select functionality based on request ID
396 | switch(header.pkt_id)
397 | {
398 | case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
399 | ProcessReply_ControllerCount(header.pkt_size, data);
400 | break;
401 |
402 | case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
403 | ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
404 | break;
405 |
406 | case NET_PACKET_ID_DEVICE_LIST_UPDATED:
407 | ProcessRequest_DeviceListChanged();
408 | break;
409 | }
410 |
411 | delete[] data;
412 | }
413 |
414 | listen_done:
415 | printf( "Client socket has been closed");
416 | server_initialized = false;
417 | server_connected = false;
418 |
419 | ControllerListMutex.lock();
420 |
421 | for(size_t server_controller_idx = 0; server_controller_idx < server_controllers.size(); server_controller_idx++)
422 | {
423 | for(size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
424 | {
425 | if(controllers[controller_idx] == server_controllers[server_controller_idx])
426 | {
427 | controllers.erase(controllers.begin() + controller_idx);
428 | break;
429 | }
430 | }
431 | }
432 |
433 | std::vector server_controllers_copy = server_controllers;
434 |
435 | server_controllers.clear();
436 |
437 | for(size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size(); server_controller_idx++)
438 | {
439 | delete server_controllers_copy[server_controller_idx];
440 | }
441 |
442 | ControllerListMutex.unlock();
443 |
444 | /*-------------------------------------------------*\
445 | | Client info has changed, call the callbacks |
446 | \*-------------------------------------------------*/
447 | ClientInfoChanged();
448 | }
449 |
450 | void NetworkClient::WaitOnControllerData()
451 | {
452 | for(int i = 0; i < 1000; i++)
453 | {
454 | if(controller_data_received)
455 | {
456 | break;
457 | }
458 | std::this_thread::sleep_for(1ms);
459 | }
460 |
461 | return;
462 | }
463 |
464 | void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char * data)
465 | {
466 | if(data_size == sizeof(unsigned int))
467 | {
468 | memcpy(&server_controller_count, data, sizeof(unsigned int));
469 | server_controller_count_received = true;
470 | }
471 | }
472 |
473 | void NetworkClient::ProcessReply_ControllerData(unsigned int /*data_size*/, char * data, unsigned int dev_idx)
474 | {
475 | RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
476 |
477 | new_controller->ReadDeviceDescription((unsigned char *)data);
478 |
479 | ControllerListMutex.lock();
480 |
481 | if(dev_idx >= server_controllers.size())
482 | {
483 | server_controllers.push_back(new_controller);
484 | }
485 | else
486 | {
487 | server_controllers[dev_idx]->active_mode = new_controller->active_mode;
488 | delete new_controller;
489 | }
490 |
491 | ControllerListMutex.unlock();
492 |
493 | controller_data_received = true;
494 | }
495 |
496 | void NetworkClient::ProcessRequest_DeviceListChanged()
497 | {
498 | change_in_progress = true;
499 |
500 | ControllerListMutex.lock();
501 |
502 | for(size_t server_controller_idx = 0; server_controller_idx < server_controllers.size(); server_controller_idx++)
503 | {
504 | for(size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
505 | {
506 | if(controllers[controller_idx] == server_controllers[server_controller_idx])
507 | {
508 | controllers.erase(controllers.begin() + controller_idx);
509 | break;
510 | }
511 | }
512 | }
513 |
514 | std::vector server_controllers_copy = server_controllers;
515 |
516 | server_controllers.clear();
517 |
518 | for(size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size(); server_controller_idx++)
519 | {
520 | delete server_controllers_copy[server_controller_idx];
521 | }
522 |
523 | ControllerListMutex.unlock();
524 |
525 | /*-------------------------------------------------*\
526 | | Client info has changed, call the callbacks |
527 | \*-------------------------------------------------*/
528 | ClientInfoChanged();
529 |
530 | /*-------------------------------------------------*\
531 | | Mark server as uninitialized and delete the list |
532 | \*-------------------------------------------------*/
533 | server_initialized = false;
534 |
535 | change_in_progress = false;
536 | }
537 |
538 | void NetworkClient::SendData_ClientString()
539 | {
540 | NetPacketHeader reply_hdr;
541 |
542 | reply_hdr.pkt_magic[0] = 'O';
543 | reply_hdr.pkt_magic[1] = 'R';
544 | reply_hdr.pkt_magic[2] = 'G';
545 | reply_hdr.pkt_magic[3] = 'B';
546 |
547 | reply_hdr.pkt_dev_idx = 0;
548 | reply_hdr.pkt_id = NET_PACKET_ID_SET_CLIENT_NAME;
549 | reply_hdr.pkt_size = strlen(client_name.c_str()) + 1;
550 |
551 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
552 | send(client_sock, (char *)client_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
553 | }
554 |
555 | void NetworkClient::SendRequest_ControllerCount()
556 | {
557 | NetPacketHeader reply_hdr;
558 |
559 | reply_hdr.pkt_magic[0] = 'O';
560 | reply_hdr.pkt_magic[1] = 'R';
561 | reply_hdr.pkt_magic[2] = 'G';
562 | reply_hdr.pkt_magic[3] = 'B';
563 |
564 | reply_hdr.pkt_dev_idx = 0;
565 | reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
566 | reply_hdr.pkt_size = 0;
567 |
568 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
569 | }
570 |
571 | void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
572 | {
573 | NetPacketHeader reply_hdr;
574 |
575 | controller_data_received = false;
576 |
577 | reply_hdr.pkt_magic[0] = 'O';
578 | reply_hdr.pkt_magic[1] = 'R';
579 | reply_hdr.pkt_magic[2] = 'G';
580 | reply_hdr.pkt_magic[3] = 'B';
581 |
582 | reply_hdr.pkt_dev_idx = dev_idx;
583 | reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
584 | reply_hdr.pkt_size = 0;
585 |
586 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
587 | }
588 |
589 | void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size)
590 | {
591 | if(change_in_progress)
592 | {
593 | return;
594 | }
595 |
596 | NetPacketHeader reply_hdr;
597 | int reply_data[2];
598 |
599 | reply_hdr.pkt_magic[0] = 'O';
600 | reply_hdr.pkt_magic[1] = 'R';
601 | reply_hdr.pkt_magic[2] = 'G';
602 | reply_hdr.pkt_magic[3] = 'B';
603 |
604 | reply_hdr.pkt_dev_idx = dev_idx;
605 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE;
606 | reply_hdr.pkt_size = sizeof(reply_data);
607 |
608 | reply_data[0] = zone;
609 | reply_data[1] = new_size;
610 |
611 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
612 | send(client_sock, (char *)&reply_data, sizeof(reply_data), MSG_NOSIGNAL);
613 | }
614 |
615 | void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
616 | {
617 | if(change_in_progress)
618 | {
619 | return;
620 | }
621 |
622 | NetPacketHeader reply_hdr;
623 |
624 | reply_hdr.pkt_magic[0] = 'O';
625 | reply_hdr.pkt_magic[1] = 'R';
626 | reply_hdr.pkt_magic[2] = 'G';
627 | reply_hdr.pkt_magic[3] = 'B';
628 |
629 | reply_hdr.pkt_dev_idx = dev_idx;
630 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
631 | reply_hdr.pkt_size = size;
632 |
633 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
634 | send(client_sock, (char *)data, size, 0);
635 | }
636 |
637 | void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
638 | {
639 | if(change_in_progress)
640 | {
641 | return;
642 | }
643 |
644 | NetPacketHeader reply_hdr;
645 |
646 | reply_hdr.pkt_magic[0] = 'O';
647 | reply_hdr.pkt_magic[1] = 'R';
648 | reply_hdr.pkt_magic[2] = 'G';
649 | reply_hdr.pkt_magic[3] = 'B';
650 |
651 | reply_hdr.pkt_dev_idx = dev_idx;
652 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
653 | reply_hdr.pkt_size = size;
654 |
655 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
656 | send(client_sock, (char *)data, size, MSG_NOSIGNAL);
657 | }
658 |
659 | void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size)
660 | {
661 | if(change_in_progress)
662 | {
663 | return;
664 | }
665 |
666 | NetPacketHeader reply_hdr;
667 |
668 | reply_hdr.pkt_magic[0] = 'O';
669 | reply_hdr.pkt_magic[1] = 'R';
670 | reply_hdr.pkt_magic[2] = 'G';
671 | reply_hdr.pkt_magic[3] = 'B';
672 |
673 | reply_hdr.pkt_dev_idx = dev_idx;
674 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
675 | reply_hdr.pkt_size = size;
676 |
677 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
678 | send(client_sock, (char *)data, size, MSG_NOSIGNAL);
679 | }
680 |
681 | void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx)
682 | {
683 | if(change_in_progress)
684 | {
685 | return;
686 | }
687 |
688 | NetPacketHeader reply_hdr;
689 |
690 | reply_hdr.pkt_magic[0] = 'O';
691 | reply_hdr.pkt_magic[1] = 'R';
692 | reply_hdr.pkt_magic[2] = 'G';
693 | reply_hdr.pkt_magic[3] = 'B';
694 |
695 | reply_hdr.pkt_dev_idx = dev_idx;
696 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE;
697 | reply_hdr.pkt_size = 0;
698 |
699 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
700 | }
701 |
702 | void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
703 | {
704 | if(change_in_progress)
705 | {
706 | return;
707 | }
708 |
709 | NetPacketHeader reply_hdr;
710 |
711 | reply_hdr.pkt_magic[0] = 'O';
712 | reply_hdr.pkt_magic[1] = 'R';
713 | reply_hdr.pkt_magic[2] = 'G';
714 | reply_hdr.pkt_magic[3] = 'B';
715 |
716 | reply_hdr.pkt_dev_idx = dev_idx;
717 | reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE;
718 | reply_hdr.pkt_size = size;
719 |
720 | send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
721 | send(client_sock, (char *)data, size, MSG_NOSIGNAL);
722 | }
723 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/NetworkClient.h:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | NetworkClient.h |
3 | | |
4 | | Client header for OpenRGB SDK |
5 | | |
6 | | Adam Honse (CalcProgrammer1) 5/9/2020 |
7 | \*-----------------------------------------*/
8 |
9 | #include "RGBController.h"
10 | #include "NetworkProtocol.h"
11 | #include "net_port.h"
12 |
13 | #include
14 | #include
15 |
16 | #pragma once
17 |
18 | typedef void (*NetClientCallback)(void *);
19 |
20 | class NetworkClient
21 | {
22 | public:
23 | NetworkClient(std::vector& control);
24 | ~NetworkClient();
25 |
26 | void ClientInfoChanged();
27 |
28 | bool GetConnected();
29 | const char * GetIP();
30 | unsigned short GetPort();
31 | bool GetOnline();
32 |
33 | void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
34 |
35 | void SetIP(const char *new_ip);
36 | void SetName(const char *new_name);
37 | void SetPort(unsigned short new_port);
38 |
39 | void StartClient();
40 | void StopClient();
41 |
42 | void ConnectionThreadFunction();
43 | void ListenThreadFunction();
44 |
45 | void WaitOnControllerData();
46 |
47 | void ProcessReply_ControllerCount(unsigned int data_size, char * data);
48 | void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
49 | void ProcessRequest_DeviceListChanged();
50 |
51 | void SendData_ClientString();
52 |
53 | void SendRequest_ControllerCount();
54 | void SendRequest_ControllerData(unsigned int dev_idx);
55 |
56 | void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
57 |
58 | void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
59 | void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
60 | void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
61 |
62 | void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
63 |
64 | void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
65 |
66 | std::vector server_controllers;
67 |
68 | std::mutex ControllerListMutex;
69 |
70 | protected:
71 | std::vector& controllers;
72 |
73 |
74 | private:
75 | SOCKET client_sock;
76 | std::string client_name;
77 | net_port port;
78 | char port_ip[20];
79 | unsigned short port_num;
80 | bool client_active;
81 | bool controller_data_received;
82 | bool server_connected;
83 | bool server_initialized;
84 | unsigned int server_controller_count;
85 | bool server_controller_count_received;
86 | bool change_in_progress;
87 |
88 | std::thread * ConnectionThread;
89 | std::thread * ListenThread;
90 |
91 | std::mutex ClientInfoChangeMutex;
92 | std::vector ClientInfoChangeCallbacks;
93 | std::vector ClientInfoChangeCallbackArgs;
94 |
95 | int recv_select(SOCKET s, char *buf, int len, int flags);
96 | };
97 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/NetworkProtocol.cpp:
--------------------------------------------------------------------------------
1 | #include "NetworkProtocol.h"
2 |
3 | NetPacketHeader * InitNetPacketHeader
4 | (
5 | unsigned int pkt_dev_idx,
6 | unsigned int pkt_id,
7 | unsigned int pkt_size
8 | )
9 | {
10 | NetPacketHeader * new_header = new NetPacketHeader;
11 |
12 | new_header->pkt_magic[0] = 'O';
13 | new_header->pkt_magic[1] = 'R';
14 | new_header->pkt_magic[2] = 'G';
15 | new_header->pkt_magic[3] = 'B';
16 |
17 | new_header->pkt_dev_idx = pkt_dev_idx;
18 | new_header->pkt_id = pkt_id;
19 | new_header->pkt_size = pkt_size;
20 | }
--------------------------------------------------------------------------------
/OpenRGBPlugin/NetworkProtocol.h:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | NetworkProtocol.h |
3 | | |
4 | | Protocol header for OpenRGB SDK |
5 | | |
6 | | Adam Honse (CalcProgrammer1) 5/9/2020 |
7 | \*-----------------------------------------*/
8 |
9 | #pragma once
10 |
11 | /*-----------------------------------------*\
12 | | Default OpenRGB SDK port is 6742 |
13 | | This is "ORGB" on a phone keypad |
14 | \*-----------------------------------------*/
15 | #define OPENRGB_SDK_PORT 6742
16 |
17 | typedef struct NetPacketHeader
18 | {
19 | char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
20 | unsigned int pkt_dev_idx; /* Device index */
21 | unsigned int pkt_id; /* Packet ID */
22 | unsigned int pkt_size; /* Packet size */
23 | } NetPacketHeader;
24 |
25 | enum
26 | {
27 | /*----------------------------------------------------------------------------------------------------------*\
28 | | Network requests |
29 | \*----------------------------------------------------------------------------------------------------------*/
30 | NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
31 | NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
32 |
33 | NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
34 |
35 | NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
36 | /*----------------------------------------------------------------------------------------------------------*\
37 | | RGBController class functions |
38 | \*----------------------------------------------------------------------------------------------------------*/
39 | NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
40 |
41 | NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
42 | NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
43 | NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
44 |
45 | NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
46 | NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
47 | };
48 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPlugin.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "CoreTempPlugin.h"
8 | #include "OpenRGBPluginClass.h"
9 |
10 | OpenRGBPluginClass *openRGBPluginClass = NULL;
11 |
12 | int Start()
13 | {
14 | return openRGBPluginClass->Start();
15 | }
16 |
17 | void Update(const LPCoreTempSharedData data)
18 | {
19 | openRGBPluginClass->Update(data);
20 | }
21 |
22 | void Stop()
23 | {
24 | openRGBPluginClass->Stop();
25 | }
26 |
27 | int Configure()
28 | {
29 | return openRGBPluginClass->Configure();
30 | }
31 |
32 | void Remove(const wchar_t *path)
33 | {
34 | openRGBPluginClass->Remove(path);
35 | }
36 |
37 | LPCoreTempPlugin WINAPI GetPlugin(HMODULE hModule)
38 | {
39 | openRGBPluginClass = new OpenRGBPluginClass();
40 | LPCoreTempPlugin plugin = openRGBPluginClass->GetPluginInstance(hModule);
41 | plugin->Start = Start;
42 | plugin->Update = Update;
43 | plugin->Stop = Stop;
44 | plugin->Configure = Configure;
45 | plugin->Remove = Remove;
46 | return plugin;
47 | }
48 |
49 | void WINAPI ReleasePlugin()
50 | {
51 | if (openRGBPluginClass)
52 | {
53 | delete openRGBPluginClass;
54 | openRGBPluginClass = NULL;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPlugin.def:
--------------------------------------------------------------------------------
1 | LIBRARY "OpenRGBPlugin"
2 | EXPORTS
3 | GetPlugin @1LIBRARY
4 | ReleasePlugin @2LIBRARY
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPlugin.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {4959ADC4-C80B-4750-9927-C349B569D7AC}
23 | Win32Proj
24 | OpenRGBPlugin
25 | 10.0
26 |
27 |
28 |
29 | DynamicLibrary
30 | true
31 | Unicode
32 | v142
33 |
34 |
35 | DynamicLibrary
36 | true
37 | Unicode
38 | v142
39 |
40 |
41 | DynamicLibrary
42 | false
43 | true
44 | Unicode
45 | v142
46 |
47 |
48 | DynamicLibrary
49 | false
50 | true
51 | Unicode
52 | v142
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | true
78 |
79 |
80 | false
81 |
82 |
83 | false
84 |
85 |
86 |
87 |
88 |
89 | Level3
90 | Disabled
91 | WIN32;_DEBUG;_WINDOWS;_USRDLL;OPENRGBPLUGIN_EXPORTS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
92 | stdcpp17
93 |
94 |
95 | Windows
96 | true
97 | OpenRGBPlugin.def
98 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)
99 |
100 |
101 |
102 |
103 |
104 |
105 | Level3
106 | Disabled
107 | WIN32;_DEBUG;_WINDOWS;_USRDLL;OPENRGBPLUGIN_EXPORTS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
108 | stdcpp17
109 |
110 |
111 | Windows
112 | true
113 | OpenRGBPlugin.def
114 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)
115 |
116 |
117 |
118 |
119 | Level3
120 |
121 |
122 | MaxSpeed
123 | true
124 | true
125 | WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENRGBPLUGIN_EXPORTS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
126 | stdcpp17
127 |
128 |
129 | Windows
130 | true
131 | true
132 | true
133 | OpenRGBPlugin.def
134 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)
135 |
136 |
137 |
138 |
139 | Level3
140 |
141 |
142 | MaxSpeed
143 | true
144 | true
145 | WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENRGBPLUGIN_EXPORTS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
146 | stdcpp17
147 |
148 |
149 | Windows
150 | true
151 | true
152 | true
153 | OpenRGBPlugin.def
154 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPlugin.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {fff31d3c-2684-4ff4-8e9c-99d00507d5de}
18 |
19 |
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | OpenRGB SDK Files
29 |
30 |
31 | OpenRGB SDK Files
32 |
33 |
34 | OpenRGB SDK Files
35 |
36 |
37 | OpenRGB SDK Files
38 |
39 |
40 | OpenRGB SDK Files
41 |
42 |
43 |
44 |
45 | Source Files
46 |
47 |
48 | Source Files
49 |
50 |
51 | Source Files
52 |
53 |
54 | OpenRGB SDK Files
55 |
56 |
57 | OpenRGB SDK Files
58 |
59 |
60 | OpenRGB SDK Files
61 |
62 |
63 | OpenRGB SDK Files
64 |
65 |
66 | OpenRGB SDK Files
67 |
68 |
69 |
70 |
71 | Source Files
72 |
73 |
74 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPluginClass.cpp:
--------------------------------------------------------------------------------
1 | #include "NetworkClient.h"
2 | //#include "RGBController.h"
3 | //#include "RGBController_Network.h"
4 |
5 | #include
6 | #include "OpenRGBPluginClass.h"
7 | #include "mapping.h"
8 | #include "LaunchApp.h"
9 |
10 |
11 | using namespace std;
12 | std::vector control;
13 | NetworkClient* RGBClient = NULL;
14 |
15 | RGBColor hsv2rgb(int H, double S, double V)
16 | {
17 | double C = S * V;
18 | double X = C * (1 - abs(fmod(H / 60.0, 2) - 1));
19 | double m = V - C;
20 | double Rs, Gs, Bs;
21 |
22 | // ERKR added full range for H, so e.g. -40 -> 320, 400 -> 40 etc
23 | H %= 360;
24 | if (H < 0) {
25 | H += 360;
26 | }
27 |
28 | if (H >= 0 && H < 60) {
29 | Rs = C;
30 | Gs = X;
31 | Bs = 0;
32 | }
33 | else if (H >= 60 && H < 120) {
34 | Rs = X;
35 | Gs = C;
36 | Bs = 0;
37 | }
38 | else if (H >= 120 && H < 180) {
39 | Rs = 0;
40 | Gs = C;
41 | Bs = X;
42 | }
43 | else if (H >= 180 && H < 240) {
44 | Rs = 0;
45 | Gs = X;
46 | Bs = C;
47 | }
48 | else if (H >= 240 && H < 300) {
49 | Rs = X;
50 | Gs = 0;
51 | Bs = C;
52 | }
53 | else {
54 | Rs = C;
55 | Gs = 0;
56 | Bs = X;
57 | }
58 | RGBColor RGB = ToRGBColor((DWORD)((Rs + m) * 255), (DWORD)((Gs + m) * 255), (DWORD)((Bs + m) * 255));
59 | return RGB;
60 | }
61 |
62 | OpenRGBPluginClass::OpenRGBPluginClass(void)
63 | {
64 | this->configurePlugin();
65 | }
66 |
67 | OpenRGBPluginClass::~OpenRGBPluginClass(void)
68 | {
69 | delete m_CoreTempPlugin.pluginInfo;
70 | }
71 |
72 | int OpenRGBPluginClass::Start()
73 | {
74 | // Return 0 for success, non-zero for failure.
75 | Settings.ReadSettings();
76 | RGBClient = new NetworkClient(control);
77 | RGBClient->SetName("CoreTempClientPlugin");
78 | RGBClient->SetIP(Settings.OpenRGBIP);
79 | RGBClient->SetPortW(Settings.OpenRGBPort);
80 | RGBClient->StartClient();
81 | EL.Initialize(L"OpenRGBPlugin");
82 | EL.WriteInfo(L"OpenRGBPlugin is Started");
83 | return 0;
84 | }
85 |
86 | void OpenRGBPluginClass::Update(const LPCoreTempSharedData data)
87 | {
88 | try {
89 | if (data != NULL)
90 | {
91 | if (RGBClient->GetOnline())
92 | {
93 | // connected
94 | if (!wasConnected)
95 | {
96 | wasConnected = true;
97 | EL.WriteInfo(L"OpenRGBPlugin Succesfully Connected OpenRGB Server");
98 | }
99 | cHSV hsv = ProcessCoreTempData(data, Settings);
100 | RGBColor cRGB = hsv2rgb(hsv.H, hsv.S, hsv.V);
101 | RGBClient->ControllerListMutex.lock();
102 | if (control.size() > Settings.ControlIdx)
103 | {
104 | if (control[Settings.ControlIdx]->GetMode() != Settings.OpenRGBMode) {
105 | control[Settings.ControlIdx]->SetMode(Settings.OpenRGBMode);
106 | }
107 | control[Settings.ControlIdx]->SetAllLEDs(cRGB);
108 | control[Settings.ControlIdx]->UpdateLEDs();
109 | }
110 | RGBClient->ControllerListMutex.unlock();
111 | }
112 | else // NOT connected
113 | {
114 | if (wasConnected)
115 | {
116 | wasConnected = false;
117 | EL.WriteWarning(L"OpenRGBPlugin lost connection with OpenRGB Server");
118 | }
119 | }
120 | }
121 | }
122 | catch (...) {
123 | if (Settings.doBeepForExceptions != 0) {
124 | Beep(1000, 10); // unexpected
125 | }
126 | EL.WriteError(L"OpenRGBPlugin: Exception occured while using the OpenRGB SDK");
127 | }
128 | }
129 |
130 | void OpenRGBPluginClass::Stop()
131 | {
132 | RGBClient->StopClient();
133 | delete RGBClient;
134 | RGBClient = NULL;
135 | EL.WriteInfo(L"OpenRGBPlugin is Stopped");
136 | }
137 |
138 | int OpenRGBPluginClass::Configure()
139 | {
140 | // Return 0 for not-implemented, non-zero for "Handled".
141 | Settings.SaveSettings();
142 | CString CommandLine = L"notepad.exe " + GetFullINIFilePath();
143 | if (launchApplicationAndWait((LPWSTR)(LPCWSTR)CommandLine) == 0) // success
144 | {
145 | Settings.ReadSettings();
146 | EL.WriteInfo(L"OpenRGBPlugin Configured");
147 | }
148 | return 1;
149 | }
150 |
151 | void OpenRGBPluginClass::Remove(const wchar_t *path)
152 | {
153 | }
154 |
155 | LPCoreTempPlugin OpenRGBPluginClass::GetPluginInstance(HMODULE hModule)
156 | {
157 | return &this->m_CoreTempPlugin;
158 | }
159 |
160 | void OpenRGBPluginClass::configurePlugin()
161 | {
162 | LPCoreTempPluginInfo pluginInfo = new CoreTempPluginInfo;
163 |
164 | m_CoreTempPlugin.pluginInfo = pluginInfo;
165 | pluginInfo->name = L"OpenRGB Light Plugin";
166 | pluginInfo->description = L"Controls the MainBoard LED's based on CPU temp and CPU load";
167 | pluginInfo->version = L"1.0";
168 |
169 | // Interface version should be 1 for current plugin API.
170 | m_CoreTempPlugin.interfaceVersion = 1;
171 | m_CoreTempPlugin.type = General_Type;
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBPluginClass.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "CoreTempPlugin.h"
3 | #include "OpenRGBSettings.h"
4 | #include "EventLog.h"
5 |
6 |
7 | class OpenRGBPluginClass
8 | {
9 | public:
10 | OpenRGBPluginClass(void);
11 | virtual ~OpenRGBPluginClass(void);
12 |
13 | int Start();
14 | void Update(const LPCoreTempSharedData data);
15 | void Stop();
16 | int Configure();
17 | void Remove(const wchar_t *path);
18 |
19 | LPCoreTempPlugin GetPluginInstance(HMODULE hModule);
20 |
21 | protected:
22 | bool wasConnected = false;
23 | EventLog EL;
24 | OpenRGBSettings Settings;
25 | CoreTempPlugin m_CoreTempPlugin;
26 | void configurePlugin();
27 | };
28 |
29 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBSettings.cpp:
--------------------------------------------------------------------------------
1 | #include "OpenRGBSettings.h"
2 |
3 | void OpenRGBSettings::SaveSettings()
4 | {
5 | CString FullIniName = GetFullINIFilePath();
6 | CString stringValue;
7 |
8 |
9 | // OpenRGB settings
10 | stringValue = OpenRGBIP;
11 | WritePrivateProfileString(L"OpenRGB_Settings", L"OpenRGBIP", stringValue, FullIniName);
12 | stringValue.Format(L"%d", OpenRGBPort);
13 | WritePrivateProfileString(L"OpenRGB_Settings", L"OpenRGBPort", stringValue, FullIniName);
14 | stringValue.Format(L"%d", OpenRGBMode);
15 | WritePrivateProfileString(L"OpenRGB_Settings", L"OpenRGBMode", stringValue, FullIniName);
16 |
17 | PluginSettings::SaveSettings();
18 | }
19 |
20 | bool OpenRGBSettings::ReadSettings()
21 | {
22 | CString FullIniName = GetFullINIFilePath();
23 | if (!PathFileExists(FullIniName)) {
24 | SaveSettings(); // create default file
25 | return false;
26 | }
27 |
28 | CString defaultValue;
29 | WCHAR resultString[50];
30 | // OpenRGB settings
31 | defaultValue = OpenRGBIP;
32 | if (0 < GetPrivateProfileString(L"OpenRGB_Settings", L"OpenRGBIP", defaultValue, resultString, sizeof(resultString) - 1, FullIniName)) {
33 | //wcstombs(OpenRGBIP, resultString, sizeof(OpenRGBIP));
34 | size_t i;
35 | wcstombs_s(&i, OpenRGBIP, resultString, sizeof(OpenRGBIP));
36 | }
37 | OpenRGBPort = GetPrivateProfileInt(L"OpenRGB_Settings", L"OpenRGBPort", OpenRGBPort, FullIniName);
38 | OpenRGBMode = GetPrivateProfileInt(L"OpenRGB_Settings", L"OpenRGBMode", OpenRGBMode, FullIniName);
39 |
40 | return PluginSettings::ReadSettings();
41 | }
--------------------------------------------------------------------------------
/OpenRGBPlugin/OpenRGBSettings.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Settings.h"
3 | #include "NetworkProtocol.h"
4 | class OpenRGBSettings : public PluginSettings
5 | {
6 | public:
7 | virtual void SaveSettings();
8 | virtual bool ReadSettings();
9 |
10 | char OpenRGBIP[17] = "127.0.0.1";
11 | int OpenRGBPort = OPENRGB_SDK_PORT;
12 | int OpenRGBMode = 0;
13 | };
14 |
15 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/RGBController.h:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | RGBController.h |
3 | | |
4 | | Definitions and types for generic RGB |
5 | | lighting controller interface |
6 | | |
7 | | Adam Honse (CalcProgrammer1) 6/2/2019 |
8 | \*-----------------------------------------*/
9 |
10 | #pragma once
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | typedef unsigned int RGBColor;
20 |
21 | #define RGBGetRValue(rgb) (rgb & 0x000000FF)
22 | #define RGBGetGValue(rgb) ((rgb >> 8) & 0x000000FF)
23 | #define RGBGetBValue(rgb) ((rgb >> 16) & 0x000000FF)
24 |
25 | #define ToRGBColor(r, g, b) ((b << 16) | (g << 8) | (r))
26 |
27 | /*------------------------------------------------------------------*\
28 | | Mode Flags |
29 | \*------------------------------------------------------------------*/
30 | enum
31 | {
32 | MODE_FLAG_HAS_SPEED = (1 << 0), /* Mode has speed parameter */
33 | MODE_FLAG_HAS_DIRECTION_LR = (1 << 1), /* Mode has left/right parameter */
34 | MODE_FLAG_HAS_DIRECTION_UD = (1 << 2), /* Mode has up/down parameter */
35 | MODE_FLAG_HAS_DIRECTION_HV = (1 << 3), /* Mode has horiz/vert parameter */
36 | MODE_FLAG_HAS_BRIGHTNESS = (1 << 4), /* Mode has brightness parameter */
37 | MODE_FLAG_HAS_PER_LED_COLOR = (1 << 5), /* Mode has per-LED colors */
38 | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR = (1 << 6), /* Mode has mode specific colors */
39 | MODE_FLAG_HAS_RANDOM_COLOR = (1 << 7), /* Mode has random color option */
40 | };
41 |
42 | /*------------------------------------------------------------------*\
43 | | Mode Directions |
44 | \*------------------------------------------------------------------*/
45 | enum
46 | {
47 | MODE_DIRECTION_LEFT = 0, /* Mode direction left */
48 | MODE_DIRECTION_RIGHT = 1, /* Mode direction right */
49 | MODE_DIRECTION_UP = 2, /* Mode direction up */
50 | MODE_DIRECTION_DOWN = 3, /* Mode direction down */
51 | MODE_DIRECTION_HORIZONTAL = 4, /* Mode direction horizontal */
52 | MODE_DIRECTION_VERTICAL = 5, /* Mode direction vertical */
53 | };
54 |
55 | enum
56 | {
57 | MODE_COLORS_NONE = 0, /* Mode has no colors */
58 | MODE_COLORS_PER_LED = 1, /* Mode has per LED colors selected */
59 | MODE_COLORS_MODE_SPECIFIC = 2, /* Mode specific colors selected */
60 | MODE_COLORS_RANDOM = 3, /* Mode has random colors selected */
61 | };
62 |
63 | /*------------------------------------------------------------------*\
64 | | Mode Type |
65 | \*------------------------------------------------------------------*/
66 | typedef struct
67 | {
68 | /*--------------------------------------------------------------*\
69 | | Mode Information |
70 | \*--------------------------------------------------------------*/
71 | std::string name; /* Mode name */
72 | int value; /* Device-specific mode value */
73 | unsigned int flags; /* Mode flags bitfield */
74 | unsigned int speed_min; /* speed minimum value */
75 | unsigned int speed_max; /* speed maximum value */
76 | unsigned int colors_min; /* minimum number of mode colors*/
77 | unsigned int colors_max; /* maximum numver of mode colors*/
78 |
79 | /*--------------------------------------------------------------*\
80 | | Mode Settings |
81 | \*--------------------------------------------------------------*/
82 | unsigned int speed; /* Mode speed parameter value */
83 | unsigned int direction; /* Mode direction value */
84 | unsigned int color_mode; /* Mode color selection */
85 | std::vector
86 | colors; /* mode-specific colors */
87 | } mode;
88 |
89 | typedef struct
90 | {
91 | std::string name; /* LED name */
92 | unsigned int value; /* Device-specific LED value */
93 | } led;
94 |
95 | typedef int zone_type;
96 |
97 | enum
98 | {
99 | ZONE_TYPE_SINGLE,
100 | ZONE_TYPE_LINEAR,
101 | ZONE_TYPE_MATRIX
102 | };
103 |
104 | typedef int device_type;
105 |
106 | enum
107 | {
108 | DEVICE_TYPE_MOTHERBOARD,
109 | DEVICE_TYPE_DRAM,
110 | DEVICE_TYPE_GPU,
111 | DEVICE_TYPE_COOLER,
112 | DEVICE_TYPE_LEDSTRIP,
113 | DEVICE_TYPE_KEYBOARD,
114 | DEVICE_TYPE_MOUSE,
115 | DEVICE_TYPE_MOUSEMAT,
116 | DEVICE_TYPE_HEADSET,
117 | DEVICE_TYPE_HEADSET_STAND,
118 | DEVICE_TYPE_GAMEPAD,
119 | DEVICE_TYPE_UNKNOWN
120 | };
121 |
122 | std::string device_type_to_str(device_type type);
123 |
124 | typedef struct
125 | {
126 | unsigned int height;
127 | unsigned int width;
128 | unsigned int * map;
129 | } matrix_map_type;
130 |
131 | typedef struct
132 | {
133 | std::string name; /* Zone name */
134 | zone_type type; /* Zone type */
135 | led * leds; /* List of LEDs in zone */
136 | RGBColor * colors; /* Colors of LEDs in zone */
137 | unsigned int start_idx; /* Start index of led/color */
138 | unsigned int leds_count; /* Number of LEDs in zone */
139 | unsigned int leds_min; /* Minimum number of LEDs */
140 | unsigned int leds_max; /* Maximum number of LEDs */
141 | matrix_map_type * matrix_map; /* Matrix map pointer */
142 | } zone;
143 |
144 | typedef void (*RGBControllerCallback)(void *);
145 |
146 | class RGBController
147 | {
148 | public:
149 | std::string name; /* controller name */
150 | std::string description; /* controller description */
151 | std::string version; /* controller version */
152 | std::string serial; /* controller serial number */
153 | std::string location; /* controller location */
154 | std::vector leds; /* LEDs */
155 | std::vector zones; /* Zones */
156 | std::vector modes; /* Modes */
157 | std::vector colors; /* Color buffer */
158 | device_type type; /* device type */
159 | int active_mode = 0;/* active mode */
160 |
161 | /*---------------------------------------------------------*\
162 | | RGBController base class constructor |
163 | \*---------------------------------------------------------*/
164 | RGBController();
165 | virtual ~RGBController();
166 |
167 | /*---------------------------------------------------------*\
168 | | Generic functions implemented in RGBController.cpp |
169 | \*---------------------------------------------------------*/
170 | void SetupColors();
171 |
172 | RGBColor GetLED(unsigned int led);
173 | void SetLED(unsigned int led, RGBColor color);
174 | void SetAllLEDs(RGBColor color);
175 | void SetAllZoneLEDs(int zone, RGBColor color);
176 |
177 | int GetMode();
178 | void SetMode(int mode);
179 |
180 | unsigned char * GetDeviceDescription();
181 | void ReadDeviceDescription(unsigned char* data_buf);
182 |
183 | unsigned char * GetModeDescription(int mode);
184 | void SetModeDescription(unsigned char* data_buf);
185 |
186 | unsigned char * GetColorDescription();
187 | void SetColorDescription(unsigned char* data_buf);
188 |
189 | unsigned char * GetZoneColorDescription(int zone);
190 | void SetZoneColorDescription(unsigned char* data_buf);
191 |
192 | unsigned char * GetSingleLEDColorDescription(int led);
193 | void SetSingleLEDColorDescription(unsigned char* data_buf);
194 |
195 | void RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg);
196 | void UnregisterUpdateCallback(void * callback_arg);
197 | void SignalUpdate();
198 |
199 | void UpdateLEDs();
200 | //void UpdateZoneLEDs(int zone);
201 | //void UpdateSingleLED(int led);
202 |
203 | void UpdateMode();
204 |
205 | void DeviceCallThreadFunction();
206 |
207 | /*---------------------------------------------------------*\
208 | | Functions to be implemented in device implementation |
209 | \*---------------------------------------------------------*/
210 | virtual void SetupZones() = 0;
211 |
212 | virtual void ResizeZone(int zone, int new_size) = 0;
213 |
214 | virtual void DeviceUpdateLEDs() = 0;
215 | virtual void UpdateZoneLEDs(int zone) = 0;
216 | virtual void UpdateSingleLED(int led) = 0;
217 |
218 | virtual void DeviceUpdateMode() = 0;
219 |
220 | virtual void SetCustomMode() = 0;
221 |
222 | private:
223 | std::thread* DeviceCallThread;
224 | std::atomic CallFlag_UpdateLEDs;
225 | std::atomic CallFlag_UpdateMode;
226 | std::atomic DeviceThreadRunning;
227 | //bool CallFlag_UpdateZoneLEDs = false;
228 | //bool CallFlag_UpdateSingleLED = false;
229 | //bool CallFlag_UpdateMode = false;
230 |
231 | std::mutex UpdateMutex;
232 | std::vector UpdateCallbacks;
233 | std::vector UpdateCallbackArgs;
234 | };
235 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/RGBController_Network.cpp:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | RGBController_Network.cpp |
3 | | |
4 | | Generic RGB Interface Network Class |
5 | | |
6 | | Adam Honse (CalcProgrammer1) 4/11/2020 |
7 | \*-----------------------------------------*/
8 |
9 | #include
10 |
11 | #include "RGBController_Network.h"
12 |
13 | RGBController_Network::RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val)
14 | {
15 | client = client_ptr;
16 | dev_idx = dev_idx_val;
17 | }
18 |
19 | void RGBController_Network::SetupZones()
20 | {
21 | //Don't send anything, this function should only process on host
22 | }
23 |
24 | void RGBController_Network::ResizeZone(int zone, int new_size)
25 | {
26 | client->SendRequest_RGBController_ResizeZone(dev_idx, zone, new_size);
27 | }
28 |
29 | void RGBController_Network::DeviceUpdateLEDs()
30 | {
31 | unsigned char * data = GetColorDescription();
32 | unsigned int size;
33 |
34 | memcpy(&size, &data[0], sizeof(unsigned int));
35 |
36 | client->SendRequest_RGBController_UpdateLEDs(dev_idx, data, size);
37 |
38 | delete[] data;
39 | }
40 |
41 | void RGBController_Network::UpdateZoneLEDs(int zone)
42 | {
43 | unsigned char * data = GetZoneColorDescription(zone);
44 | unsigned int size;
45 |
46 | memcpy(&size, &data[0], sizeof(unsigned int));
47 |
48 | client->SendRequest_RGBController_UpdateZoneLEDs(dev_idx, data, size);
49 |
50 | delete[] data;
51 | }
52 |
53 | void RGBController_Network::UpdateSingleLED(int led)
54 | {
55 | unsigned char * data = GetSingleLEDColorDescription(led);
56 |
57 | client->SendRequest_RGBController_UpdateSingleLED(dev_idx, data, sizeof(int) + sizeof(RGBColor));
58 |
59 | delete[] data;
60 | }
61 |
62 | void RGBController_Network::SetCustomMode()
63 | {
64 | client->SendRequest_RGBController_SetCustomMode(dev_idx);
65 |
66 | client->SendRequest_ControllerData(dev_idx);
67 | client->WaitOnControllerData();
68 | }
69 |
70 | void RGBController_Network::DeviceUpdateMode()
71 | {
72 | unsigned char * data = GetModeDescription(active_mode);
73 | unsigned int size;
74 |
75 | memcpy(&size, &data[0], sizeof(unsigned int));
76 |
77 | client->SendRequest_RGBController_UpdateMode(dev_idx, data, size);
78 |
79 | delete[] data;
80 | }
81 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/RGBController_Network.h:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------*\
2 | | RGBController_Network.h |
3 | | |
4 | | Generic RGB Interface Network Class |
5 | | |
6 | | Adam Honse (CalcProgrammer1) 4/11/2020 |
7 | \*-----------------------------------------*/
8 |
9 | #pragma once
10 |
11 | #include "RGBController.h"
12 | #include "NetworkClient.h"
13 |
14 | class RGBController_Network : public RGBController
15 | {
16 | public:
17 | RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val);
18 |
19 | void SetupZones();
20 |
21 | void ResizeZone(int zone, int new_size);
22 |
23 | void DeviceUpdateLEDs();
24 | void UpdateZoneLEDs(int zone);
25 | void UpdateSingleLED(int led);
26 |
27 | void SetCustomMode();
28 | void DeviceUpdateMode();
29 |
30 | private:
31 | NetworkClient * client;
32 | unsigned int dev_idx;
33 | };
34 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/net_port.cpp:
--------------------------------------------------------------------------------
1 | /*---------------------------------------------------------*\
2 | | Cross Platform Network Library for Windows and Linux |
3 | | This library provides access to TCP and UDP ports with |
4 | | a common API for both Windows and Linux systems. It |
5 | | features read and write |
6 | | |
7 | | Adam Honse (calcprogrammer1@gmail.com), 12/15/2016 |
8 | \*---------------------------------------------------------*/
9 |
10 | #include "net_port.h"
11 | #define _WINSOCK_DEPRECATED_NO_WARNINGS // erkr
12 | #pragma warning(disable : 4996) //erkr
13 |
14 | #ifndef WIN32
15 | #include
16 | #include
17 | #include
18 | #endif
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | const char yes = 1;
25 |
26 | net_port::net_port()
27 | {
28 |
29 | }
30 |
31 | //net_port (constructor)
32 | // When created with port information, the constructor
33 | // will automatically open client address on port
34 | net_port::net_port(const char * client_name, const char * port)
35 | {
36 | udp_client(client_name, port);
37 | }
38 |
39 | net_port::~net_port()
40 | {
41 | freeaddrinfo(result_list);
42 | }
43 |
44 | bool net_port::udp_client(const char * client_name, const char * port)
45 | {
46 | sockaddr_in myAddress;
47 |
48 | #ifdef WIN32
49 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
50 | {
51 | WSACleanup();
52 | return(false);
53 | }
54 | #endif
55 |
56 | sock = socket(AF_INET, SOCK_DGRAM, 0);
57 | if (sock == INVALID_SOCKET)
58 | {
59 | WSACleanup();
60 | return(false);
61 | }
62 |
63 | myAddress.sin_family = AF_INET;
64 | myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
65 | myAddress.sin_port = htons(0);
66 |
67 | if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
68 | {
69 | WSACleanup();
70 | return false;
71 | }
72 |
73 | result_list = NULL;
74 | addrinfo hints = {};
75 | hints.ai_family = AF_INET;
76 | hints.ai_socktype = SOCK_DGRAM;
77 | if(getaddrinfo(client_name, port, &hints, &result_list) == 0)
78 | {
79 | memcpy(&addrDest, result_list->ai_addr, result_list->ai_addrlen);
80 | freeaddrinfo(result_list);
81 | return(true);
82 | }
83 | else
84 | {
85 | WSACleanup();
86 | return(false);
87 | }
88 | }
89 |
90 | int net_port::udp_listen(char * recv_data, int length)
91 | {
92 | return(recvfrom(sock, recv_data, length, 0, NULL, NULL));
93 | }
94 |
95 | int net_port::udp_write(char * buffer, int length)
96 | {
97 | return(sendto(sock, buffer, length, 0, (sockaddr *)&addrDest, sizeof(addrDest)));
98 | }
99 |
100 | bool net_port::tcp_client(const char * client_name, const char * port)
101 | {
102 | addrinfo hints = {};
103 |
104 | connected = false;
105 | result_list = NULL;
106 |
107 | #ifdef WIN32
108 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
109 | {
110 | WSACleanup();
111 | return(false);
112 | }
113 | #endif
114 |
115 | port = strtok((char *)port, "\r");
116 |
117 | hints.ai_family = AF_INET;
118 | hints.ai_socktype = SOCK_STREAM;
119 | getaddrinfo(client_name, port, &hints, &result_list);
120 |
121 | if(result_list == NULL)
122 | {
123 | WSACleanup();
124 | return(false);
125 | }
126 |
127 | return(true);
128 | }
129 |
130 | bool net_port::tcp_client_connect()
131 | {
132 | connected = false;
133 |
134 | {
135 | sock = socket(AF_INET, SOCK_STREAM, 0);
136 | if (sock == INVALID_SOCKET)
137 | {
138 | WSACleanup();
139 | return(false);
140 | }
141 |
142 | u_long arg = 1;
143 | fd_set fdset;
144 | timeval tv;
145 |
146 | ioctlsocket(sock, FIONBIO, &arg);
147 |
148 | if(result_list == NULL)
149 | {
150 | connected = false;
151 | return(false);
152 | }
153 | connect(sock, result_list->ai_addr, result_list->ai_addrlen);
154 |
155 | FD_ZERO(&fdset);
156 | FD_SET(sock, &fdset);
157 |
158 | tv.tv_sec = 4;
159 | tv.tv_usec = 0;
160 |
161 | /*-------------------------------------------------*\
162 | | Set socket options - no delay |
163 | \*-------------------------------------------------*/
164 | setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
165 |
166 | if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
167 | {
168 | char so_error;
169 | socklen_t len = sizeof(so_error);
170 |
171 | getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
172 |
173 | if (so_error == 0)
174 | {
175 | connected = true;
176 | arg = 0;
177 | ioctlsocket(sock, FIONBIO, &arg);
178 | }
179 | else
180 | {
181 | connected = false;
182 | closesocket(sock);
183 | }
184 | }
185 | else
186 | {
187 | connected = false;
188 | closesocket(sock);
189 | }
190 | }
191 | return(connected);
192 | }
193 |
194 | bool net_port::tcp_server(const char * port)
195 | {
196 | sockaddr_in myAddress;
197 |
198 | /*-------------------------------------------------*\
199 | | Windows requires WSAStartup before using sockets |
200 | \*-------------------------------------------------*/
201 | #ifdef WIN32
202 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
203 | {
204 | WSACleanup();
205 | return false;
206 | }
207 | #endif
208 |
209 | /*-------------------------------------------------*\
210 | | Create the server socket |
211 | \*-------------------------------------------------*/
212 | sock = socket(AF_INET, SOCK_STREAM, 0);
213 | if (sock == INVALID_SOCKET)
214 | {
215 | WSACleanup();
216 | return false;
217 | }
218 |
219 | /*-------------------------------------------------*\
220 | | Fill in server address info with port value |
221 | \*-------------------------------------------------*/
222 | port = strtok((char *)port, "\r");
223 |
224 | myAddress.sin_family = AF_INET;
225 | myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
226 | myAddress.sin_port = htons(atoi(port));
227 |
228 | /*-------------------------------------------------*\
229 | | Bind the server socket |
230 | \*-------------------------------------------------*/
231 | if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
232 | {
233 | WSACleanup();
234 | return false;
235 | }
236 |
237 | /*-------------------------------------------------*\
238 | | Set socket options - no delay |
239 | \*-------------------------------------------------*/
240 | setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
241 |
242 | return(true);
243 | }
244 |
245 | SOCKET * net_port::tcp_server_listen()
246 | {
247 | /*-------------------------------------------------*\
248 | | Create new socket for client connection |
249 | \*-------------------------------------------------*/
250 | SOCKET * client = new SOCKET();
251 |
252 | /*-------------------------------------------------*\
253 | | Listen for incoming client connection on the |
254 | | server socket. This call blocks until a |
255 | | connection is established |
256 | \*-------------------------------------------------*/
257 | listen(sock, 10);
258 |
259 | /*-------------------------------------------------*\
260 | | Accept the client connection |
261 | \*-------------------------------------------------*/
262 | *client = accept(sock, NULL, NULL);
263 |
264 | /*-------------------------------------------------*\
265 | | Get the new client socket and store it in the |
266 | | clients vector |
267 | \*-------------------------------------------------*/
268 | u_long arg = 0;
269 | ioctlsocket(*client, FIONBIO, &arg);
270 | setsockopt(*client, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
271 | clients.push_back(client);
272 |
273 | return client;
274 | }
275 |
276 | void net_port::tcp_close()
277 | {
278 | closesocket(sock);
279 | connected = false;
280 | }
281 |
282 | int net_port::tcp_listen(char * recv_data, int length)
283 | {
284 | return(recv(sock, recv_data, length, 0));
285 | }
286 |
287 | int net_port::tcp_client_write(char * buffer, int length)
288 | {
289 | return(send(sock, buffer, length, 0));
290 | }
291 |
292 | int net_port::tcp_write(char * buffer, int length)
293 | {
294 | int ret = length;
295 | int val = length;
296 |
297 | timeval waitd;
298 | fd_set writefd;
299 |
300 | for (unsigned int i = 0; i < clients.size(); i++)
301 | {
302 | val = length;
303 |
304 | FD_ZERO(&writefd);
305 | FD_SET(*(clients[i]), &writefd);
306 |
307 | waitd.tv_sec = 5;
308 | waitd.tv_usec = 0;
309 |
310 | if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
311 | {
312 | val = send(*(clients[i]), (const char *)&length, sizeof(length), 0);
313 |
314 | if (val == -1)
315 | {
316 | clients.erase(clients.begin() + i);
317 | return 0;
318 | }
319 | }
320 | else
321 | {
322 | clients.erase(clients.begin() + i);
323 | return 0;
324 | }
325 |
326 | waitd.tv_sec = 5;
327 | waitd.tv_usec = 0;
328 |
329 | if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
330 | {
331 | val = send(*(clients[i]), buffer, length, 0);
332 |
333 | if (val == -1)
334 | {
335 | clients.erase(clients.begin() + i);
336 | return 0;
337 | }
338 |
339 | if (val != length)
340 | {
341 | ret = val;
342 | }
343 | }
344 | else
345 | {
346 | clients.erase(clients.begin() + i);
347 | return 0;
348 | }
349 | }
350 | return(ret);
351 | }
352 |
--------------------------------------------------------------------------------
/OpenRGBPlugin/net_port.h:
--------------------------------------------------------------------------------
1 | /*---------------------------------------------------------*\
2 | | Cross Platform Network Library for Windows and Linux |
3 | | This library provides access to TCP and UDP ports with |
4 | | a common API for both Windows and Linux systems. It |
5 | | features read and write |
6 | | |
7 | | Adam Honse (calcprogrammer1@gmail.com), 12/15/2016 |
8 | \*---------------------------------------------------------*/
9 |
10 | #ifndef NET_PORT_H
11 | #define NET_PORT_H
12 |
13 | #include
14 |
15 | #ifdef _WIN32 // erkr
16 | #include
17 | #include
18 | #else
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #endif
28 |
29 | #ifndef _WIN32 // erkr
30 | #define SOCKET int
31 | #define ioctlsocket ioctl
32 | #define closesocket close
33 | #define WSACleanup()
34 | #define INVALID_SOCKET -1
35 | #define SOCKET_ERROR -1
36 | #define SD_RECEIVE SHUT_RD
37 | #endif
38 |
39 | //Network Port Class
40 | //The reason for this class is that network ports are treated differently
41 | //on Windows and Linux. By creating a class, those differences can be
42 | //made invisible to the program and make cross-platform usage easy
43 |
44 | class net_port
45 | {
46 | public:
47 | net_port();
48 | net_port(const char * client_name, const char * port);
49 |
50 | ~net_port();
51 |
52 | //Function to open the port
53 | bool udp_client(const char* client_name, const char * port);
54 | bool tcp_client(const char* client_name, const char * port);
55 | bool tcp_client_connect();
56 |
57 | //Function to open a server
58 | bool tcp_server(const char * port);
59 | std::size_t tcp_server_num_clients();
60 | SOCKET * tcp_server_get_client(std::size_t client_idx);
61 | SOCKET * tcp_server_listen();
62 |
63 | int udp_listen(char * recv_data, int length);
64 | int tcp_listen(char * recv_data, int length);
65 |
66 | //Function to write data to the serial port
67 | int udp_write(char * buffer, int length);
68 | int tcp_write(char * buffer, int length);
69 | int tcp_client_write(char * buffer, int length);
70 |
71 | void tcp_close();
72 |
73 | bool connected;
74 | SOCKET sock;
75 |
76 | private:
77 | #ifdef WIN32
78 | WSADATA wsa;
79 | #endif
80 |
81 | std::vector clients;
82 |
83 | sockaddr addrDest;
84 | addrinfo* result_list;
85 | };
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/RGBLightPlugin.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30204.135
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MysticLightPlugin", "MysticLightPlugin\MysticLightPlugin.vcxproj", "{A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcxitems", "{86A4B606-80FC-4D9F-BD44-7AF927AB2DE9}"
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenRGBPlugin", "OpenRGBPlugin\OpenRGBPlugin.vcxproj", "{4959ADC4-C80B-4750-9927-C349B569D7AC}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E9BFDEA2-2003-4300-8E50-2FA50BA41C2A}"
13 | ProjectSection(SolutionItems) = preProject
14 | LICENSE = LICENSE
15 | readme.md = readme.md
16 | EndProjectSection
17 | EndProject
18 | Global
19 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
20 | Common\Common.vcxitems*{4959adc4-c80b-4750-9927-c349b569d7ac}*SharedItemsImports = 4
21 | Common\Common.vcxitems*{86a4b606-80fc-4d9f-bd44-7af927ab2de9}*SharedItemsImports = 9
22 | Common\Common.vcxitems*{a5b7f71e-0d88-4f5f-851c-ff5d98fc100e}*SharedItemsImports = 4
23 | EndGlobalSection
24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
25 | Debug|Win32 = Debug|Win32
26 | Debug|x64 = Debug|x64
27 | Release|Win32 = Release|Win32
28 | Release|x64 = Release|x64
29 | EndGlobalSection
30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
31 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Debug|Win32.ActiveCfg = Debug|Win32
32 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Debug|Win32.Build.0 = Debug|Win32
33 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Debug|x64.ActiveCfg = Debug|x64
34 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Debug|x64.Build.0 = Debug|x64
35 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Release|Win32.ActiveCfg = Release|x64
36 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Release|Win32.Build.0 = Release|x64
37 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Release|x64.ActiveCfg = Release|x64
38 | {A5B7F71E-0D88-4F5F-851C-FF5D98FC100E}.Release|x64.Build.0 = Release|x64
39 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Debug|Win32.ActiveCfg = Debug|Win32
40 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Debug|Win32.Build.0 = Debug|Win32
41 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Debug|x64.ActiveCfg = Debug|x64
42 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Debug|x64.Build.0 = Debug|x64
43 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Release|Win32.ActiveCfg = Release|Win32
44 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Release|Win32.Build.0 = Release|Win32
45 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Release|x64.ActiveCfg = Release|x64
46 | {4959ADC4-C80B-4750-9927-C349B569D7AC}.Release|x64.Build.0 = Release|x64
47 | EndGlobalSection
48 | GlobalSection(SolutionProperties) = preSolution
49 | HideSolutionNode = FALSE
50 | EndGlobalSection
51 | GlobalSection(ExtensibilityGlobals) = postSolution
52 | SolutionGuid = {115B3B1F-7938-49D4-B5D7-62FB9CEBC028}
53 | EndGlobalSection
54 | EndGlobal
55 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # RGBPlugins for CoreTemp
2 | A [CoreTemp](https://www.alcpu.com/CoreTemp/) (alcpu) plugin , that controls your PC RGB LEDs based on the actual CPU temperature and CPU load.
3 | The colors (can be adjusted) are mapped from blue for cold to cyan->green->yellow->Red for Warm up to violet for critical.
4 |
5 |
6 |
7 | The intensity is based on the CPU load (can be disabled).
8 |
9 | ## Motherboard support.
10 | The RGBPlugins solution contains two projects. Just use the one that fits your needs:
11 | * **MSI MysticLight**: For MSI boards supporting the [MSI MysticLight SDK](http://download.msi.com/uti_exe/Mystic_light_SDK.zip). You need to install the MSI DragonCenter service with the MysticLight addon.
12 | * **OpenRGB**: For all Boards supported by the open source project [OpenRGB](https://gitlab.com/CalcProgrammer1/OpenRGB). You need to run the OpenRGB package with the Server SDK enabled.
13 |
14 | Some considerations:
15 | * The MSI Mysticlight SDK was not relaiable for a long time. Since the latest version (included in the package) it seems to connect fine. One issue (at least on my Motherboard) is that the LEDs briefly flicker every time they get a new setting.
16 | * OpenRGB is a very ambitious new open source project that aims to control all RGB PC devices via one interface. It is not yet very mature (as I speak it is version 0.4). It supports my MSI Motherboard board, but at startup it often doesn’t recognize the RGB hardware.
17 |
18 | ## Install notes:
19 | Create a plugins directory in your CoreTemp folder if it not yet exists. e.g.: `C:\Program Files\Core Temp\plugins`
20 | Within that folder, a sub-directory is needed for every CoreTemp plugin. e.g.: `C:\Program Files\Core Temp\plugins\RGB`
21 | Depending if you have a 32 or 64 bits version of CoreTemp, you copy the 32 or 64 bits version of the RGBplugin into the RGB plugin folder.
22 | If you use the MSI plugin version, the 32 or 64 bits SDK DLL needs to be added there as well.
23 | With a good old INI-file the temperature-color mapping can be adjusted. Just press the configure button in the CoreTemp plugin manager.
24 | It will launch Notepad with the plugin ini file. In this INI-file both the temperature ranges and the corresponding color ranges can be adjusted.
25 |
26 | When Notepad is closed, the new settings wil be loaded.
27 |
28 | ## PlugIn setting in the INI-File:
29 | ```
30 | [OpenRGB_Settings] // only applicable for the OpenRGB version
31 | OpenRGBIP=127.0.0.1 // default for local host
32 | OpenRGBPort=6742 // the default port for the Open RGB Server
33 | OpenRGBMode=0 // Needs to be the direct mode, normally the first one
34 | [General_Settings]
35 | doBeepForExceptions=0 // if not zero the plugin will beep when the MSI/OpnRGB SDK throws an exception
36 | ControlIdx=0 // The RGB device index to be used.
37 | [Core_Temp_Mappings]
38 | TColdBelow=25 // All CPU temps below this threshold have the HUECold color (default is Blue)
39 | TWarm=55 // The CPU Warm temperature (default color RED)
40 | THot=60 // The CPU Hot temperature (default color RED up to this temperature)
41 | TCriticalAbove=80 // The CPU Critical temperature (Violet above this temperature)
42 | [Core_Load_Mappings]
43 | LoadBasedIntensity=1 // Default is 1 where the itensity is based on the CPU load. Set to 0 to disable
44 | ILowPct=10 // Intensity for 0% CPU load
45 | IHighPct=100 // Intensity for 100% CPU load
46 | [Color_HUE360_Mappings]// Colors are defined as a 360 hue circle. Values below 0 or above 360 will work as well! -360=0=360=720 etc
47 | HUECold=240 // Start color (default 240 = Blue)
48 | HRangeCold2Warm=-240 // The HUE range from Cold to Warm. Default -240, (from 240 down to 0 : blue->cyan->green->yellow->Red)
49 | HRangeWarm2Hot=0 // Default no color change between Warm to Hot (all RED)
50 | HRangeHot2Critical=-20 // Default -20 (from 0 down to -20: Red to violet)
51 | ```
52 | The HUE 0-360 scale:
53 |
54 |
55 | The code was compiled, using VS2019 Version 16.6.2
56 |
57 | Success.
58 |
--------------------------------------------------------------------------------