Exemple #1
0
        public SensorManager(ISensorValueProviderFactory sensorValueProviderFactory, IReadOnlyDictionary <Identifier, SensorConfig> sensorConfigs)
        {
            Logger.Info("Creating Sensor Manager...");
            _sensorValueProviderFactory = sensorValueProviderFactory;
            _sensorConfigs = sensorConfigs;

            _openHardwareMonitorFacade = new OpenHardwareMonitorFacade();
            _sensorValueProviders      = new Dictionary <Identifier, ISensorValueProvider>();
            _hardware = new HashSet <IHardware>();
        }
Exemple #2
0
        private static void ShowHardwareInfo()
        {
            LogManager.DisableLogging();

            void WriteHeader(string header)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(header);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("-------------------------------");
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            void WriteFooter()
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("-------------------------------");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Press any key to continue...");
                Console.ResetColor();
            }

            Console.Clear();
            WriteHeader("Controllers");

            PluginLoader.Load($@"{AppDomain.CurrentDomain.BaseDirectory}\Plugins", typeof(IControllerDefinition));
            using (var deviceManager = new DeviceManager())
            {
                foreach (var controller in deviceManager.Controllers)
                {
                    Console.WriteLine($"Name: {controller.Name}" +
                                      $"\nVendorId: {controller.VendorId}" +
                                      $"\nProductId: {controller.ProductId}");
                    Console.WriteLine($"Ports:");
                    foreach (var port in controller.Ports)
                    {
                        var data = controller.GetPortData(port.Id);
                        Console.WriteLine($"\tId: {port.Id}" +
                                          $"\n\tData: {data}" +
                                          $"\n\tIdentifier: {port}" +
                                          $"\n");
                    }

                    Console.WriteLine($"Available effect types:");
                    Console.WriteLine($"{string.Join(", ", controller.EffectTypes)}");
                    Console.WriteLine();
                }
            }

            WriteHeader("Plugins");

            var pluginAssemblies = PluginLoader.SearchAll($@"{AppDomain.CurrentDomain.BaseDirectory}\Plugins");

            Console.WriteLine("Valid plugins:");
            foreach (var assembly in pluginAssemblies)
            {
                Console.WriteLine($"\t{Path.GetFileName(assembly.Location)}");
            }

            Console.WriteLine();

            WriteHeader("Sensors");
            using (var _openHardwareMonitorFacade = new OpenHardwareMonitorFacade())
            {
                var availableSensors = _openHardwareMonitorFacade.Sensors.Where(s => s.SensorType == SensorType.Temperature);
                foreach (var(hardware, sensors) in availableSensors.GroupBy(s => s.Hardware))
                {
                    Console.WriteLine($"{hardware.Name}:");
                    hardware.Update();

                    foreach (var sensor in sensors)
                    {
                        Console.WriteLine($"\t{sensor.Name} ({sensor.Identifier}): {sensor.Value ?? float.NaN}");
                    }
                }
            }

            WriteFooter();
            Console.ReadKey(true);

            LogManager.EnableLogging();
        }
Exemple #3
0
        private static bool DebugMenu()
        {
            if (!LogManager.Configuration.LoggingRules.Any(r => r.IsLoggingEnabledForLevel(LogLevel.Trace)))
            {
                LogManager.DisableLogging();
            }

            void WriteHeader(string header)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(header);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("-------------------------------");
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            void WriteFooter()
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("-------------------------------");
                Console.ForegroundColor = ConsoleColor.White;
                Console.ResetColor();
            }

            void WriteProperty(int indent, string propertyName, object value = null)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write($"» {new string('\t', indent)} ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write($"{propertyName}");
                if (value != null)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write($"{value}");
                }
                Console.WriteLine();
                Console.ResetColor();
            }

            void WaitForInput()
            {
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }

            void ListControllers()
            {
                WriteHeader("Controllers");
                WriteProperty(0, "");

                PluginLoader.Load($@"{AppDomain.CurrentDomain.BaseDirectory}\Plugins", typeof(IControllerDefinition));
                using (var deviceManager = new DeviceManager())
                {
                    foreach (var controller in deviceManager.Controllers)
                    {
                        WriteProperty(0, "Name: ", controller.Name);
                        WriteProperty(1, "VendorId: ", controller.VendorId);
                        WriteProperty(1, "ProductId: ", controller.ProductId);
                        WriteProperty(1, "Ports: ");

                        foreach (var port in controller.Ports)
                        {
                            var data = controller.GetPortData(port.Id);
                            WriteProperty(2, $"{port.Id}: ");
                            WriteProperty(3, "Data: ", data);
                            WriteProperty(3, "Identifier: ", port);
                        }

                        WriteProperty(1, "Available effect types: ", string.Join(", ", controller.EffectTypes));
                    }
                }

                WriteProperty(0, "");
                WriteFooter();
            }

            void ListSensors(params SensorType[] types)
            {
                WriteHeader("Sensors");
                WriteProperty(0, "");

                string FormatValue(SensorType type, float value)
                {
                    switch (type)
                    {
                    case SensorType.Voltage:     return($"{value:F2} V");

                    case SensorType.Clock:       return($"{value:F0} MHz");

                    case SensorType.Load:        return($"{value:F1} %");

                    case SensorType.Temperature: return($"{value:F1} °C");

                    case SensorType.Fan:         return($"{value:F0} RPM");

                    case SensorType.Flow:        return($"{value:F0} L/h");

                    case SensorType.Control:     return($"{value:F1} %");

                    case SensorType.Level:       return($"{value:F1} %");

                    case SensorType.Power:       return($"{value:F0} W");

                    case SensorType.Data:        return($"{value:F0} GB");

                    case SensorType.SmallData:   return($"{value:F1} MB");

                    case SensorType.Factor:      return($"{value:F3}");

                    case SensorType.Frequency:   return($"{value:F1} Hz");

                    case SensorType.Throughput:  return($"{value:F1} B/s");
                    }

                    return($"{value}");
                }

                using (var _openHardwareMonitorFacade = new OpenHardwareMonitorFacade())
                {
                    var availableSensors = _openHardwareMonitorFacade.Sensors.Where(s => types.Length > 0 ? types.Contains(s.SensorType) : true);
                    foreach (var(hardware, sensors) in availableSensors.GroupBy(s => s.Hardware))
                    {
                        WriteProperty(0, $"{hardware.Name}:");
                        hardware.Update();

                        foreach (var(type, group) in sensors.GroupBy(s => s.SensorType))
                        {
                            WriteProperty(1, $"{type}:");
                            foreach (var sensor in group)
                            {
                                WriteProperty(2, $"{ sensor.Name} ({ sensor.Identifier}): ", FormatValue(type, sensor.Value ?? float.NaN));
                            }
                        }

                        WriteProperty(0, "");
                    }
                }

                WriteFooter();
            }

            void ListPlugins()
            {
                WriteHeader("Plugins");
                WriteProperty(0, "");

                var pluginAssemblies = PluginLoader.SearchAll($@"{AppDomain.CurrentDomain.BaseDirectory}\Plugins");

                WriteProperty(0, "Detected plugins:");
                foreach (var assembly in pluginAssemblies)
                {
                    WriteProperty(1, Path.GetFileName(assembly.Location));
                }

                WriteProperty(0, "");
                WriteFooter();
            }

            var enabled = Service != null && Service.Status != ServiceControllerStatus.Running;
            var menu    = new MenuPage("Main Menu > Debug");

            menu.Add("Report", () => {
                Console.Clear();
                ListControllers();
                ListSensors(SensorType.Temperature);
                WaitForInput();
                return(false);
            }, () => enabled);
            menu.Add("Controllers", () => {
                Console.Clear();
                ListControllers();
                WaitForInput();
                return(false);
            }, () => enabled);
            menu.Add("Sensors", () => {
                Console.Clear();
                ListSensors();
                WaitForInput();
                return(false);
            }, () => enabled);
            menu.Add("Plugins", () => {
                Console.Clear();
                ListPlugins();
                WaitForInput();
                return(false);
            }, () => enabled);
            menu.Add("Back", () => {
                LogManager.EnableLogging();
                return(true);
            }, () => true, '0');

            while (true)
            {
                Console.Clear();
                var selected = menu.Show();
                if (selected.Callback())
                {
                    return(false);
                }
            }
        }