Example #1
0
        private string GetString()
        {
            if (!sensor.Value.HasValue)
            {
                return("-");
            }

            switch (sensor.SensorType)
            {
            case SensorType.Voltage:
                return(string.Format("{0:F1}", sensor.Value));

            case SensorType.Clock:
                return(string.Format("{0:F1}", 1e-3f * sensor.Value));

            case SensorType.Load:
                return(string.Format("{0:F0}", sensor.Value));

            case SensorType.Temperature:
                if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
                {
                    return(string.Format("{0:F0}",
                                         UnitManager.CelsiusToFahrenheit(sensor.Value)));
                }
                else
                {
                    return(string.Format("{0:F0}", sensor.Value));
                }

            case SensorType.Fan:
                return(string.Format("{0:F1}", 1e-3f * sensor.Value));

            case SensorType.Flow:
                return(string.Format("{0:F1}", 1e-3f * sensor.Value));

            case SensorType.Control:
                return(string.Format("{0:F0}", sensor.Value));

            case SensorType.Level:
                return(string.Format("{0:F0}", sensor.Value));

            case SensorType.Power:
                return(string.Format("{0:F0}", sensor.Value));

            case SensorType.Data:
                return(string.Format("{0:F0}", sensor.Value));

            case SensorType.Factor:
                return(string.Format("{0:F1}", sensor.Value));

            case SensorType.DataRate:
                return(string.Format(BytesFormatProvider.Instance, "{0:bf0}", sensor.Value));
            }
            return("-");
        }
        private string GetString()
        {
            if (!Sensor.Value.HasValue)
            {
                return("-");
            }

            switch (Sensor.SensorType)
            {
            case SensorType.Voltage:
                return(string.Format("{0:F1}", Sensor.Value));

            case SensorType.Clock:
                return(string.Format("{0:F1}", 1e-3f * Sensor.Value));

            case SensorType.Load:
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Temperature:
                if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
                {
                    return(string.Format("{0:F0}",
                                         UnitManager.CelsiusToFahrenheit(Sensor.Value)));
                }
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Fan:
                return(string.Format("{0:F1}", 1e-3f * Sensor.Value));

            case SensorType.Flow:
                return(string.Format("{0:F1}", 1e-3f * Sensor.Value));

            case SensorType.Control:
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Level:
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Power:
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Data:
                return(string.Format("{0:F0}", Sensor.Value));

            case SensorType.Factor:
                return(string.Format("{0:F1}", Sensor.Value));
            }
            return("-");
        }
Example #3
0
        public void SetSensors(List <ISensor> sensors,
                               IDictionary <ISensor, Color> colors)
        {
            model.Series.Clear();

            var types = new ListSet <SensorType>();

            foreach (var sensor in sensors)
            {
                var series = new LineSeries();
                if (sensor.SensorType == SensorType.Temperature)
                {
                    series.ItemsSource = sensor.Values.Select(value => new DataPoint
                    {
                        X = (now - value.Time).TotalSeconds,
                        Y = unitManager.TemperatureUnit == TemperatureUnit.Celsius
                            ? value.Value
                            : UnitManager.CelsiusToFahrenheit(value.Value).Value
                    });
                }
                else
                {
                    series.ItemsSource = sensor.Values.Select(value => new DataPoint
                    {
                        X = (now - value.Time).TotalSeconds,
                        Y = value.Value
                    });
                }
                series.Color           = colors[sensor].ToOxyColor();
                series.StrokeThickness = 1;
                series.YAxisKey        = axes[sensor.SensorType].Key;
                series.Title           = sensor.Hardware.Name + " " + sensor.Name;
                model.Series.Add(series);

                types.Add(sensor.SensorType);
            }

            foreach (var pair in axes.Reverse())
            {
                var axis = pair.Value;
                var type = pair.Key;
                axis.IsAxisVisible = types.Contains(type);
            }

            UpdateAxesPosition();
            InvalidatePlot();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            int      w = Size.Width;

            g.Clear(Color.Transparent);

            DrawBackground(g);

            int x;
            int y = topMargin;

            if (sensors.Count == 0)
            {
                x = leftBorder + 1;
                g.DrawString("Right-click on a sensor in the main window and select " +
                             "\"Show in Gadget\" to show the sensor here.",
                             smallFont, Brushes.White,
                             new Rectangle(x, y - 1, w - rightBorder - x, 0));
            }

            foreach (KeyValuePair <IHardware, IList <ISensor> > pair in sensors)
            {
                if (hardwareNames.Value)
                {
                    if (y > topMargin)
                    {
                        y += hardwareLineHeight - sensorLineHeight;
                    }
                    x = leftBorder + 1;
                    g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
                                new Rectangle(x, y + 1, iconSize, iconSize));
                    x += iconSize + 1;
                    g.DrawString(pair.Key.Name, largeFont, Brushes.White,
                                 new Rectangle(x, y - 1, w - rightBorder - x, 0),
                                 stringFormat);
                    y += hardwareLineHeight;
                }

                foreach (ISensor sensor in pair.Value)
                {
                    int remainingWidth;


                    if ((sensor.SensorType != SensorType.Load &&
                         sensor.SensorType != SensorType.Control &&
                         sensor.SensorType != SensorType.Level) || percentageDisplayType == PercentageDisplayType.Value || !sensor.Value.HasValue)
                    {
                        string formatted;

                        if (sensor.Value.HasValue)
                        {
                            string format = "";
                            switch (sensor.SensorType)
                            {
                            case SensorType.Voltage:
                                format = "{0:F3} V";
                                break;

                            case SensorType.Clock:
                                format = "{0:F0} MHz";
                                break;

                            case SensorType.Temperature:
                                format = "{0:F1} °C";
                                break;

                            case SensorType.Fan:
                                format = "{0:F0} RPM";
                                break;

                            case SensorType.Flow:
                                format = "{0:F0} L/h";
                                break;

                            case SensorType.Power:
                                format = "{0:F1} W";
                                break;

                            case SensorType.Data:
                                format = "{0:F1} GB";
                                break;

                            case SensorType.Factor:
                                format = "{0:F3}";
                                break;

                            case SensorType.Load:
                            case SensorType.Control:
                            case SensorType.Level:
                                format = "{0:F1} %";
                                break;

                            case SensorType.DataRate:
                                format = "{0:bf}/s";
                                break;
                            }

                            if (sensor.SensorType == SensorType.Temperature &&
                                unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
                            {
                                formatted = string.Format("{0:F1} °F",
                                                          UnitManager.CelsiusToFahrenheit(sensor.Value));
                            }
                            else if (sensor.SensorType == SensorType.DataRate)
                            {
                                formatted = string.Format(BytesFormatProvider.Instance, format, sensor.Value);
                            }
                            else
                            {
                                formatted = string.Format(format, sensor.Value);
                            }
                        }
                        else
                        {
                            formatted = "-";
                        }

                        g.DrawString(formatted, smallFont, darkWhite,
                                     new RectangleF(-1, y - 1, w - rightMargin + 3, 0),
                                     alignRightStringFormat);

                        remainingWidth = w - (int)Math.Floor(g.MeasureString(formatted,
                                                                             smallFont, w, StringFormat.GenericTypographic).Width) -
                                         rightMargin;
                    }
                    else
                    {
                        DrawProgress(g, w - progressWidth - rightMargin,
                                     y + 0.35f * sensorLineHeight, progressWidth,
                                     0.6f * sensorLineHeight, 0.01f * sensor.Value.Value);

                        remainingWidth = w - progressWidth - rightMargin;

                        if (percentageDisplayType == PercentageDisplayType.Both)
                        {
                            string formatted = string.Format("{0:F1} %", sensor.Value);
                            g.DrawString(formatted, smallFont, darkWhite,
                                         new RectangleF(-1, y - 1, remainingWidth, 0),
                                         alignRightStringFormat);

                            remainingWidth = remainingWidth - (int)Math.Floor(g.MeasureString(formatted,
                                                                                              smallFont, w, StringFormat.GenericTypographic).Width);
                        }
                    }

                    remainingWidth -= leftMargin + 2;
                    if (remainingWidth > 0)
                    {
                        g.DrawString(sensor.Name, smallFont, darkWhite,
                                     new RectangleF(leftMargin - 1, y - 1, remainingWidth, 0),
                                     trimStringFormat);
                    }

                    y += sensorLineHeight;
                }
            }
        }
        public void Update()
        {
            Icon icon = notifyIcon.Icon;

            switch (sensor.SensorType)
            {
            case SensorType.Load:
            case SensorType.Control:
            case SensorType.Level:
                notifyIcon.Icon = CreatePercentageIcon();
                break;

            default:
                notifyIcon.Icon = CreateTransparentIcon();
                break;
            }

            if (icon != null)
            {
                icon.Dispose();
            }

            string format = "";

            switch (sensor.SensorType)
            {
            case SensorType.Voltage: format = "\n{0}: {1:F2} V"; break;

            case SensorType.Clock: format = "\n{0}: {1:F0} MHz"; break;

            case SensorType.Load: format = "\n{0}: {1:F1} %"; break;

            case SensorType.Temperature: format = "\n{0}: {1:F1} °C"; break;

            case SensorType.Fan: format = "\n{0}: {1:F0} RPM"; break;

            case SensorType.Flow: format = "\n{0}: {1:F0} L/h"; break;

            case SensorType.Control: format = "\n{0}: {1:F1} %"; break;

            case SensorType.Level: format = "\n{0}: {1:F1} %"; break;

            case SensorType.Power: format = "\n{0}: {1:F0} W"; break;

            case SensorType.Data: format = "\n{0}: {1:F0} GB"; break;

            case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
            }
            string formattedValue = string.Format(format, sensor.Name, sensor.Value);

            if (sensor.SensorType == SensorType.Temperature &&
                unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
            {
                format         = "\n{0}: {1:F1} °F";
                formattedValue = string.Format(format, sensor.Name,
                                               UnitManager.CelsiusToFahrenheit(sensor.Value));
            }

            string hardwareName = sensor.Hardware.Name;

            hardwareName = hardwareName.Substring(0,
                                                  Math.Min(63 - formattedValue.Length, hardwareName.Length));
            string text = hardwareName + formattedValue;

            if (text.Length > 63)
            {
                text = null;
            }

            notifyIcon.Text    = text;
            notifyIcon.Visible = true;
        }