Disabling Nuvoton NCT6791D because of fan full speed bug on Asus Z97 WS.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
15 using System.Diagnostics;
16 using System.Windows.Forms;
18 using OpenHardwareMonitor.Hardware;
19 using OpenHardwareMonitor.Utilities;
20 using System.Runtime.InteropServices;
24 namespace OpenHardwareMonitor.GUI
26 public class SoundGraphDisplay : IDisposable
28 private IComputer computer;
29 private PersistentSettings settings;
30 private UnitManager unitManager;
31 private List<SensorFrontView> list = new List<SensorFrontView>();
32 private SoundGraph.Server iServer;
34 private int iNextSensorToDisplay=0;
35 private int iTickCounter=0;
38 public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
39 UnitManager unitManager)
41 this.computer = computer;
42 this.settings = settings;
43 this.unitManager = unitManager;
44 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
45 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
47 //Start our client if needed
48 Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
49 if (!(processes.Length > 0))
53 //Try to launch the sound graph process from the same folder as this executable
54 string exeName = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
55 exeName += @"\SoundGraphAccess.exe";
56 Process client = UserAccountControl.CreateProcessAsStandardUser(exeName, "");
60 Debug.WriteLine("SoundGraphAccess.exe start-up failed: " + e.ToString());
64 //Start our SoundGraph server
65 iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
69 private void HardwareRemoved(IHardware hardware)
71 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
72 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
73 foreach (ISensor sensor in hardware.Sensors)
74 SensorRemoved(sensor);
75 foreach (IHardware subHardware in hardware.SubHardware)
76 HardwareRemoved(subHardware);
79 private void HardwareAdded(IHardware hardware)
81 foreach (ISensor sensor in hardware.Sensors)
83 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
84 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
85 foreach (IHardware subHardware in hardware.SubHardware)
86 HardwareAdded(subHardware);
89 private void SensorAdded(ISensor sensor)
91 if (settings.GetValue(new Identifier(sensor.Identifier,
92 "FrontView").ToString(), false))
96 private void SensorRemoved(ISensor sensor)
99 Remove(sensor, false);
102 public void Dispose()
104 foreach (SensorFrontView icon in list)
112 public void Redraw(bool aPacked, bool aDisplayTime)
114 const int KNumberOfTickBeforeSwitch = 4;
115 const int KMaxCharacterPerLine = 16;
116 string packedFirstLine=""; //We have 16 chars per line on our VFD
117 string packedSecondLine="";
120 string time = DateTime.Now.ToShortTimeString();
122 //Update all sensors from our front view
123 foreach (SensorFrontView sensor in list)
128 if (aDisplayTime && count == 1)
130 //First slot is take by time display
132 packedFirstLine = time + " ";
137 //Build strings for packed mode
138 string packedText = "";
139 packedText = sensor.iFirstLine.Substring(0, 3) + ":" + sensor.iSecondLine;
142 packedFirstLine = packedText + " "; //Minimum one space to separate sensors on the same line
146 //Add enough spaces to align to right hand side
147 while (packedFirstLine.Length + packedText.Length < KMaxCharacterPerLine)
149 packedFirstLine += " ";
151 packedFirstLine += packedText;
155 packedSecondLine = packedText + " "; //Minimum one space to separate sensors on the same line
159 //Add enough spaces to align to right hand side
160 while (packedSecondLine.Length + packedText.Length < KMaxCharacterPerLine)
162 packedSecondLine += " ";
164 packedSecondLine += packedText;
167 //SetText(sensor.iFirstLine, sensor.iSecondLine);
170 //Alternate between sensors
175 //string packedLine = "";
177 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
180 if (iNextSensorToDisplay==1)
182 iNextSensorToDisplay=0;
186 iNextSensorToDisplay=1;
190 //TODO: Do something like that to cycle lines if ever we want to
191 //SetText(time, (iNextSensorToDisplay == 1 && packedSecondLine.Length > 0 ? packedSecondLine : packedFirstLine));
193 //Display packed sensors on our FrontView display
194 SetText(packedFirstLine, packedSecondLine);
198 string secondLine = list[iNextSensorToDisplay].iSecondLine;
202 while (secondLine.Length + time.Length < KMaxCharacterPerLine)
208 //Display current sensor on our FrontView display
209 SetText(list[iNextSensorToDisplay].iFirstLine, secondLine);
211 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
214 iNextSensorToDisplay++;
219 if (iNextSensorToDisplay == list.Count)
221 //Go back to first sensor
222 iNextSensorToDisplay = 0;
228 public bool Contains(ISensor sensor)
230 foreach (SensorFrontView icon in list)
231 if (icon.Sensor == sensor)
236 public void Add(ISensor sensor, bool balloonTip)
238 if (Contains(sensor))
245 list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
246 //UpdateMainIconVisibilty();
247 settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
248 iNextSensorToDisplay = 0;
251 //Just added first sensor in FrontView, unable FrontView plug-in mode
258 public void Remove(ISensor sensor)
260 Remove(sensor, true);
261 iNextSensorToDisplay = 0;
264 //No sensor to display in FrontView, just disable FrontView plug-in mode
270 private void Remove(ISensor sensor, bool deleteConfig)
275 new Identifier(sensor.Identifier, "FrontView").ToString());
277 SensorFrontView instance = null;
278 foreach (SensorFrontView icon in list)
279 if (icon.Sensor == sensor)
281 if (instance != null)
283 list.Remove(instance);
284 //UpdateMainIconVisibilty();
291 private void UpdateMainIconVisibilty()
296 mainIcon.Visible = list.Count == 0;
300 mainIcon.Visible = false;
307 iServer.SendMessage("init:");
312 iServer.SendMessage("uninit:");
315 public void SetText(string aUpperLine, string aLowerLine)
317 iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
322 iServer.SendMessage("quit:");
326 public bool IsMainIconEnabled
328 get { return mainIconEnabled; }
331 if (mainIconEnabled != value)
333 mainIconEnabled = value;
334 UpdateMainIconVisibilty();