Support for SharpDisplayManager.
Switching to .NET v4.0 to allow System.ServiceModel.
OxyPlot fix and recompile for .NET v4.0.
FrontView fix to start-up without SoundGraphAccess.exe.
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;
29 namespace OpenHardwareMonitor.GUI
31 public class SoundGraphDisplay : IDisposable
33 private IComputer computer;
34 private PersistentSettings settings;
35 private UnitManager unitManager;
36 private List<SensorFrontView> list = new List<SensorFrontView>();
37 private SoundGraph.Server iServer;
39 private int iNextSensorToDisplay=0;
40 private int iTickCounter=0;
43 public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
44 UnitManager unitManager)
46 this.computer = computer;
47 this.settings = settings;
48 this.unitManager = unitManager;
49 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
50 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
52 //Start our client if needed
53 Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
54 if (!(processes.Length > 0))
58 //Try to launch the sound graph process from the same folder as this executable
59 string exeName = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
60 exeName += @"\SoundGraphAccess.exe";
61 Process client = UserAccountControl.CreateProcessAsStandardUser(exeName, "");
65 Debug.WriteLine("SoundGraphAccess.exe start-up failed: " + e.ToString());
69 //Start our SoundGraph server
70 iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
74 private void HardwareRemoved(IHardware hardware)
76 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
77 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
78 foreach (ISensor sensor in hardware.Sensors)
79 SensorRemoved(sensor);
80 foreach (IHardware subHardware in hardware.SubHardware)
81 HardwareRemoved(subHardware);
84 private void HardwareAdded(IHardware hardware)
86 foreach (ISensor sensor in hardware.Sensors)
88 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
89 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
90 foreach (IHardware subHardware in hardware.SubHardware)
91 HardwareAdded(subHardware);
94 private void SensorAdded(ISensor sensor)
96 if (settings.GetValue(new Identifier(sensor.Identifier,
97 "FrontView").ToString(), false))
101 private void SensorRemoved(ISensor sensor)
103 if (Contains(sensor))
104 Remove(sensor, false);
107 public void Dispose()
109 foreach (SensorFrontView icon in list)
117 public void Redraw(bool aPacked, bool aDisplayTime)
119 const int KNumberOfTickBeforeSwitch = 4;
120 const int KMaxCharacterPerLine = 16;
121 string packedFirstLine=""; //We have 16 chars per line on our VFD
122 string packedSecondLine="";
125 string time = DateTime.Now.ToShortTimeString();
127 //Update all sensors from our front view
128 foreach (SensorFrontView sensor in list)
133 if (aDisplayTime && count == 1)
135 //First slot is take by time display
137 packedFirstLine = time + " ";
142 //Build strings for packed mode
143 string packedText = "";
144 packedText = sensor.iFirstLine.Substring(0, 3) + ":" + sensor.iSecondLine;
147 packedFirstLine = packedText + " "; //Minimum one space to separate sensors on the same line
151 //Add enough spaces to align to right hand side
152 while (packedFirstLine.Length + packedText.Length < KMaxCharacterPerLine)
154 packedFirstLine += " ";
156 packedFirstLine += packedText;
160 packedSecondLine = packedText + " "; //Minimum one space to separate sensors on the same line
164 //Add enough spaces to align to right hand side
165 while (packedSecondLine.Length + packedText.Length < KMaxCharacterPerLine)
167 packedSecondLine += " ";
169 packedSecondLine += packedText;
172 //SetText(sensor.iFirstLine, sensor.iSecondLine);
175 //Alternate between sensors
180 //string packedLine = "";
182 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
185 if (iNextSensorToDisplay==1)
187 iNextSensorToDisplay=0;
191 iNextSensorToDisplay=1;
195 //TODO: Do something like that to cycle lines if ever we want to
196 //SetText(time, (iNextSensorToDisplay == 1 && packedSecondLine.Length > 0 ? packedSecondLine : packedFirstLine));
198 //Display packed sensors on our FrontView display
199 SetText(packedFirstLine, packedSecondLine);
203 string secondLine = list[iNextSensorToDisplay].iSecondLine;
207 while (secondLine.Length + time.Length < KMaxCharacterPerLine)
213 //Display current sensor on our FrontView display
214 SetText(list[iNextSensorToDisplay].iFirstLine, secondLine);
216 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
219 iNextSensorToDisplay++;
224 if (iNextSensorToDisplay == list.Count)
226 //Go back to first sensor
227 iNextSensorToDisplay = 0;
233 public bool Contains(ISensor sensor)
235 foreach (SensorFrontView icon in list)
236 if (icon.Sensor == sensor)
241 public void Add(ISensor sensor, bool balloonTip)
243 if (Contains(sensor))
250 list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
251 //UpdateMainIconVisibilty();
252 settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
253 iNextSensorToDisplay = 0;
256 //Just added first sensor in FrontView, unable FrontView plug-in mode
263 public void Remove(ISensor sensor)
265 Remove(sensor, true);
266 iNextSensorToDisplay = 0;
269 //No sensor to display in FrontView, just disable FrontView plug-in mode
275 private void Remove(ISensor sensor, bool deleteConfig)
280 new Identifier(sensor.Identifier, "FrontView").ToString());
282 SensorFrontView instance = null;
283 foreach (SensorFrontView icon in list)
284 if (icon.Sensor == sensor)
286 if (instance != null)
288 list.Remove(instance);
289 //UpdateMainIconVisibilty();
296 private void UpdateMainIconVisibilty()
301 mainIcon.Visible = list.Count == 0;
305 mainIcon.Visible = false;
312 iServer.SendMessage("init:");
317 iServer.SendMessage("uninit:");
320 public void SetText(string aUpperLine, string aLowerLine)
322 iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
327 iServer.SendMessage("quit:");
331 public bool IsMainIconEnabled
333 get { return mainIconEnabled; }
336 if (mainIconEnabled != value)
338 mainIconEnabled = value;
339 UpdateMainIconVisibilty();