Front View plug-in does not init if no sensor added. MiniDisplay
authorStephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 4449b09e2ee0968
parent 443 8c139748f179
child 445 fe4c711fd7f8
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
GUI/MainForm.cs
GUI/SensorFrontView.cs
GUI/SoundGraphDisplay.cs
GUI/SoundGraphServer.cs
     1.1 --- a/GUI/MainForm.cs	Thu Apr 18 19:51:05 2013 +0200
     1.2 +++ b/GUI/MainForm.cs	Thu Apr 18 23:25:10 2013 +0200
     1.3 @@ -324,11 +324,6 @@
     1.4  
     1.5        InitializePlotForm();
     1.6  
     1.7 -
     1.8 -      soundGraphDisplay.Init();
     1.9 -
    1.10 -
    1.11 -
    1.12        startupMenuItem.Visible = startupManager.IsAvailable;
    1.13        
    1.14        if (startMinMenuItem.Checked) {
     2.1 --- a/GUI/SensorFrontView.cs	Thu Apr 18 19:51:05 2013 +0200
     2.2 +++ b/GUI/SensorFrontView.cs	Thu Apr 18 23:25:10 2013 +0200
     2.3 @@ -157,13 +157,13 @@
     2.4              {
     2.5                  case SensorType.Voltage: format = "{0:F2}V"; break;
     2.6                  case SensorType.Clock: format = "{0:F0}MHz"; break;
     2.7 -                case SensorType.Load: format = "{0:F1}%"; break;
     2.8 +                case SensorType.Load: format = "{0:F0}%"; break;
     2.9                  //iMON VFD escape sequence for Celsius
    2.10                  case SensorType.Temperature: format = "{0:F0}\x001A"; break;
    2.11 -                case SensorType.Fan: format = "{0:F0}RPM"; break;
    2.12 +                case SensorType.Fan: format = "{0:F0}*"; break; //RPM
    2.13                  case SensorType.Flow: format = "{0:F0}L/h"; break;
    2.14 -                case SensorType.Control: format = "{0:F1}%"; break;
    2.15 -                case SensorType.Level: format = "{0:F1}%"; break;
    2.16 +                case SensorType.Control: format = "{0:F0}%"; break;
    2.17 +                case SensorType.Level: format = "{0:F0}%"; break;
    2.18                  case SensorType.Power: format = "{0:F0}W"; break;
    2.19                  case SensorType.Data: format = "{0:F0}GB"; break;
    2.20                  case SensorType.Factor: format = "{0:F3}GB"; break;
     3.1 --- a/GUI/SoundGraphDisplay.cs	Thu Apr 18 19:51:05 2013 +0200
     3.2 +++ b/GUI/SoundGraphDisplay.cs	Thu Apr 18 23:25:10 2013 +0200
     3.3 @@ -53,19 +53,15 @@
     3.4              Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
     3.5              if (!(processes.Length > 0))
     3.6              {
     3.7 -
     3.8 -                //Process client = UserAccountControl.CreateProcessAsStandardUser(@"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe","");
     3.9 -                    /*
    3.10 -                Process client = new Process();
    3.11 -                client.StartInfo.FileName = @"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe";
    3.12 -                client.StartInfo.WorkingDirectory = @"D:\Dev\SoundGraphAccess";
    3.13 -                client.Start();*/
    3.14 +                //Try to launch the sound graph process from the same folder as this executable
    3.15 +                string exeName=System.IO.Path.GetDirectoryName(Application.ExecutablePath);
    3.16 +                exeName += @"\SoundGraphAccess.exe";
    3.17 +                Process client = UserAccountControl.CreateProcessAsStandardUser(exeName,"");
    3.18              }
    3.19  
    3.20              //Start our SoundGraph server
    3.21              iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
    3.22              iServer.Start();
    3.23 -            //iServer.SendMessage("init:");
    3.24          }
    3.25  
    3.26          private void HardwareRemoved(IHardware hardware)
    3.27 @@ -127,17 +123,25 @@
    3.28                  count++;
    3.29                  sensor.Update();
    3.30  
    3.31 +                if (aDisplayTime && count == 1)
    3.32 +                {
    3.33 +                    //First slot is take by time display
    3.34 +                    count++;
    3.35 +                    packedFirstLine = time + " ";
    3.36 +                }
    3.37 +
    3.38                  if (aPacked)
    3.39                  {
    3.40 +                    //Build strings for packed mode
    3.41                      string packedText = "";
    3.42                      packedText = sensor.iFirstLine.Substring(0, 3) + ":" + sensor.iSecondLine;
    3.43                      if (count == 1)
    3.44                      {
    3.45 -                        packedFirstLine = packedText;
    3.46 +                        packedFirstLine = packedText + " "; //Minimum one space to separate sensors on the same line
    3.47                      }
    3.48                      else if (count == 2)
    3.49                      {
    3.50 -                        //Add enough spaces
    3.51 +                        //Add enough spaces to align to right hand side
    3.52                          while (packedFirstLine.Length + packedText.Length < KMaxCharacterPerLine)
    3.53                          {
    3.54                              packedFirstLine += " ";
    3.55 @@ -146,19 +150,17 @@
    3.56                      }
    3.57                      else if (count == 3)
    3.58                      {
    3.59 -                        packedSecondLine = packedText;
    3.60 +                        packedSecondLine = packedText + " "; //Minimum one space to separate sensors on the same line
    3.61                      }
    3.62                      else if (count == 4)
    3.63                      {
    3.64 -                        //Add enough spaces
    3.65 +                        //Add enough spaces to align to right hand side
    3.66                          while (packedSecondLine.Length + packedText.Length < KMaxCharacterPerLine)
    3.67                          {
    3.68                              packedSecondLine += " ";
    3.69                          }
    3.70                          packedSecondLine += packedText;
    3.71                      }
    3.72 -
    3.73 -
    3.74                  }
    3.75                  //SetText(sensor.iFirstLine, sensor.iSecondLine);
    3.76              }
    3.77 @@ -183,17 +185,11 @@
    3.78                          }
    3.79                      }
    3.80  
    3.81 -                    if (aDisplayTime)
    3.82 -                    {
    3.83 -                        SetText(time, (iNextSensorToDisplay == 1 && packedSecondLine.Length > 0 ? packedSecondLine : packedFirstLine));
    3.84 -                    }
    3.85 -                    else
    3.86 -                    {
    3.87 -                        //Display packed sensors on our FrontView display
    3.88 -                        SetText(packedFirstLine, packedSecondLine);
    3.89 -                    }
    3.90 +                    //TODO: Do something like that to cycle lines if ever we want to
    3.91 +                    //SetText(time, (iNextSensorToDisplay == 1 && packedSecondLine.Length > 0 ? packedSecondLine : packedFirstLine));
    3.92  
    3.93 -
    3.94 +                    //Display packed sensors on our FrontView display
    3.95 +                    SetText(packedFirstLine, packedSecondLine);
    3.96                  }
    3.97                  else
    3.98                  {
    3.99 @@ -248,6 +244,11 @@
   3.100                  //UpdateMainIconVisibilty();
   3.101                  settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true);
   3.102                  iNextSensorToDisplay = 0;
   3.103 +                if (list.Count == 1)
   3.104 +                {
   3.105 +                    //Just added first sensor in FrontView, unable FrontView plug-in mode
   3.106 +                    Init();
   3.107 +                }
   3.108              }
   3.109  
   3.110          }
   3.111 @@ -256,6 +257,12 @@
   3.112          {
   3.113              Remove(sensor, true);
   3.114              iNextSensorToDisplay = 0;
   3.115 +            if (list.Count == 0)
   3.116 +            {
   3.117 +                //No sensor to display in FrontView, just disable FrontView plug-in mode
   3.118 +                Uninit();
   3.119 +            }
   3.120 +
   3.121          }
   3.122  
   3.123          private void Remove(ISensor sensor, bool deleteConfig)
     4.1 --- a/GUI/SoundGraphServer.cs	Thu Apr 18 19:51:05 2013 +0200
     4.2 +++ b/GUI/SoundGraphServer.cs	Thu Apr 18 23:25:10 2013 +0200
     4.3 @@ -343,9 +343,9 @@
     4.4                  {
     4.5                      byte[] Rc = new byte[ReadLength];
     4.6                      Buffer.BlockCopy(buffer, 0, Rc, 0, ReadLength);
     4.7 -
     4.8 -                    Trace.WriteLine(encoder.GetString(Rc, 0, ReadLength));
     4.9 -                    Trace.WriteLine("Received " + ReadLength + " Bytes: " + encoder.GetString(Rc, 0, ReadLength));
    4.10 +                    string msg = encoder.GetString(Rc, 0, ReadLength);
    4.11 +                    Trace.WriteLine(msg);
    4.12 +                    Trace.WriteLine("Received " + ReadLength + " Bytes: " + msg);
    4.13                      buffer.Initialize();
    4.14                  }
    4.15