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;
21 using System.ServiceModel;
22 using SharpLib.Display;
25 namespace OpenHardwareMonitor.GUI
27 public class SharpDisplay : IDisposable
29 private IComputer computer;
30 private PersistentSettings settings;
31 private UnitManager unitManager;
32 private List<SensorSharpDisplay> iSensors = new List<SensorSharpDisplay>();
33 private Client iClient;
34 TextField iTextFieldTop;
35 TextField iTextFieldBottom;
36 TextField iTextFieldTopRight;
37 TextField iTextFieldBottomRight;
39 DataField[] iTextFields;
41 private int iNextSensorToDisplay = 0;
42 private int iTickCounter = 0;
45 public SharpDisplay(IComputer computer, PersistentSettings settings, UnitManager unitManager)
47 this.computer = computer;
48 this.settings = settings;
49 this.unitManager = unitManager;
50 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
51 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
54 //Instance context is then managed by our client class
55 iClient = new Client();
56 iClient.CloseOrderEvent += OnCloseOrder;
58 iTextFieldTop = new TextField("", ContentAlignment.MiddleLeft,0,0);
59 iTextFieldBottom = new TextField("", ContentAlignment.MiddleLeft, 0, 1);
60 iTextFieldTopRight = new TextField("", ContentAlignment.MiddleRight,1,0);
61 iTextFieldBottomRight = new TextField("", ContentAlignment.MiddleRight,1,1);
64 iClient.SetName("Open Hardware Monitor");
65 iClient.SetPriority(Priorities.SystemMonitor);
70 public void OnCloseOrder()
76 private void HardwareRemoved(IHardware hardware)
78 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
79 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
80 foreach (ISensor sensor in hardware.Sensors)
81 SensorRemoved(sensor);
82 foreach (IHardware subHardware in hardware.SubHardware)
83 HardwareRemoved(subHardware);
86 private void HardwareAdded(IHardware hardware)
88 foreach (ISensor sensor in hardware.Sensors)
90 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
91 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
92 foreach (IHardware subHardware in hardware.SubHardware)
93 HardwareAdded(subHardware);
96 private void SensorAdded(ISensor sensor)
98 if (settings.GetValue(new Identifier(sensor.Identifier,
99 "SharpDisplay").ToString(), false))
103 private void SensorRemoved(ISensor sensor)
105 if (Contains(sensor))
106 Remove(sensor, false);
109 public void Dispose()
111 foreach (SensorSharpDisplay icon in iSensors)
120 private void CreateFields()
124 //We just switched to packed mode
125 //Make sure our layout is proper
126 TableLayout layout = new TableLayout(2, 2);
127 iClient.SetLayout(layout);
128 iTextFields = new DataField[] { iTextFieldTop, iTextFieldBottom, iTextFieldTopRight, iTextFieldBottomRight };
129 iClient.CreateFields(iTextFields);
134 TableLayout layout = new TableLayout(1, 2);
135 iClient.SetLayout(layout);
136 iTextFields = new DataField[] { iTextFieldTop, iTextFieldBottom };
137 iClient.CreateFields(iTextFields);
141 public void Redraw(bool aPacked, bool aDisplayTime)
143 const int KNumberOfTickBeforeSwitch = 4;
144 const int KMaxCharacterPerLine = 16;
147 //string time = DateTime.Now.ToShortTimeString();
148 string time = DateTime.Now.ToLongTimeString();
150 if (iSensors.Count > 0)
152 if (iPacked != aPacked)
163 //Update all sensors from our front view
164 foreach (SensorSharpDisplay sensor in iSensors)
169 if (aDisplayTime && count == 1)
171 //First slot is taken by time display
173 iTextFieldTop.Text = time;
174 iClient.SetField(iTextFieldTop);
179 //Build strings for packed mode
180 string packedText = "";
181 packedText = sensor.iFirstLine.Substring(0, 3) + ":" + sensor.iSecondLine;
184 iTextFieldTop.Text = packedText;
185 iClient.SetField(iTextFieldTop);
189 iTextFieldBottom.Text = packedText;
190 iClient.SetField(iTextFieldBottom);
194 iTextFieldTopRight.Text = packedText;
195 iClient.SetField(iTextFieldTopRight);
199 iTextFieldBottomRight.Text = packedText;
200 iClient.SetField(iTextFieldBottomRight);
205 //Alternate between sensors
206 if (iSensors.Count > 0)
210 //Review that stuff cause as it is it's probably useless
211 //string packedLine = "";
213 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
216 if (iNextSensorToDisplay == 1)
218 iNextSensorToDisplay = 0;
222 iNextSensorToDisplay = 1;
228 string secondLine = iSensors[iNextSensorToDisplay].iSecondLine;
232 while (secondLine.Length + time.Length < KMaxCharacterPerLine)
238 //Display current sensor on our FrontView display
239 SetText(iSensors[iNextSensorToDisplay].iFirstLine, secondLine);
241 if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
244 iNextSensorToDisplay++;
249 if (iNextSensorToDisplay == iSensors.Count)
251 //Go back to first sensor
252 iNextSensorToDisplay = 0;
258 public bool Contains(ISensor sensor)
260 foreach (SensorSharpDisplay icon in iSensors)
261 if (icon.Sensor == sensor)
266 public void Add(ISensor sensor, bool balloonTip)
268 if (Contains(sensor))
275 iSensors.Add(new SensorSharpDisplay(this, sensor, balloonTip, settings, unitManager));
276 //UpdateMainIconVisibilty();
277 settings.SetValue(new Identifier(sensor.Identifier, "SharpDisplay").ToString(), true);
278 iNextSensorToDisplay = 0;
279 if (iSensors.Count == 1)
281 //Just added first sensor in FrontView, unable FrontView plug-in mode
288 public void Remove(ISensor sensor)
290 Remove(sensor, true);
291 iNextSensorToDisplay = 0;
292 if (iSensors.Count == 0)
294 //No sensor to display in FrontView, just disable FrontView plug-in mode
300 private void Remove(ISensor sensor, bool deleteConfig)
305 new Identifier(sensor.Identifier, "SharpDisplay").ToString());
307 SensorSharpDisplay instance = null;
308 foreach (SensorSharpDisplay icon in iSensors)
309 if (icon.Sensor == sensor)
311 if (instance != null)
313 iSensors.Remove(instance);
314 //UpdateMainIconVisibilty();
321 private void UpdateMainIconVisibilty()
326 mainIcon.Visible = list.Count == 0;
330 mainIcon.Visible = false;
337 //iServer.SendMessage("init:");
342 //iServer.SendMessage("uninit:");
345 public void SetText(string aUpperLine, string aLowerLine)
347 //iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
348 iTextFieldTop.Text = aUpperLine;
349 iTextFieldBottom.Text = aLowerLine;
350 iClient.SetFields(iTextFields);
355 //iServer.SendMessage("quit:");
359 public bool IsMainIconEnabled
361 get { return mainIconEnabled; }
364 if (mainIconEnabled != value)
366 mainIconEnabled = value;
367 UpdateMainIconVisibilty();