Ejemplo n.º 1
0
        public static void Main()
        {
            // confirm warning (just on time)
            if (!File.Exists(".confirmed"))
            {
                var confirmResult = MessageBox.Show(
                    String.Join(
                        Environment.NewLine,
                        "This programm takes over the DELL fan conrol",
                        "and disables the internal thermal fan management!",
                        "",
                        "Use at your own risk and control the temperatures",
                        "with an external tool.",
                        "",
                        "The driver will ONLY be unloaded on a hard reset!"
                        ),
                    "Caution!",
                    MessageBoxButtons.OKCancel
                    );

                if (confirmResult == DialogResult.Cancel)
                {
                    Program.Quit();
                    return;
                }

                File.Create(".confirmed");
            }

            // all other exceptions
            Application.ThreadException += new ThreadExceptionEventHandler(Program.OnThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.OnUnhandledException);

            // see https://stackoverflow.com/a/10579614, must be called before Appplication.Run();
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(Program.OnApplicationExit);
            Application.ApplicationExit         += new EventHandler(Program.OnApplicationExit);
            SystemEvents.SessionEnding          += new SessionEndingEventHandler(Program.OnSessionEnding);

            // see https://stackoverflow.com/a/406473
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            appContext = new DellFanControlApplicationContext();
            Application.Run(appContext);
        }
Ejemplo n.º 2
0
        public DellFanCtrl(DellFanControlApplicationContext context)
        {
            this.Init(context);

            uint tempCPU       = 0;
            uint tempGPU       = 0;
            int  fanOneLevel   = 0;
            int  fanTwoLevel   = 0;
            int  fanDelayTime1 = 0;
            int  fanDelayTime2 = 0;

            while (context.driverRunning)
            {
                Thread.Sleep(context.config["pollingInterval"]);

                if (context.nextAction == (int)Global.ACTION.EXIT)
                {
                    context.nextAction = (int)Global.ACTION.WAIT;
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL1, DELL_SMM_IO_NO_ARG);
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL2, DELL_SMM_IO_NO_ARG);
                    break;
                }

                if (context.nextAction == (int)Global.ACTION.ENABLE)
                {
                    context.nextAction = (int)Global.ACTION.NONE;
                    tempCPU            = 0;
                    tempGPU            = 0;
                    fanOneLevel        = 0;
                    fanTwoLevel        = 0;
                    fanDelayTime1      = 0;
                    fanDelayTime2      = 0;
                    this.Init(context);
                }

                if (context.nextAction == (int)Global.ACTION.RESUME)
                {
                    context.nextAction = (int)Global.ACTION.NONE;
                    tempCPU            = 0;
                    tempGPU            = 0;
                    fanOneLevel        = 0;
                    fanTwoLevel        = 0;
                    fanDelayTime1      = 0;
                    fanDelayTime2      = 0;
                    this.Init(context);
                }

                if (context.nextAction == (int)Global.ACTION.DISABLE)
                {
                    context.nextAction = (int)Global.ACTION.WAIT;
                    tempCPU            = 0;
                    tempGPU            = 0;
                    fanOneLevel        = 0;
                    fanTwoLevel        = 0;
                    fanDelayTime1      = 0;
                    fanDelayTime2      = 0;
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL1, DELL_SMM_IO_NO_ARG);
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL2, DELL_SMM_IO_NO_ARG);
                    continue;
                }

                if (context.nextAction == (int)Global.ACTION.SUSPEND)
                {
                    context.nextAction = (int)Global.ACTION.WAIT;
                    tempCPU            = 0;
                    tempGPU            = 0;
                    fanOneLevel        = 0;
                    fanTwoLevel        = 0;
                    fanDelayTime1      = 0;
                    fanDelayTime2      = 0;
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL1, DELL_SMM_IO_NO_ARG);
                    dell_smm_io(DELL_SMM_IO_ENABLE_FAN_CTL2, DELL_SMM_IO_NO_ARG);
                    continue;
                }

                tempCPU = dell_smm_io_get_cpu_temperature();
                tempGPU = dell_smm_io_get_gpu_temperature();

                context.trayIcon.Text = "CPU: " + tempCPU.ToString() + "°C" + Environment.NewLine + "GPU: " + tempGPU.ToString() + "°C";

                if (context.nextAction == (int)Global.ACTION.WAIT)
                {
                    continue;
                }

                fanDelayTime1--;
                fanDelayTime2--;

                if (fanDelayTime1 <= 0)
                {
                    fanDelayTime1 = 0;
                }

                if (fanDelayTime2 <= 0)
                {
                    fanDelayTime2 = 0;
                }

                // Fan one

                if (tempCPU < context.config["FanOneCPUTemperatureThresholdZero"] && tempGPU < context.config["FanOneGPUTemperatureThresholdZero"])
                {
                    fanOneLevel = 0;
                }

                if (tempCPU >= context.config["FanOneCPUTemperatureThresholdOne"] || tempGPU >= context.config["FanOneGPUTemperatureThresholdOne"])
                {
                    fanOneLevel = 1;
                }

                if (tempCPU >= context.config["FanOneCPUTemperatureThresholdTwo"] || tempGPU >= context.config["FanOneGPUTemperatureThresholdTwo"])
                {
                    fanOneLevel = 2;
                }

                // Fan two

                if (tempCPU < context.config["FanTwoCPUTemperatureThresholdZero"] && tempGPU < context.config["FanTwoGPUTemperatureThresholdZero"])
                {
                    fanTwoLevel = 0;
                }

                if (tempCPU >= context.config["FanTwoCPUTemperatureThresholdOne"] || tempGPU >= context.config["FanTwoGPUTemperatureThresholdOne"])
                {
                    fanTwoLevel = 1;
                }

                if (tempCPU >= context.config["FanTwoCPUTemperatureThresholdTwo"] || tempGPU >= context.config["FanTwoGPUTemperatureThresholdTwo"])
                {
                    fanTwoLevel = 2;
                }

                // Set the fan speed

                // Fan 1

                if (fanOneLevel == 0 && fanDelayTime1 == 0)
                {
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN1, DELL_SMM_IO_FAN_LV0);
                }

                if (fanOneLevel == 1 && fanDelayTime2 == 0)
                {
                    fanDelayTime1 = context.config["minCooldownTime"];
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN1, DELL_SMM_IO_FAN_LV1);
                }

                if (fanOneLevel == 2)
                {
                    fanDelayTime2 = context.config["minCooldownTime"];
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN1, DELL_SMM_IO_FAN_LV2);
                }

                // Fan 2

                if (fanTwoLevel == 0 && fanDelayTime1 == 0)
                {
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN2, DELL_SMM_IO_FAN_LV0);
                }

                if (fanTwoLevel == 1 && fanDelayTime2 == 0)
                {
                    fanDelayTime1 = context.config["minCooldownTime"];
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN2, DELL_SMM_IO_FAN_LV1);
                }

                if (fanTwoLevel == 2)
                {
                    fanDelayTime2 = context.config["minCooldownTime"];
                    dell_smm_io_set_fan_lv(DELL_SMM_IO_FAN2, DELL_SMM_IO_FAN_LV2);
                }
            }

            Interop.CloseHandle(this.hDriver);
            BDSID_Shutdown();
        }
Ejemplo n.º 3
0
        public void Init(DellFanControlApplicationContext context)
        {
            this.hDriver = Interop.CreateFile(
                @"\\.\BZHDELLSMMIO",
                Interop.GENERIC_READ | Interop.GENERIC_WRITE,
                0,
                IntPtr.Zero,
                Interop.OPEN_EXISTING,
                Interop.FILE_ATTRIBUTE_NORMAL,
                IntPtr.Zero
                );

            IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);

            if (this.hDriver == INVALID_HANDLE_VALUE)
            {
                Console.WriteLine("notRunning");
                BDSID_InstallDriver();

                Process process = new Process();
                if (Environment.Is64BitOperatingSystem)
                {
                    process.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\lib\\wind64.exe";
                }
                else
                {
                    process.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\lib\\wind32.exe";
                }
                process.StartInfo.Arguments              = "/L BZHDELLSMMIO";
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;
                process.Start();
                while (!process.StandardOutput.EndOfStream)
                {
                    // TODO: Catch wind64.exe errors by parsing line
                    string line = process.StandardOutput.ReadLine();
                }

                this.hDriver = Interop.CreateFile(@"\\.\BZHDELLSMMIO",
                                                  Interop.GENERIC_READ | Interop.GENERIC_WRITE,
                                                  Interop.FILE_SHARE_READ | Interop.FILE_SHARE_WRITE,
                                                  IntPtr.Zero,
                                                  Interop.OPEN_EXISTING,
                                                  Interop.FILE_ATTRIBUTE_NORMAL,
                                                  IntPtr.Zero);

                // As long as the driver is not signed and started with wind64.exe we do not need this
                // BDSID_StartDriver();
            }

            if (context.config["FanOneActive"] == 1)
            {
                dell_smm_io(DELL_SMM_IO_DISABLE_FAN_CTL1, DELL_SMM_IO_NO_ARG);
            }

            if (context.config["FanTwoActive"] == 1)
            {
                dell_smm_io(DELL_SMM_IO_DISABLE_FAN_CTL2, DELL_SMM_IO_NO_ARG);
            }

            // Console.WriteLine(Interop.GetLastError());
        }