Sensors can now be displayed in FrontView.
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 nextSensorToDisplay=0;
42 public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
43 UnitManager unitManager)
45 this.computer = computer;
46 this.settings = settings;
47 this.unitManager = unitManager;
48 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
49 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
51 //Start our client if needed
52 Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
53 if (!(processes.Length > 0))
56 //Process client = UserAccountControl.CreateProcessAsStandardUser(@"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe","");
58 Process client = new Process();
59 client.StartInfo.FileName = @"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe";
60 client.StartInfo.WorkingDirectory = @"D:\Dev\SoundGraphAccess";
64 //Start our SoundGraph server
65 iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
67 //iServer.SendMessage("init:");
70 private void HardwareRemoved(IHardware hardware)
72 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
73 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
74 foreach (ISensor sensor in hardware.Sensors)
75 SensorRemoved(sensor);
76 foreach (IHardware subHardware in hardware.SubHardware)
77 HardwareRemoved(subHardware);
80 private void HardwareAdded(IHardware hardware)
82 foreach (ISensor sensor in hardware.Sensors)
84 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
85 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
86 foreach (IHardware subHardware in hardware.SubHardware)
87 HardwareAdded(subHardware);
90 private void SensorAdded(ISensor sensor)
92 if (settings.GetValue(new Identifier(sensor.Identifier,
93 "FrontView").ToString(), false))
97 private void SensorRemoved(ISensor sensor)
100 Remove(sensor, false);
103 public void Dispose()
105 foreach (SensorFrontView icon in list)
115 //TODO: construct our two lines of texts, scroll or alternate sensors
116 foreach (SensorFrontView sensor in list)
119 //SetText(sensor.iFirstLine, sensor.iSecondLine);
122 //Alternate between sensors
125 SetText(list[nextSensorToDisplay].iFirstLine, list[nextSensorToDisplay].iSecondLine);
126 nextSensorToDisplay++;
129 if (nextSensorToDisplay == list.Count)
131 //Go back to first sensor
132 nextSensorToDisplay = 0;
140 public bool Contains(ISensor sensor)
142 foreach (SensorFrontView icon in list)
143 if (icon.Sensor == sensor)
148 public void Add(ISensor sensor, bool balloonTip)
150 if (Contains(sensor))
157 list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
158 //UpdateMainIconVisibilty();
159 settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
160 nextSensorToDisplay = 0;
165 public void Remove(ISensor sensor)
167 Remove(sensor, true);
168 nextSensorToDisplay = 0;
171 private void Remove(ISensor sensor, bool deleteConfig)
176 new Identifier(sensor.Identifier, "FrontView").ToString());
178 SensorFrontView instance = null;
179 foreach (SensorFrontView icon in list)
180 if (icon.Sensor == sensor)
182 if (instance != null)
184 list.Remove(instance);
185 //UpdateMainIconVisibilty();
192 private void UpdateMainIconVisibilty()
197 mainIcon.Visible = list.Count == 0;
201 mainIcon.Visible = false;
208 iServer.SendMessage("init:");
213 iServer.SendMessage("uninit:");
216 public void SetText(string aUpperLine, string aLowerLine)
218 iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
223 iServer.SendMessage("quit:");
227 public bool IsMainIconEnabled
229 get { return mainIconEnabled; }
232 if (mainIconEnabled != value)
234 mainIconEnabled = value;
235 UpdateMainIconVisibilty();