Ejemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Rectangle newBounds = new Rectangle {
                X      = settings.GetValue("mainForm.Location.X", Location.X),
                Y      = settings.GetValue("mainForm.Location.Y", Location.Y),
                Width  = settings.GetValue("mainForm.Width", 470),
                Height = settings.GetValue("mainForm.Height", 640)
            };

            Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
                                                      int.MinValue, int.MinValue);

            foreach (Screen screen in Screen.AllScreens)
            {
                fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
            }

            Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);

            if (intersection.Width < 20 || intersection.Height < 20 ||
                !settings.Contains("mainForm.Location.X")
                )
            {
                newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
                              (newBounds.Width / 2);

                newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
                              (newBounds.Height / 2);
            }

            this.Bounds = newBounds;
        }
    public SensorNode(ISensor sensor, PersistentSettings settings, 
      UnitManager unitManager) : base() {      
      this.sensor = sensor;
      this.settings = settings;
      this.unitManager = unitManager;
      switch (sensor.SensorType) {
        case SensorType.Voltage: format = "{0:F3} V"; break;
        case SensorType.Clock: format = "{0:F0} MHz"; break;
        case SensorType.Load: format = "{0:F1} %"; 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.Control: format = "{0:F1} %"; break;
        case SensorType.Level: format = "{0:F1} %"; break;
        case SensorType.Power: format = "{0:F1} W"; break;
        case SensorType.Data: format = "{0:F1} GB"; break;
        case SensorType.SmallData: format = "{0:F1} MB"; break;
        case SensorType.Factor: format = "{0:F3}"; break;
      }

      bool hidden = settings.GetValue(new Identifier(sensor.Identifier, 
        "hidden").ToString(), sensor.IsDefaultHidden);
      base.IsVisible = !hidden;

      this.Plot = settings.GetValue(new Identifier(sensor.Identifier, 
        "plot").ToString(), false);

      string id = new Identifier(sensor.Identifier, "penColor").ToString();
      if (settings.Contains(id))
        this.PenColor = settings.GetValue(id, Color.Black);
    }
Ejemplo n.º 3
0
        public SensorNode(ISensor sensor, PersistentSettings settings, 
            UnitManager unitManager)
            : base()
        {
            this.sensor = sensor;
              this.settings = settings;
              this.unitManager = unitManager;
              switch (sensor.SensorType) {
            case SensorType.Voltage: format = "{0:F3} V"; break;
            case SensorType.Clock: format = "{0:F0} MHz"; break;
            case SensorType.Load: format = "{0:F1} %"; 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.Control: format = "{0:F1} %"; break;
            case SensorType.Level: format = "{0:F1} %"; break;
            case SensorType.Power: format = "{0:F1} W"; break;
            case SensorType.Data: format = "{0:F1} GB"; break;
            case SensorType.SmallData: format = "{0:F1} MB"; break;
            case SensorType.Factor: format = "{0:F3}"; break;
              }

              bool hidden = settings.GetValue(new Identifier(sensor.Identifier,
            "hidden").ToString(), sensor.IsDefaultHidden);
              base.IsVisible = !hidden;

              this.Plot = settings.GetValue(new Identifier(sensor.Identifier,
            "plot").ToString(), false);

              string id = new Identifier(sensor.Identifier, "penColor").ToString();
              if (settings.Contains(id))
            this.PenColor = settings.GetValue(id, Color.Black);
        }
Ejemplo n.º 4
0
        public SensorNode(ISensor sensor, PersistentSettings settings, UnitManager unitManager)
        {
            Sensor       = sensor;
            _settings    = settings;
            _unitManager = unitManager;

            switch (sensor.SensorType)
            {
            case SensorType.Voltage: Format = "{0:F3} V"; break;

            case SensorType.Current: Format = "{0:F3} A"; break;

            case SensorType.Clock: Format = "{0:F1} MHz"; break;

            case SensorType.Load: Format = "{0:F1} %"; break;

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

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

            case SensorType.Flow: Format = "{0:F1} L/h"; break;

            case SensorType.Control: Format = "{0:F1} %"; break;

            case SensorType.Level: Format = "{0:F1} %"; break;

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

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

            case SensorType.SmallData: Format = "{0:F1} MB"; break;

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

            case SensorType.Frequency: Format = "{0:F1} Hz"; break;

            case SensorType.Throughput: Format = "{0:F1} B/s"; break;
            }

            bool hidden = settings.GetValue(new Identifier(sensor.Identifier, "hidden").ToString(), sensor.IsDefaultHidden);

            base.IsVisible = !hidden;
            Plot           = settings.GetValue(new Identifier(sensor.Identifier, "plot").ToString(), false);
            string id = new Identifier(sensor.Identifier, "penColor").ToString();

            if (settings.Contains(id))
            {
                PenColor = settings.GetValue(id, Color.Black);
            }
        }
Ejemplo n.º 5
0
        public static void LoadEvent(int id, PersistentSettings settings)
        {
            Event e = new Event(new Identifier("event", id + ""));

            e.Name = settings.GetValue(new Identifier(e.Identifier, "name").ToString(), float.MaxValue.ToString());

            for (int i = 0; i < MAX_TRIGGERS; i++)
            {
                if (settings.Contains(new Identifier(e.Identifier, "trigger", i + "", "type").ToString()))
                {
                    EventTrigger t = EventTrigger.LoadTrigger(e, i, settings);
                }
            }
        }
Ejemplo n.º 6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Rectangle newBounds = new Rectangle {
                X     = settings.GetValue("mainForm.Location.X", Location.X),
                Y     = settings.GetValue("mainForm.Location.Y", Location.Y),
                Width = settings.GetValue("mainForm.Width",
                                          DpiHelper.LogicalToDeviceUnits(470)),
                Height = settings.GetValue("mainForm.Height",
                                           DpiHelper.LogicalToDeviceUnits(640))
            };

            Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
                                                      int.MinValue, int.MinValue);

            foreach (Screen screen in Screen.AllScreens)
            {
                fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
            }

            Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);

            if (intersection.Width < 20 || intersection.Height < 20 ||
                !settings.Contains("mainForm.Location.X")
                )
            {
                newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
                              (newBounds.Width / 2);

                newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
                              (newBounds.Height / 2);
            }

            this.Bounds = newBounds;

            if (!splitContainer.Panel2Collapsed)
            {
                splitContainer.SplitterDistance = settings.GetValue("splitContainer.SplitterDistance", splitContainer.SplitterDistance);
            }
        }
Ejemplo n.º 7
0
        public FanControllerManager(List <ISensor> sensors, PersistentSettings settings)
        {
            this.sensors  = sensors;
            this.settings = settings;

            active      = new List <FanController>();
            controllers = new List <FanController>();

            // Load controllers
            for (byte i = 0; i < MAX_CONTROLLERS; i++)
            {
                if (settings.Contains(new Identifier("FanController", i + "", "name").ToString()))
                {
                    // Skip controllers with missing fan control
                    try
                    {
                        AddController(new FanController(i, sensors, settings));
                    }
                    catch (Exception) { }
                }
            }
        }
Ejemplo n.º 8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Rectangle newBounds = new Rectangle {
                X     = settings.GetValue("mainForm.Location.X", Location.X),
                Y     = settings.GetValue("mainForm.Location.Y", Location.Y),
                Width = settings.GetValue("mainForm.Width",
                                          DpiHelper.LogicalToDeviceUnits(470)),
                Height = settings.GetValue("mainForm.Height",
                                           DpiHelper.LogicalToDeviceUnits(640))
            };

            Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
                                                      int.MinValue, int.MinValue);

            foreach (Screen screen in Screen.AllScreens)
            {
                fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
            }

            Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);

            if (intersection.Width < 20 || intersection.Height < 20 ||
                !settings.Contains("mainForm.Location.X")
                )
            {
                newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
                              (newBounds.Width / 2);

                newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
                              (newBounds.Height / 2);
            }

            this.Bounds = newBounds;

            // Register for receiving hardware change information (trough WndProc)
            DeviceNotification.RegisterDeviceNotification(Handle);
        }
Ejemplo n.º 9
0
        public SensorNode(ISensor sensor, PersistentSettings settings,
                          UnitManager unitManager, ISensorTextManager sensorTextManager) : base()
        {
            this.sensor            = sensor;
            this.settings          = settings;
            this.unitManager       = unitManager;
            this.sensorTextManager = sensorTextManager;


            bool hidden = settings.GetValue(new Identifier(sensor.Identifier,
                                                           "hidden").ToString(), sensor.IsDefaultHidden);

            base.IsVisible = !hidden;

            this.Plot = settings.GetValue(new Identifier(sensor.Identifier,
                                                         "plot").ToString(), false);

            string id = new Identifier(sensor.Identifier, "penColor").ToString();

            if (settings.Contains(id))
            {
                this.PenColor = settings.GetValue(id, Color.Black);
            }
        }
Ejemplo n.º 10
0
        public FanController(byte id, List <ISensor> sensors, PersistentSettings settings)
        {
            this.id       = id;
            this.sensors  = sensors;
            this.settings = settings;

            identifier = new Identifier("FanController", id + "");


            if (!settings.Contains(new Identifier(identifier, "name").ToString()))
            {
                // Create new instsance
                Name  = "FanController " + id;
                value = new ValueString("", sensors);

                // Select the first IControl available
                foreach (ISensor s in sensors)
                {
                    if (s.Control == null)
                    {
                        continue;
                    }
                    else
                    {
                        Controlled = s.Control;
                        break;
                    }
                }
                sourceSensor = sensors[0];
            }
            else
            {
                // Load instance
                name  = settings.GetValue(new Identifier(identifier, "name").ToString(), "FanController " + id);
                value = new ValueString(settings.GetValue(new Identifier(identifier, "valueString").ToString(), "0"), sensors);

                string c = settings.GetValue(new Identifier(identifier, "controlled").ToString(), null);
                foreach (ISensor s in sensors)
                {
                    if (s.Control == null)
                    {
                        continue;
                    }
                    if (s.Control.Identifier.ToString() == c)
                    {
                        controlled = s.Control;
                        break;
                    }
                }
            }

            if (controlled == null)
            {
                throw new Exception("No supported fan control found");
            }

            curve        = new FanControlCurve(new Identifier(identifier, "curve"), settings);
            enabled      = bool.Parse(settings.GetValue(new Identifier(identifier, "enabled").ToString(), "false"));
            hysteresis   = float.Parse(settings.GetValue(new Identifier(identifier, "hysteresis").ToString(), "1").Replace('.', ','));
            sourceSensor = SharedData.AllSensors.GetByIdentifier(settings.GetValue(new Identifier(identifier, "sourceSensor").ToString(), "0"));
            if (sourceSensor == null)
            {
                sourceSensor = sensors[0];
            }
            source     = (InputSource)int.Parse(settings.GetValue(new Identifier(identifier, "inputSource").ToString(), "0"));
            tryRestart = bool.Parse(settings.GetValue(new Identifier(identifier, "tryRestart").ToString(), "true"));
        }
Ejemplo n.º 11
0
        public DisplayConnector(IHardware[] hardware, List <ISensor> sensors, PersistentSettings settings)
        {
            this.settings = settings;
            this.sensors  = sensors;

            int tmp = 0;

            if (!int.TryParse(settings.GetValue(
                                  new Identifier(identifier, "mode").ToString(), "2"),
                              NumberStyles.Integer, CultureInfo.InvariantCulture,
                              out tmp))
            {
                mode = LCDConnectionMode.NONE;
            }
            else
            {
                mode = (LCDConnectionMode)tmp;
            }


            text = new List <SensorString>();

            this.curText = 0;
            int.TryParse(settings.GetValue(new Identifier(identifier, "curText").ToString(), "0"), out this.curText);

            int curID = 0;

            while (settings.Contains(new Identifier(identifier, curID + "", "text").ToString()))
            {
                text.Add(new SensorString(settings.GetValue(new Identifier(identifier, curID + "", "text").ToString(), "-"), sensors));
                curID++;
            }
            if (text.Count == 0)
            {
                text.Add(new SensorString("-", sensors));
            }

            // this.text = new List<SensorString>(new SensorString(settings.GetValue(new Identifier(identifier, curText + "", "text").ToString(), "-"), sensors);

            if (mode == LCDConnectionMode.SERIAL)
            {
                try
                {
                    //InitSerial(settings.GetValue(new Identifier(identifier, "comport").ToString(), "COM1"));
                } catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                    mode = LCDConnectionMode.NONE;
                }
            }
            else if (mode == LCDConnectionMode.ARDUINO)
            {
                // Stupidly pick the first Arduino found
                foreach (IHardware h in hardware)
                {
                    if (h.GetType() == typeof(Arduino))
                    {
                        arduino = (Arduino)h;
                        break;
                    }
                }
                if (arduino == null)
                {
                    mode = LCDConnectionMode.NONE;
                }
                else
                {
                    arduino.SetDisplay(true);
                    settings.hotkeyManager.RegisterHotkey("test", 0x0002 + 0x0004, (int)Keys.P, delegate
                    {
                        ToggleDisplay();
                    });
                    settings.hotkeyManager.RegisterHotkey("next_display_text", 0x0002 + 0x0004, (int)Keys.J, delegate
                    {
                        if (CurText + 1 > text.Count - 1)
                        {
                            CurText = 0;
                        }
                        else
                        {
                            CurText = CurText + 1;
                        }
                    });
                    settings.hotkeyManager.RegisterHotkey("prev_display_text", 0x0002 + 0x0004, (int)Keys.K, delegate
                    {
                        if (CurText - 1 < 0)
                        {
                            CurText = text.Count - 1;
                        }
                        else
                        {
                            CurText = CurText - 1;
                        }
                    });
                }
            }
        }
Ejemplo n.º 12
0
        public MainForm()
        {
            InitializeComponent();

            this.settings = new PersistentSettings();
            this.settings.Load(Path.ChangeExtension(
                                   Application.ExecutablePath, ".config"));

            this.unitManager = new UnitManager(settings);

            // set the DockStyle here, to avoid conflicts with the MainMenu
            this.splitContainer.Dock = DockStyle.Fill;

            this.Font      = SystemFonts.MessageBoxFont;
            treeView.Font  = SystemFonts.MessageBoxFont;
            plotPanel.Font = SystemFonts.MessageBoxFont;

            nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
            nodeCheckBox.CheckStateChanged    += UpdatePlotSelection;
            nodeTextBoxText.DrawText          += nodeTextBoxText_DrawText;
            nodeTextBoxValue.DrawText         += nodeTextBoxText_DrawText;
            nodeTextBoxMin.DrawText           += nodeTextBoxText_DrawText;
            nodeTextBoxMax.DrawText           += nodeTextBoxText_DrawText;
            nodeTextBoxText.EditorShowing     += nodeTextBoxText_EditorShowing;

            if (settings.Contains("mainForm.Location.X"))
            {
                int x = settings.GetValue("mainForm.Location.X", Location.X);
                x = x < 0 ? 0 : x;
                int y = settings.GetValue("mainForm.Location.Y", Location.Y);
                y             = y < 0 ? 0 : y;
                this.Location = new Point(x, y);
            }
            else
            {
                StartPosition = FormStartPosition.CenterScreen;
            }

            ClientSize = new Size(
                settings.GetValue("mainForm.Width", 470),
                settings.GetValue("mainForm.Height", 640));

            foreach (TreeColumn column in treeView.Columns)
            {
                column.Width = Math.Max(20, Math.Min(400,
                                                     settings.GetValue("treeView.Columns." + column.Header + ".Width",
                                                                       column.Width)));
            }

            treeModel  = new TreeModel();
            root       = new Node(System.Environment.MachineName);
            root.Image = Utilities.EmbeddedResources.GetImage("computer.png");

            treeModel.Nodes.Add(root);
            treeView.Model = treeModel;

            this.computer = new Computer(settings);

            systemTray = new SystemTray(computer, settings);
            systemTray.HideShowCommand += hideShowClick;
            systemTray.ExitCommand     += exitClick;

            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128)) // Unix
            {
                splitContainer.BorderStyle   = BorderStyle.None;
                splitContainer.Border3DStyle = Border3DStyle.Adjust;
                splitContainer.SplitterWidth = 4;
                treeView.BorderStyle         = BorderStyle.Fixed3D;
                plotPanel.BorderStyle        = BorderStyle.Fixed3D;
                gadgetMenuItem.Visible       = false;
                minCloseMenuItem.Visible     = false;
            }
            else // Windows
            {
                gadget = new SensorGadget(computer, settings, unitManager);
            }

            computer.HardwareAdded   += new HardwareEventHandler(HardwareAdded);
            computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
            computer.Open();

            timer.Enabled = true;

            plotColorPalette     = new Color[13];
            plotColorPalette[0]  = Color.Blue;
            plotColorPalette[1]  = Color.OrangeRed;
            plotColorPalette[2]  = Color.Green;
            plotColorPalette[3]  = Color.LightSeaGreen;
            plotColorPalette[4]  = Color.Goldenrod;
            plotColorPalette[5]  = Color.DarkViolet;
            plotColorPalette[6]  = Color.YellowGreen;
            plotColorPalette[7]  = Color.SaddleBrown;
            plotColorPalette[8]  = Color.RoyalBlue;
            plotColorPalette[9]  = Color.DeepPink;
            plotColorPalette[10] = Color.MediumSeaGreen;
            plotColorPalette[11] = Color.Olive;
            plotColorPalette[12] = Color.Firebrick;

            showHiddenSensors          = new UserOption("hiddenMenuItem", false, hiddenMenuItem, settings);
            showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
                treeModel.ForceVisible = showHiddenSensors.Value;
            };

            showPlot          = new UserOption("plotMenuItem", false, plotMenuItem, settings);
            showPlot.Changed += delegate(object sender, EventArgs e) {
                splitContainer.Panel2Collapsed = !showPlot.Value;
                treeView.Invalidate();
            };

            showValue          = new UserOption("valueMenuItem", true, valueMenuItem, settings);
            showValue.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[1].IsVisible = showValue.Value;
            };

            showMin          = new UserOption("minMenuItem", false, minMenuItem, settings);
            showMin.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[2].IsVisible = showMin.Value;
            };

            showMax          = new UserOption("maxMenuItem", true, maxMenuItem, settings);
            showMax.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[3].IsVisible = showMax.Value;
            };

            startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem, settings);

            minimizeToTray          = new UserOption("minTrayMenuItem", true, minTrayMenuItem, settings);
            minimizeToTray.Changed += delegate(object sender, EventArgs e) {
                systemTray.IsMainIconEnabled = minimizeToTray.Value;
            };

            minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, settings);

            autoStart          = new UserOption(null, startupManager.Startup, startupMenuItem, settings);
            autoStart.Changed += delegate(object sender, EventArgs e) {
                try {
                    startupManager.Startup = autoStart.Value;
                } catch (InvalidOperationException) {
                    MessageBox.Show("Updating the auto-startup option failed.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    autoStart.Value = startupManager.Startup;
                }
            };

            readHddSensors          = new UserOption("hddMenuItem", true, hddMenuItem, settings);
            readHddSensors.Changed += delegate(object sender, EventArgs e) {
                computer.HDDEnabled = readHddSensors.Value;
                UpdatePlotSelection(null, null);
            };

            showGadget          = new UserOption("gadgetMenuItem", false, gadgetMenuItem, settings);
            showGadget.Changed += delegate(object sender, EventArgs e) {
                if (gadget != null)
                {
                    gadget.Visible = showGadget.Value;
                }
            };

            celciusMenuItem.Checked =
                unitManager.TemperatureUnit == TemperatureUnit.Celcius;
            fahrenheitMenuItem.Checked = !celciusMenuItem.Checked;

            startupMenuItem.Visible = startupManager.IsAvailable;

            if (startMinMenuItem.Checked)
            {
                if (!minTrayMenuItem.Checked)
                {
                    WindowState = FormWindowState.Minimized;
                    Show();
                }
            }
            else
            {
                Show();
            }

            // Create a handle, otherwise calling Close() does not fire FormClosed
            IntPtr handle = Handle;

            // Make sure the settings are saved when the user logs off
            Microsoft.Win32.SystemEvents.SessionEnded +=
                delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
                SaveConfiguration();
            };
        }