Skip to content

Commit 6df54ce

Browse files
committed
Added OFF-mode and Temperature-based mode.
1 parent 882f504 commit 6df54ce

5 files changed

Lines changed: 173 additions & 11 deletions

File tree

MSI LED Tool/AnimationType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public enum AnimationType
55
NoAnimation = 1,
66
Breathing = 2,
77
Flashing = 3,
8-
DoubleFlashing = 4
8+
DoubleFlashing = 4,
9+
Off = 5,
10+
TemperatureBased = 6
911
}
1012
}

MSI LED Tool/LedSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ public class LedSettings
1616

1717
[DataMember]
1818
public int B { get; set; }
19+
20+
[DataMember]
21+
public int TemperatureUpperLimit { get; set; }
22+
23+
[DataMember]
24+
public int TemperatureLowerLimit { get; set; }
1925
}
2026
}

MSI LED Tool/Program.cs

Lines changed: 159 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.IO;
55
using System.Linq;
6+
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78
using System.Threading;
89
using System.Windows.Forms;
@@ -48,6 +49,7 @@ class Program
4849
private static Color ledColor;
4950
private static AnimationType animationType;
5051
private static Manufacturer manufacturer;
52+
private static int[] temperatureLimits;
5153

5254
static void Main(string[] args)
5355
{
@@ -64,6 +66,23 @@ static void Main(string[] args)
6466
{
6567
ledColor = Color.FromArgb(255, settings.R, settings.G, settings.B);
6668
animationType = settings.AnimationType;
69+
70+
if (settings.TemperatureLowerLimit < 0)
71+
{
72+
settings.TemperatureLowerLimit = 0;
73+
}
74+
75+
if (settings.TemperatureUpperLimit > 100)
76+
{
77+
settings.TemperatureUpperLimit = 100;
78+
}
79+
80+
if (settings.TemperatureUpperLimit <= settings.TemperatureLowerLimit)
81+
{
82+
settings.TemperatureUpperLimit = settings.TemperatureLowerLimit + 1;
83+
}
84+
85+
temperatureLimits = new[] { settings.TemperatureLowerLimit, settings.TemperatureUpperLimit};
6786
}
6887
}
6988
}
@@ -77,7 +96,9 @@ static void Main(string[] args)
7796
R = 255,
7897
G = 0,
7998
B = 0,
80-
AnimationType = AnimationType.NoAnimation
99+
AnimationType = AnimationType.NoAnimation,
100+
TemperatureUpperLimit = 85,
101+
TemperatureLowerLimit = 45,
81102
}));
82103
}
83104
}
@@ -147,7 +168,7 @@ private static bool InitializeNvidiaAdapters(long gpuCount)
147168
{
148169
for (int i = 0; i < gpuCount; i++)
149170
{
150-
NdaGraphicsInfo graphicsInfo;
171+
NdaGraphicsInfo graphicsInfo;
151172
if (NDA_GetGraphicsInfo(i, out graphicsInfo) == false)
152173
{
153174
return false;
@@ -177,7 +198,7 @@ private static bool InitializeAmdAdapters(int gpuCount)
177198
{
178199
return false;
179200
}
180-
201+
181202
// PCI\VEN_1002&DEV_67DF&SUBSYS_34111462&REV_CF\4&25438C51&0&0008
182203
var pnpSegments = graphicsInfo.Card_PNP.Split('\\');
183204

@@ -227,6 +248,34 @@ private static void UpdateLedsFront()
227248
case AnimationType.DoubleFlashing:
228249
UpdateLeds(30, 4, 0, 10, 10, 91);
229250
break;
251+
case AnimationType.Off:
252+
UpdateLeds(24, 4, 4);
253+
break;
254+
case AnimationType.TemperatureBased:
255+
switch (manufacturer)
256+
{
257+
case Manufacturer.Nvidia:
258+
NdaGraphicsInfo ndaGraphicsInfo;
259+
if (NDA_GetGraphicsInfo(0, out ndaGraphicsInfo))
260+
{
261+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
262+
temperatureLimits[1], ndaGraphicsInfo.GPU_Temperature_Current);
263+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
264+
UpdateLeds(21, 4, 4);
265+
}
266+
break;
267+
case Manufacturer.AMD:
268+
AdlGraphicsInfo adlGraphicsInfo;
269+
if (ADL_GetGraphicsInfo(0, out adlGraphicsInfo))
270+
{
271+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
272+
temperatureLimits[1], adlGraphicsInfo.GPU_Temperature_Current);
273+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
274+
UpdateLeds(21, 4, 4);
275+
}
276+
break;
277+
}
278+
break;
230279
}
231280
}
232281
}
@@ -250,6 +299,34 @@ private static void UpdateLedsSide()
250299
case AnimationType.DoubleFlashing:
251300
UpdateLeds(30, 1, 0, 10, 10, 91);
252301
break;
302+
case AnimationType.Off:
303+
UpdateLeds(24, 1, 4);
304+
break;
305+
case AnimationType.TemperatureBased:
306+
switch (manufacturer)
307+
{
308+
case Manufacturer.Nvidia:
309+
NdaGraphicsInfo ndaGraphicsInfo;
310+
if (NDA_GetGraphicsInfo(0, out ndaGraphicsInfo))
311+
{
312+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
313+
temperatureLimits[1], ndaGraphicsInfo.GPU_Temperature_Current);
314+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
315+
UpdateLeds(21, 1, 4);
316+
}
317+
break;
318+
case Manufacturer.AMD:
319+
AdlGraphicsInfo adlGraphicsInfo;
320+
if (ADL_GetGraphicsInfo(0, out adlGraphicsInfo))
321+
{
322+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
323+
temperatureLimits[1], adlGraphicsInfo.GPU_Temperature_Current);
324+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
325+
UpdateLeds(21, 1, 4);
326+
}
327+
break;
328+
}
329+
break;
253330
}
254331
}
255332
}
@@ -272,6 +349,34 @@ private static void UpdateLedsBack()
272349
case AnimationType.DoubleFlashing:
273350
UpdateLeds(30, 2, 0, 10, 10, 91);
274351
break;
352+
case AnimationType.Off:
353+
UpdateLeds(24, 2, 4);
354+
break;
355+
case AnimationType.TemperatureBased:
356+
switch (manufacturer)
357+
{
358+
case Manufacturer.Nvidia:
359+
NdaGraphicsInfo ndaGraphicsInfo;
360+
if (NDA_GetGraphicsInfo(0, out ndaGraphicsInfo))
361+
{
362+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
363+
temperatureLimits[1], ndaGraphicsInfo.GPU_Temperature_Current);
364+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
365+
UpdateLeds(21, 2, 4);
366+
}
367+
break;
368+
case Manufacturer.AMD:
369+
AdlGraphicsInfo adlGraphicsInfo;
370+
if (ADL_GetGraphicsInfo(0, out adlGraphicsInfo))
371+
{
372+
int temperatureDelta = CalculateTemperatureDeltaHunderdBased(temperatureLimits[0],
373+
temperatureLimits[1], adlGraphicsInfo.GPU_Temperature_Current);
374+
ledColor = GetColorForDeltaTemperature(temperatureDelta);
375+
UpdateLeds(21, 2, 4);
376+
}
377+
break;
378+
}
379+
break;
275380
}
276381
}
277382
}
@@ -292,20 +397,67 @@ private static void UpdateLeds(int cmd, int ledId, int time, int ontime = 0, int
292397

293398
if (manufacturer == Manufacturer.Nvidia)
294399
{
295-
NDA_SetIlluminationParmColor_RGB(i, cmd, ledId, 0, ontime, offtime, time, darkTime, 0, ledColor.R,
296-
ledColor.G, ledColor.B, oneCall);
400+
NDA_SetIlluminationParmColor_RGB(i, cmd, ledId, 0, ontime, offtime, time, darkTime, 0, ledColor.R, ledColor.G, ledColor.B, oneCall);
297401
}
298402

299403
if (manufacturer == Manufacturer.AMD)
300404
{
301-
ADL_SetIlluminationParm_RGB(i, cmd, ledId, 0, ontime, offtime, time, darkTime, 0, ledColor.R,
302-
ledColor.G, ledColor.B, oneCall);
405+
ADL_SetIlluminationParm_RGB(i, cmd, ledId, 0, ontime, offtime, time, darkTime, 0, ledColor.R, ledColor.G, ledColor.B, oneCall);
303406
}
304407

305408
vgaMutex = false;
306409
}
307410

308411
Thread.CurrentThread.Join(2000);
309412
}
413+
414+
private static int CalculateTemperatureDeltaHunderdBased(int upperLimit, int lowerLimit, int current)
415+
{
416+
try
417+
{
418+
var difference = upperLimit - lowerLimit;
419+
if (difference <= 0)
420+
{
421+
return 50;
422+
}
423+
424+
return (current/difference*100);
425+
}
426+
catch
427+
{
428+
return 50;
429+
}
430+
}
431+
432+
private static Color GetColorForDeltaTemperature(int x)
433+
{
434+
return Color.FromArgb(GetRedForDeltaTemperature(x), GetGreenForDeltaTemperature(x), 0);
435+
}
436+
437+
private static int GetRedForDeltaTemperature(int x)
438+
{
439+
var percent = x/100.0f;
440+
var value = Convert.ToInt32(percent * 255 * 2);
441+
442+
if (value > 255)
443+
{
444+
return 255;
445+
}
446+
447+
return value;
448+
}
449+
450+
private static int GetGreenForDeltaTemperature(int x)
451+
{
452+
var percent = x / 100.0f;
453+
var value = Convert.ToInt32((255 - percent * 255) * 2);
454+
455+
if (value > 255)
456+
{
457+
return 255;
458+
}
459+
460+
return value;
461+
}
310462
}
311463
}

MSI LED Tool/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.2.0.0")]
35-
[assembly: AssemblyFileVersion("1.2.0.0")]
34+
[assembly: AssemblyVersion("1.3.0.0")]
35+
[assembly: AssemblyFileVersion("1.3.0.0")]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ It supports a fixed color, breathing mode, flashing mode and double flashing mod
66
# Installation
77
* To install the tool you place the "MSI LED Tool" executable, the "Settings.json" file and the included "Lib" folder in whichever folder you desire to be its location.
88
* You have to point the path in the "regedit.reg" accordingly to your newly created and selected folder.
9-
* Open the Settings.json file to change the R(ed), G(reen), B(lue) variables to your desired color scheme and set the AnimationType variable to your desired animation type. "AnimationType":1 means no animation.
9+
* Open the Settings.json file to change the R(ed), G(reen), B(lue) variables to your desired color scheme and set the AnimationType variable to your desired animation type. "AnimationType":1 means no animation. When selecting the "Temperature Based" mode. The Upper- and LowerLimit options define the full green (lower) and full red (upper) numbers. So 45-85 means that anything from 45C and lower is 100% green and anything from 85C and upper is 100% red. It will then colorize from green to yellow to orange to red as your GPU temperature changes.
1010
* 1 = No Animation
1111
* 2 = Breathing
1212
* 3 = Flashing
1313
* 4 = Double Flashing
14+
* 5 = Disable LEDs
15+
* 6 = Temperature Based
1416
* Run the "MSI LED Tool" executable and if you like what you see, run the "regedit.reg" file to register the tool to startup upon Windows boot, after which it will automatically apply your configured settings.
1517

1618
# Releases

0 commit comments

Comments
 (0)