Sensors can now be displayed in FrontView.
1.1 --- a/GUI/MainForm.cs Mon Feb 02 13:28:41 2015 +0100
1.2 +++ b/GUI/MainForm.cs Sat Apr 13 00:43:25 2013 +0200
1.3 @@ -549,6 +549,8 @@
1.4
1.5 if (soundGraphDisplay != null)
1.6 {
1.7 + soundGraphDisplay.Redraw();
1.8 + /*
1.9 displayTick=!displayTick;
1.10 if (displayTick)
1.11 {
1.12 @@ -558,6 +560,7 @@
1.13 {
1.14 soundGraphDisplay.SetText(" -+-", "");
1.15 }
1.16 + */
1.17 }
1.18
1.19
1.20 @@ -690,7 +693,7 @@
1.21 }
1.22 {
1.23 MenuItem item = new MenuItem("Show in iMON FrontView");
1.24 - item.Checked = systemTray.Contains(node.Sensor);
1.25 + item.Checked = soundGraphDisplay.Contains(node.Sensor);
1.26 item.Click += delegate(object obj, EventArgs args)
1.27 {
1.28 if (item.Checked)
2.1 --- a/GUI/SensorFrontView.cs Mon Feb 02 13:28:41 2015 +0100
2.2 +++ b/GUI/SensorFrontView.cs Sat Apr 13 00:43:25 2013 +0200
2.3 @@ -26,15 +26,13 @@
2.4 private UnitManager unitManager;
2.5
2.6 private ISensor sensor;
2.7 - private Bitmap bitmap;
2.8 - private Graphics graphics;
2.9 private Color color;
2.10 private Color darkColor;
2.11 - private Brush brush;
2.12 - private Brush darkBrush;
2.13 - private Pen pen;
2.14 private Font font;
2.15 private Font smallFont;
2.16 + public string iFirstLine;
2.17 + public string iSecondLine;
2.18 +
2.19
2.20 public SensorFrontView(SoundGraphDisplay soundGraphDisplay, ISensor sensor,
2.21 bool balloonTip, PersistentSettings settings, UnitManager unitManager)
2.22 @@ -73,14 +71,6 @@
2.23 this.smallFont = new Font(family,
2.24 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
2.25
2.26 - this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
2.27 - this.graphics = Graphics.FromImage(this.bitmap);
2.28 -
2.29 - if (Environment.OSVersion.Version.Major > 5)
2.30 - {
2.31 - this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
2.32 - this.graphics.SmoothingMode = SmoothingMode.HighQuality;
2.33 - }
2.34 }
2.35
2.36 public ISensor Sensor
2.37 @@ -98,32 +88,16 @@
2.38 this.color.R / 3,
2.39 this.color.G / 3,
2.40 this.color.B / 3);
2.41 - Brush brush = this.brush;
2.42 - this.brush = new SolidBrush(this.color);
2.43 - if (brush != null)
2.44 - brush.Dispose();
2.45 - Brush darkBrush = this.darkBrush;
2.46 - this.darkBrush = new SolidBrush(this.darkColor);
2.47 - if (darkBrush != null)
2.48 - darkBrush.Dispose();
2.49 }
2.50 }
2.51
2.52 public void Dispose()
2.53 {
2.54 -
2.55 - if (brush != null)
2.56 - brush.Dispose();
2.57 - if (darkBrush != null)
2.58 - darkBrush.Dispose();
2.59 - pen.Dispose();
2.60 - graphics.Dispose();
2.61 - bitmap.Dispose();
2.62 font.Dispose();
2.63 smallFont.Dispose();
2.64 }
2.65
2.66 - private string GetString()
2.67 + public string GetString()
2.68 {
2.69 if (!sensor.Value.HasValue)
2.70 return "-";
2.71 @@ -160,73 +134,6 @@
2.72 return "-";
2.73 }
2.74
2.75 - private Icon CreateTransparentIcon()
2.76 - {
2.77 - string text = GetString();
2.78 - int count = 0;
2.79 - for (int i = 0; i < text.Length; i++)
2.80 - if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
2.81 - count++;
2.82 - bool small = count > 2;
2.83 -
2.84 - graphics.Clear(Color.Black);
2.85 - TextRenderer.DrawText(graphics, text, small ? smallFont : font,
2.86 - new Point(-2, small ? 1 : 0), Color.White, Color.Black);
2.87 -
2.88 - BitmapData data = bitmap.LockBits(
2.89 - new Rectangle(0, 0, bitmap.Width, bitmap.Height),
2.90 - ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
2.91 -
2.92 - IntPtr Scan0 = data.Scan0;
2.93 -
2.94 - int numBytes = bitmap.Width * bitmap.Height * 4;
2.95 - byte[] bytes = new byte[numBytes];
2.96 - Marshal.Copy(Scan0, bytes, 0, numBytes);
2.97 - bitmap.UnlockBits(data);
2.98 -
2.99 - byte red, green, blue;
2.100 - for (int i = 0; i < bytes.Length; i += 4)
2.101 - {
2.102 - blue = bytes[i];
2.103 - green = bytes[i + 1];
2.104 - red = bytes[i + 2];
2.105 -
2.106 - bytes[i] = color.B;
2.107 - bytes[i + 1] = color.G;
2.108 - bytes[i + 2] = color.R;
2.109 - bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
2.110 - }
2.111 -
2.112 - return IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
2.113 - PixelFormat.Format32bppArgb);
2.114 - }
2.115 -
2.116 - private Icon CreatePercentageIcon()
2.117 - {
2.118 - try
2.119 - {
2.120 - graphics.Clear(Color.Transparent);
2.121 - }
2.122 - catch (ArgumentException)
2.123 - {
2.124 - graphics.Clear(Color.Black);
2.125 - }
2.126 - graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height);
2.127 - float value = sensor.Value.GetValueOrDefault();
2.128 - float y = 0.16f * (100 - value);
2.129 - graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y);
2.130 - graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);
2.131 -
2.132 - BitmapData data = bitmap.LockBits(
2.133 - new Rectangle(0, 0, bitmap.Width, bitmap.Height),
2.134 - ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
2.135 - byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4];
2.136 - Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
2.137 - bitmap.UnlockBits(data);
2.138 -
2.139 - return IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
2.140 - PixelFormat.Format32bppArgb);
2.141 - }
2.142
2.143 public void Update()
2.144 {
2.145 @@ -248,35 +155,30 @@
2.146 string format = "";
2.147 switch (sensor.SensorType)
2.148 {
2.149 - case SensorType.Voltage: format = "\n{0}: {1:F2} V"; break;
2.150 - case SensorType.Clock: format = "\n{0}: {1:F0} MHz"; break;
2.151 - case SensorType.Load: format = "\n{0}: {1:F1} %"; break;
2.152 - case SensorType.Temperature: format = "\n{0}: {1:F1} °C"; break;
2.153 - case SensorType.Fan: format = "\n{0}: {1:F0} RPM"; break;
2.154 - case SensorType.Flow: format = "\n{0}: {1:F0} L/h"; break;
2.155 - case SensorType.Control: format = "\n{0}: {1:F1} %"; break;
2.156 - case SensorType.Level: format = "\n{0}: {1:F1} %"; break;
2.157 - case SensorType.Power: format = "\n{0}: {1:F0} W"; break;
2.158 - case SensorType.Data: format = "\n{0}: {1:F0} GB"; break;
2.159 - case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
2.160 + case SensorType.Voltage: format = "{0}: {1:F2} V"; break;
2.161 + case SensorType.Clock: format = "{0}: {1:F0} MHz"; break;
2.162 + case SensorType.Load: format = "{0}: {1:F1} %"; break;
2.163 + case SensorType.Temperature: format = "{0}: {1:F1} °C"; break;
2.164 + case SensorType.Fan: format = "{0}: {1:F0} RPM"; break;
2.165 + case SensorType.Flow: format = "{0}: {1:F0} L/h"; break;
2.166 + case SensorType.Control: format = "{0}: {1:F1} %"; break;
2.167 + case SensorType.Level: format = "{0}: {1:F1} %"; break;
2.168 + case SensorType.Power: format = "{0}: {1:F0} W"; break;
2.169 + case SensorType.Data: format = "{0}: {1:F0} GB"; break;
2.170 + case SensorType.Factor: format = "{0}: {1:F3} GB"; break;
2.171 }
2.172 string formattedValue = string.Format(format, sensor.Name, sensor.Value);
2.173
2.174 if (sensor.SensorType == SensorType.Temperature &&
2.175 unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
2.176 {
2.177 - format = "\n{0}: {1:F1} °F";
2.178 + format = "{0}: {1:F1} °F";
2.179 formattedValue = string.Format(format, sensor.Name,
2.180 UnitManager.CelsiusToFahrenheit(sensor.Value));
2.181 }
2.182
2.183 - string hardwareName = sensor.Hardware.Name;
2.184 - hardwareName = hardwareName.Substring(0,
2.185 - Math.Min(63 - formattedValue.Length, hardwareName.Length));
2.186 - string text = hardwareName + formattedValue;
2.187 - if (text.Length > 63)
2.188 - text = null;
2.189 -
2.190 + iFirstLine = sensor.Hardware.Name;
2.191 + iSecondLine = formattedValue;
2.192
2.193 }
2.194 }
3.1 --- a/GUI/SoundGraphDisplay.cs Mon Feb 02 13:28:41 2015 +0100
3.2 +++ b/GUI/SoundGraphDisplay.cs Sat Apr 13 00:43:25 2013 +0200
3.3 @@ -36,6 +36,8 @@
3.4 private List<SensorFrontView> list = new List<SensorFrontView>();
3.5 private SoundGraph.Server iServer;
3.6
3.7 + private int nextSensorToDisplay=0;
3.8 +
3.9
3.10 public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
3.11 UnitManager unitManager)
3.12 @@ -88,7 +90,7 @@
3.13 private void SensorAdded(ISensor sensor)
3.14 {
3.15 if (settings.GetValue(new Identifier(sensor.Identifier,
3.16 - "tray").ToString(), false))
3.17 + "FrontView").ToString(), false))
3.18 Add(sensor, false);
3.19 }
3.20
3.21 @@ -110,8 +112,29 @@
3.22
3.23 public void Redraw()
3.24 {
3.25 - foreach (SensorFrontView icon in list)
3.26 - icon.Update();
3.27 + //TODO: construct our two lines of texts, scroll or alternate sensors
3.28 + foreach (SensorFrontView sensor in list)
3.29 + {
3.30 + sensor.Update();
3.31 + //SetText(sensor.iFirstLine, sensor.iSecondLine);
3.32 + }
3.33 +
3.34 + //Alternate between sensors
3.35 + if (list.Count > 0)
3.36 + {
3.37 + SetText(list[nextSensorToDisplay].iFirstLine, list[nextSensorToDisplay].iSecondLine);
3.38 + nextSensorToDisplay++;
3.39 + }
3.40 +
3.41 + if (nextSensorToDisplay == list.Count)
3.42 + {
3.43 + //Go back to first sensor
3.44 + nextSensorToDisplay = 0;
3.45 + }
3.46 +
3.47 +
3.48 + //
3.49 +
3.50 }
3.51
3.52 public bool Contains(ISensor sensor)
3.53 @@ -131,15 +154,18 @@
3.54 else
3.55 {
3.56 //SL:
3.57 - //list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
3.58 + list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
3.59 //UpdateMainIconVisibilty();
3.60 - //settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
3.61 + settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
3.62 + nextSensorToDisplay = 0;
3.63 }
3.64 +
3.65 }
3.66
3.67 public void Remove(ISensor sensor)
3.68 {
3.69 Remove(sensor, true);
3.70 + nextSensorToDisplay = 0;
3.71 }
3.72
3.73 private void Remove(ISensor sensor, bool deleteConfig)
3.74 @@ -147,9 +173,7 @@
3.75 if (deleteConfig)
3.76 {
3.77 settings.Remove(
3.78 - new Identifier(sensor.Identifier, "tray").ToString());
3.79 - settings.Remove(
3.80 - new Identifier(sensor.Identifier, "traycolor").ToString());
3.81 + new Identifier(sensor.Identifier, "FrontView").ToString());
3.82 }
3.83 SensorFrontView instance = null;
3.84 foreach (SensorFrontView icon in list)
3.85 @@ -158,7 +182,7 @@
3.86 if (instance != null)
3.87 {
3.88 list.Remove(instance);
3.89 - UpdateMainIconVisibilty();
3.90 + //UpdateMainIconVisibilty();
3.91 instance.Dispose();
3.92 }
3.93 }
3.94 @@ -191,7 +215,7 @@
3.95
3.96 public void SetText(string aUpperLine, string aLowerLine)
3.97 {
3.98 - iServer.SendMessage("set-vfd-text:" + aUpperLine);
3.99 + iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine);
3.100 }
3.101
3.102 public void Quit()