private void _Mode_SelectionChanged(object sender, SelectionChangedEventArgs e) { EC ec = SingleInstanceManager.Instance.ec; var config = SingleInstanceManager.Instance.cfg; var item = sender as ComboBox; lock (SingleInstanceManager.Instance.controller) { if (item.SelectedIndex == 4) { SingleInstanceManager.Instance.controller.ShouldUpdate = true; } else { if (config.FanMode == 4) { ec.SetFanModeAuto(); } SingleInstanceManager.Instance.controller.ShouldUpdate = false; } } if (item.SelectedIndex >= 0 && item.SelectedIndex < 7 && item.SelectedIndex != 4) { ec.SetWMI(121, 1, Convert.ToUInt32(item.SelectedIndex)); } config.FanMode = item.SelectedIndex; }
void UpdateInfo() { EC ec = SingleInstanceManager.Instance.ec; //Cpu Cpu.Info_1_Data.Text = PercentToStrConvert(cpu_Helper.GetCPUTotalUsage()); Cpu.Info_2_Data.Text = TempToStrConvert(ec.Cpu_Temp); //Gpu if (Gpu_1.Visibility == Visibility.Visible) { uint gpu, mem; NV_Queries.nv_getUtilizationRatesByIndex(0, out mem, out gpu); Gpu_1.Info_1_Data.Text = PercentToStrConvert(gpu); Gpu_1.Info_2_Data.Text = TempToStrConvert(ec.Gpu1_Temp); } if (Gpu_2.Visibility == Visibility.Visible) { uint gpu, mem; NV_Queries.nv_getUtilizationRatesByIndex(1, out mem, out gpu); Gpu_2.Info_1_Data.Text = PercentToStrConvert(gpu); Gpu_2.Info_2_Data.Text = TempToStrConvert(ec.Gpu2_Temp); } //Fan Fan_1.UpdataFanInfo(ec.Fan_1.RPM, ec.Fan_1.Duty); if (Fan_2.Visibility == Visibility.Visible) { Fan_2.UpdataFanInfo(ec.Fan_2.RPM, ec.Fan_2.Duty); } if (Fan_3.Visibility == Visibility.Visible) { Fan_3.UpdataFanInfo(ec.Fan_3.RPM, ec.Fan_3.Duty); } }
private void onEC_Event(object sender, CustomEventArgs e) { Config config = SingleInstanceManager.Instance.cfg; EC ec = SingleInstanceManager.Instance.ec; lock (this) { int fanmode = 0; switch (e.Message) { case "106": //MaxQ fanmode = 5; ec.SetWMI(121, 0, (uint)fanmode); goto Save; case "107": //EC Custom fanmode = 6; ec.SetWMI(121, 0, (uint)fanmode); goto Save; case "112": //EC Auto(default value) if (config.FanMode == 4) { ShouldUpdate = true; //switch to our fan } else { fanmode = 0; ec.SetWMI(121, 0, (uint)fanmode); } goto Save; case "143": //Max fanmode = 1; if (config.FanMode == 4) { ec.SetWMI(121, 0, (uint)0); //need to set auto first,or it may struck sometime } ec.SetWMI(121, 0, (uint)fanmode); goto Save; } return; Save: if (!(config.FanMode == 4)) { config.FanMode = fanmode;//Not our fan, save config } else if (fanmode != 0) { ShouldUpdate = false; } } }
protected override bool OnStartup(StartupEventArgs e) { // First time app is launched ec = new EC(); cfg = new Config(); tray = new Tray(); ols = new Ols(); supportMSR = ols.GetStatus() == (uint)Ols.Status.NO_ERROR && ols.GetDllStatus() == (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR; supportNVSMI = InitNVSMI(); InitMonitor(); tray.AddTrayIcon(); controller = new Controller(cfg.FanCount, TimeSpan.FromMilliseconds(cfg.PollSpan)); SetAutoStart(); Application.ApplicationExit += onExit; Application.Run(); return(false); }
public Monitor(EC ec, int Gpu_Num, int FanNum, TimeSpan updatespan, TimeSpan duration) { this.ec = ec; Update_Interval = (int)updatespan.TotalMilliseconds; if (!(Gpu_Num <= 2 && Gpu_Num >= 0)) { throw new ArgumentException("Gpu_Num"); } //Intel Power unit if (SingleInstanceManager.Instance.supportMSR) { uint index = 0x606, eax = 0, edx = 0; SingleInstanceManager.Instance.ols.Rdmsr(index, ref eax, ref edx); Power_Unit = Math.Pow(0.5, eax & 0xF); Enery_Status_Unit = Math.Pow(0.5, (eax >> 8) & 0xF); //Init Power data getPowerByIndex(0x64D); getPowerByIndex(0x611); if (lastJ[1] != 0)//0 means not support { Plt_P = new MonitorData("Plt_P", updatespan, new SolidColorBrush(Colors.DarkSlateGray), duration); } } //Cpu Monitor Cpu_T = new MonitorData("Cpu_T", updatespan, new SolidColorBrush(Colors.Red), duration); if (SingleInstanceManager.Instance.supportMSR) { Cpu_P = new MonitorData("Cpu_P", updatespan, new SolidColorBrush(Colors.DarkRed), duration); } //Gpu Monitor if (Gpu_Num > 0) { Gpu_1_Temp = new MonitorData("Gpu 1_T", updatespan, new SolidColorBrush(Colors.Orange), duration); if (SingleInstanceManager.Instance.supportNVSMI) { Gpu_1_Power = new MonitorData("Gpu 1_P", updatespan, new SolidColorBrush(Colors.DarkOrange), duration); } if (Gpu_Num == 2) { Gpu_2_Temp = new MonitorData("Gpu 2_T", updatespan, new SolidColorBrush(Colors.Blue), duration); if (SingleInstanceManager.Instance.supportNVSMI) { Gpu_2_Power = new MonitorData("Gpu 2_P", updatespan, new SolidColorBrush(Colors.DarkBlue), duration); } } } Fan_1 = new MonitorData("Fan 1", updatespan, new SolidColorBrush(Colors.Green), duration); if (FanNum >= 2) { Fan_2 = new MonitorData("Fan 2", updatespan, new SolidColorBrush(Colors.Chocolate), duration); } if (FanNum == 3) { Fan_3 = new MonitorData("Fan 3", updatespan, new SolidColorBrush(Colors.RoyalBlue), duration); } //Listen Sleep Event SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; MonitorThread = new Thread(new ThreadStart(MonitorMethod)); MonitorThread.Name = "MonitorThread"; MonitorThread.Priority = ThreadPriority.Highest; MonitorThread.Start(); }