diff --git a/MSI-LED-Custom/Form1.cs b/MSI-LED-Custom/Form1.cs index 6012dab..7b94186 100644 --- a/MSI-LED-Custom/Form1.cs +++ b/MSI-LED-Custom/Form1.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,20 +7,27 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Timers; +using System.Threading; namespace MSI_LED_Custom { public partial class Form1 : Form { - public Form1() + bool updateAll; + System.Timers.Timer updateAllTimer; + private readonly SynchronizationContext syncContext; + public Form1(bool updateAll) { + this.updateAll = updateAll; InitializeComponent(); + syncContext = SynchronizationContext.Current; } private void Form1_Load(object sender, EventArgs e) { label1.Text = Program.ledColor.ToString(); - label4.Text = Program.adapterIndexes.Count.ToString(); + label4.Text = Program.adapterIndexes.Count.ToString(); textBox1.Text = Program.ledColor.R.ToString(); textBox2.Text = Program.ledColor.G.ToString(); @@ -28,6 +35,8 @@ private void Form1_Load(object sender, EventArgs e) textBox4.Text = Program.tempMin.ToString(); textBox5.Text = Program.tempMax.ToString(); + comboBox1.SelectedIndex = (int)Program.animationType; + } private void button1_Click(object sender, EventArgs e) @@ -56,13 +65,13 @@ private void button1_Click(object sender, EventArgs e) { textBox3.Text = "0"; } - + Program.ledColor = Color.FromArgb(255, Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text), Int32.Parse(textBox3.Text)); label1.Text = Program.ledColor.ToString(); Program.tempMin = Int32.Parse(textBox4.Text); Program.tempMax = Int32.Parse(textBox5.Text); - + Program.ledManager.UpdateAll(Program.ledColor, AnimationType.Off, Program.tempMin, Program.tempMax); Program.ledManager.UpdateAll(Program.ledColor, Program.animationType, Program.tempMin, Program.tempMax); Properties.Settings.Default["Color"] = Program.ledColor; @@ -75,31 +84,31 @@ private void button1_Click(object sender, EventArgs e) private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { - switch ( comboBox1.SelectedIndex ) + switch (comboBox1.SelectedIndex) { case (int)AnimationType.NoAnimation: - Program.animationType = AnimationType.NoAnimation; - break; + Program.animationType = AnimationType.NoAnimation; + break; case (int)AnimationType.Breathing: - Program.animationType = AnimationType.Breathing; - break; + Program.animationType = AnimationType.Breathing; + break; case (int)AnimationType.Flashing: - Program.animationType = AnimationType.Flashing; - break; + Program.animationType = AnimationType.Flashing; + break; case (int)AnimationType.DoubleFlashing: - Program.animationType = AnimationType.DoubleFlashing; - break; + Program.animationType = AnimationType.DoubleFlashing; + break; case (int)AnimationType.Off: - Program.animationType = AnimationType.Off; - break; + Program.animationType = AnimationType.Off; + break; case (int)AnimationType.TemperatureBased: - Program.animationType = AnimationType.TemperatureBased; - break; + Program.animationType = AnimationType.TemperatureBased; + break; } } @@ -123,5 +132,33 @@ private void label9_Click(object sender, EventArgs e) { } + + private void Form1_Shown(object sender, EventArgs e) + { + if (this.updateAll) + { + this.WindowState = FormWindowState.Minimized; + updateAllTimer = new System.Timers.Timer(20000); // через 20 секунд программа закроется + updateAllTimer.AutoReset = false; + updateAllTimer.Elapsed += updateTimer; + updateAllTimer.Enabled = true; + updateAllTimer.Start(); + + } + } + void updateTimer(Object source, System.Timers.ElapsedEventArgs e) + { + FormClose(); + + } + private void FormClose() + { + syncContext.Post(FormClose2, null); + } + + private void FormClose2(object temp) + { + this.Close(); + } } } diff --git a/MSI-LED-Custom/Program.cs b/MSI-LED-Custom/Program.cs index b935686..1520597 100644 --- a/MSI-LED-Custom/Program.cs +++ b/MSI-LED-Custom/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; +using System.Timers; namespace MSI_LED_Custom { @@ -16,7 +17,7 @@ static class Program /// /// - + public static bool overwriteSecurityChecks; public static List adapterIndexes; public static Manufacturer manufacturer; @@ -30,14 +31,17 @@ static class Program public static int tempMax = 70; - public static string vendorCode = "N/A"; - public static string deviceCode = "N/A"; + public static string vendorCode = "N/A"; + public static string deviceCode = "N/A"; public static string subVendorCode = "N/A"; public static string[] args; + static bool updateAll = false; + + [STAThread] - static void Main(String[] args ) + static void Main(String[] args) { if (Properties.Settings.Default["Color"] is Color) @@ -71,6 +75,11 @@ static void Main(String[] args ) { overwriteSecurityChecks = true; } + else if (args[i].Equals("updateAll")) + { + updateAll = true; + + } } int gpuCountNda = 0; @@ -102,17 +111,15 @@ static void Main(String[] args ) } } - + ledManager = new LedManager_Common(manufacturer, animationType); ledManager.InitLedManagers(); ledManager.StartAll(); ledManager.UpdateAll(ledColor, animationType, tempMin, tempMax); - Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new Form1(updateAll)); - ledManager.StopAll(); } @@ -169,15 +176,15 @@ private static bool InitializeNvidiaAdapters(int gpuCount) { for (int i = 0; i < gpuCount; i++) { - + if (_NDA.NDA_GetGraphicsInfo(i, out NdaGraphicsInfo) == false) { return false; } - string deviceCode = NdaGraphicsInfo.Card_pDeviceId.Substring(0, 4).ToUpper(); - string vendorCode = NdaGraphicsInfo.Card_pDeviceId.Substring(4, 4).ToUpper(); - string subVendorCode = NdaGraphicsInfo.Card_pSubSystemId.Substring(4, 4).ToUpper(); + deviceCode = NdaGraphicsInfo.Card_pDeviceId.Substring(0, 4).ToUpper(); + vendorCode = NdaGraphicsInfo.Card_pDeviceId.Substring(4, 4).ToUpper(); + subVendorCode = NdaGraphicsInfo.Card_pSubSystemId.Substring(4, 4).ToUpper(); if (overwriteSecurityChecks) { diff --git a/README.md b/README.md index c5ad2e1..7237436 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ You have the choice between : 5. Off 6. Temperature Based +You can start program with 'updateAll' arg and it will apply color settings and close after 20 seconds. Usefull for autostart with Windows. + ## Why there is no motherboard support ? The control of the motherboard need to communicate with a kernel driver, and I don't know anything about this, but you can read more about this here : https://github.com/nagisa/msi-rgb/