Better formatting FrontView lines. MiniDisplay
authorStephaneLenclud
Sun, 14 Apr 2013 22:38:41 +0200
branchMiniDisplay
changeset 43906369ace500d
parent 438 f590956d3234
child 440 f43bab5fc81e
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.
GUI/SensorFrontView.cs
GUI/SoundGraphDisplay.cs
GUI/SoundGraphServer.cs
     1.1 --- a/GUI/SensorFrontView.cs	Sat Apr 13 00:43:25 2013 +0200
     1.2 +++ b/GUI/SensorFrontView.cs	Sun Apr 14 22:38:41 2013 +0200
     1.3 @@ -155,31 +155,36 @@
     1.4              string format = "";
     1.5              switch (sensor.SensorType)
     1.6              {
     1.7 -                case SensorType.Voltage: format = "{0}: {1:F2} V"; break;
     1.8 -                case SensorType.Clock: format = "{0}: {1:F0} MHz"; break;
     1.9 -                case SensorType.Load: format = "{0}: {1:F1} %"; break;
    1.10 -                case SensorType.Temperature: format = "{0}: {1:F1} °C"; break;
    1.11 -                case SensorType.Fan: format = "{0}: {1:F0} RPM"; break;
    1.12 -                case SensorType.Flow: format = "{0}: {1:F0} L/h"; break;
    1.13 -                case SensorType.Control: format = "{0}: {1:F1} %"; break;
    1.14 -                case SensorType.Level: format = "{0}: {1:F1} %"; break;
    1.15 -                case SensorType.Power: format = "{0}: {1:F0} W"; break;
    1.16 -                case SensorType.Data: format = "{0}: {1:F0} GB"; break;
    1.17 -                case SensorType.Factor: format = "{0}: {1:F3} GB"; break;
    1.18 +                case SensorType.Voltage: format = "{0:F2}V"; break;
    1.19 +                case SensorType.Clock: format = "{0:F0}MHz"; break;
    1.20 +                case SensorType.Load: format = "{0:F1}%"; break;
    1.21 +                //iMON VFD escape sequence for Celsius
    1.22 +                case SensorType.Temperature: format = "{0:F0}\x001A"; break;
    1.23 +                case SensorType.Fan: format = "{0:F0}RPM"; break;
    1.24 +                case SensorType.Flow: format = "{0:F0}L/h"; break;
    1.25 +                case SensorType.Control: format = "{0:F1}%"; break;
    1.26 +                case SensorType.Level: format = "{0:F1}%"; break;
    1.27 +                case SensorType.Power: format = "{0:F0}W"; break;
    1.28 +                case SensorType.Data: format = "{0:F0}GB"; break;
    1.29 +                case SensorType.Factor: format = "{0:F3}GB"; break;
    1.30              }
    1.31 -            string formattedValue = string.Format(format, sensor.Name, sensor.Value);
    1.32 +            string formattedValue = string.Format(format, sensor.Value);
    1.33  
    1.34              if (sensor.SensorType == SensorType.Temperature &&
    1.35                unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
    1.36              {
    1.37 -                format = "{0}: {1:F1} °F";
    1.38 -                formattedValue = string.Format(format, sensor.Name,
    1.39 -                  UnitManager.CelsiusToFahrenheit(sensor.Value));
    1.40 +                //iMON VFD escape sequence for Fahrenheit
    1.41 +                format = "{0:F0}\x001B";
    1.42 +                formattedValue = string.Format(format, UnitManager.CelsiusToFahrenheit(sensor.Value));
    1.43              }
    1.44  
    1.45 -            iFirstLine = sensor.Hardware.Name;
    1.46 +            //iFirstLine = sensor.Hardware.Name;
    1.47 +            //iSecondLine = sensor.Name+ ":" + formattedValue;
    1.48 +
    1.49 +            iFirstLine = sensor.Name;
    1.50              iSecondLine = formattedValue;
    1.51  
    1.52 +
    1.53          }
    1.54      }
    1.55  }
     2.1 --- a/GUI/SoundGraphDisplay.cs	Sat Apr 13 00:43:25 2013 +0200
     2.2 +++ b/GUI/SoundGraphDisplay.cs	Sun Apr 14 22:38:41 2013 +0200
     2.3 @@ -36,7 +36,8 @@
     2.4          private List<SensorFrontView> list = new List<SensorFrontView>();
     2.5          private SoundGraph.Server iServer;
     2.6  
     2.7 -        private int nextSensorToDisplay=0;
     2.8 +        private int iNextSensorToDisplay=0;
     2.9 +        private int iTickCounter=0;
    2.10  
    2.11  
    2.12          public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
    2.13 @@ -112,7 +113,7 @@
    2.14  
    2.15          public void Redraw()
    2.16          {
    2.17 -            //TODO: construct our two lines of texts, scroll or alternate sensors
    2.18 +            //Update all sensors from our front view
    2.19              foreach (SensorFrontView sensor in list)
    2.20              {
    2.21                  sensor.Update();
    2.22 @@ -122,18 +123,22 @@
    2.23              //Alternate between sensors 
    2.24              if (list.Count > 0)
    2.25              {
    2.26 -                SetText(list[nextSensorToDisplay].iFirstLine, list[nextSensorToDisplay].iSecondLine);
    2.27 -                nextSensorToDisplay++;
    2.28 +                //Display current sensor on our FrontView display
    2.29 +                SetText(list[iNextSensorToDisplay].iFirstLine, list[iNextSensorToDisplay].iSecondLine);
    2.30 +                iTickCounter++;
    2.31 +                if (iTickCounter==2) //Move to the next sensor only every second tick
    2.32 +                {
    2.33 +                    iTickCounter = 0;
    2.34 +                    iNextSensorToDisplay++;
    2.35 +                }
    2.36              }
    2.37  
    2.38 -            if (nextSensorToDisplay == list.Count)
    2.39 +            if (iNextSensorToDisplay == list.Count)
    2.40              {
    2.41                  //Go back to first sensor
    2.42 -                nextSensorToDisplay = 0;
    2.43 +                iNextSensorToDisplay = 0;
    2.44              }
    2.45  
    2.46 -
    2.47 -            //
    2.48              
    2.49          }
    2.50  
    2.51 @@ -157,7 +162,7 @@
    2.52                  list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
    2.53                  //UpdateMainIconVisibilty();
    2.54                  settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
    2.55 -                nextSensorToDisplay = 0;
    2.56 +                iNextSensorToDisplay = 0;
    2.57              }
    2.58  
    2.59          }
    2.60 @@ -165,7 +170,7 @@
    2.61          public void Remove(ISensor sensor)
    2.62          {
    2.63              Remove(sensor, true);
    2.64 -            nextSensorToDisplay = 0;
    2.65 +            iNextSensorToDisplay = 0;
    2.66          }
    2.67  
    2.68          private void Remove(ISensor sensor, bool deleteConfig)
     3.1 --- a/GUI/SoundGraphServer.cs	Sat Apr 13 00:43:25 2013 +0200
     3.2 +++ b/GUI/SoundGraphServer.cs	Sun Apr 14 22:38:41 2013 +0200
     3.3 @@ -365,15 +365,23 @@
     3.4           */
     3.5          public void SendMessage(string message)
     3.6          {
     3.7 +            byte[] m8 = new byte[message.Length];
     3.8 +            int i = 0;
     3.9 +            foreach (char c in message)
    3.10 +            {
    3.11 +                m8[i]=System.Convert.ToByte(c);
    3.12 +                i++;
    3.13 +            }
    3.14  
    3.15 -                ASCIIEncoding encoder = new ASCIIEncoding();
    3.16 -                byte[] messageBuffer = encoder.GetBytes(message);
    3.17 +            //ASCIIEncoding encoder = new ASCIIEncoding();
    3.18 +            //byte[] messageBuffer = encoder.GetBytes(message);
    3.19  
    3.20 -                if (iStreamOutbound != null && iStreamOutbound.CanWrite)
    3.21 -                {
    3.22 -                    iStreamOutbound.Write(messageBuffer, 0, messageBuffer.Length);
    3.23 -                    iStreamOutbound.Flush();
    3.24 -                }
    3.25 +            if (iStreamOutbound != null && iStreamOutbound.CanWrite)
    3.26 +            {
    3.27 +                //iStreamOutbound.Write(messageBuffer, 0, messageBuffer.Length);
    3.28 +                iStreamOutbound.Write(m8, 0, message.Length);
    3.29 +                iStreamOutbound.Flush();
    3.30 +            }
    3.31  
    3.32  
    3.33          }