Better formatting FrontView lines.
Now cycling through each FrontView sensor every 2 seconds.
Fixing character conversion when sending VFD text.
Using special FrontView characters for Celsius and Farenheit.
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))
57 //Process client = UserAccountControl.CreateProcessAsStandardUser(@"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe","");
59 Process client = new Process();
60 client.StartInfo.FileName = @"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe";
61 client.StartInfo.WorkingDirectory = @"D:\Dev\SoundGraphAccess";
65 //Start our SoundGraph server
66 iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
68 //iServer.SendMessage("init:");
71 private void HardwareRemoved(IHardware hardware)
73 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
74 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
75 foreach (ISensor sensor in hardware.Sensors)
76 SensorRemoved(sensor);
77 foreach (IHardware subHardware in hardware.SubHardware)
78 HardwareRemoved(subHardware);
81 private void HardwareAdded(IHardware hardware)
83 foreach (ISensor sensor in hardware.Sensors)
85 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
86 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
87 foreach (IHardware subHardware in hardware.SubHardware)
88 HardwareAdded(subHardware);
91 private void SensorAdded(ISensor sensor)
93 if (settings.GetValue(new Identifier(sensor.Identifier,
94 "FrontView").ToString(), false))
98 private void SensorRemoved(ISensor sensor)
100 if (Contains(sensor))
101 Remove(sensor, false);
104 public void Dispose()
106 foreach (SensorFrontView icon in list)
116 //Update all sensors from our front view
117 foreach (SensorFrontView sensor in list)
120 //SetText(sensor.iFirstLine, sensor.iSecondLine);
123 //Alternate between sensors
126 //Display current sensor on our FrontView display
127 SetText(list[iNextSensorToDisplay].iFirstLine, list[iNextSensorToDisplay].iSecondLine);
129 if (iTickCounter==2) //Move to the next sensor only every second tick
132 iNextSensorToDisplay++;
136 if (iNextSensorToDisplay == list.Count)
138 //Go back to first sensor
139 iNextSensorToDisplay = 0;
145 public bool Contains(ISensor sensor)
147 foreach (SensorFrontView icon in list)
148 if (icon.Sensor == sensor)
153 public void Add(ISensor sensor, bool balloonTip)
155 if (Contains(sensor))
162 list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
163 //UpdateMainIconVisibilty();
164 settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
165 iNextSensorToDisplay = 0;
170 public void Remove(ISensor sensor)
172 Remove(sensor, true);
173 iNextSensorToDisplay = 0;
176 private void Remove(ISensor sensor, bool deleteConfig)
181 new Identifier(sensor.Identifier, "FrontView").ToString());
183 SensorFrontView instance = null;
184 foreach (SensorFrontView icon in list)
185 if (icon.Sensor == sensor)
187 if (instance != null)
189 list.Remove(instance);
190 //UpdateMainIconVisibilty();
197 private void UpdateMainIconVisibilty()
202 mainIcon.Visible = list.Count == 0;
206 mainIcon.Visible = false;
213 iServer.SendMessage("init:");
218 iServer.SendMessage("uninit:");
221 public void SetText(string aUpperLine, string aLowerLine)
223 iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
228 iServer.SendMessage("quit:");
232 public bool IsMainIconEnabled
234 get { return mainIconEnabled; }
237 if (mainIconEnabled != value)
239 mainIconEnabled = value;
240 UpdateMainIconVisibilty();