private void MonitorCPUTemperatureAndRegulateFan() { int fanSpeedAdjustmentsCounter = 0; var temps = new RunningAvg(MagicConstants.NR_MEASUREMENTS_FOR_AVERAGE_TEMP); int fanPercentage = MagicConstants.INITIAL_FAN_PERCENTAGE; int prevFanPercentage = MagicConstants.INITIAL_FAN_PERCENTAGE; int?currTemp; fan?.SetFanSpeed(1, fanPercentage); var CPU = GetCPU(); while (true) { CPU.Update(); currTemp = GetCurrentTemperature(CPU); if (currTemp != null) { temps.Add(currTemp.Value); fanPercentage = CalcFanPercentage(fanPercentage, temps.GetAvg(MagicConstants.NR_MEASUREMENTS_FOR_CURRENT_TEMP), temps.GetAvg()); if (fanPercentage != prevFanPercentage) { Log.Information($"\nLast updated fan speed at {DateTime.Now.ToLongTimeString()}. {++fanSpeedAdjustmentsCounter} updates so far.\n"); fan?.SetFanSpeed(1, fanPercentage); prevFanPercentage = fanPercentage; } } System.Threading.Thread.Sleep(MagicConstants.SLEEP_TIME_BETWEEN_MEASUREMENTS); } }
private void tmrMain_Tick(object sender, EventArgs e) { // Get CPU temperature and set fan speed currentCpuTemp = GetCurrentTemperature("CPU"); currentGpuTemp = GetCurrentTemperature("GPU"); currentCpuFan = CalcFanPercentage("CPU", currentCpuTemp); currentGpuFan = CalcFanPercentage("GPU", currentGpuTemp); if (currentCpuTemp >= 80 && currentGpuTemp >= 80) { currentCpuFan = 100; currentGpuFan = 100; } if (currentCpuFan != prevFanCPUPercentage) { fan?.SetFanSpeed(1, currentCpuFan); prevFanCPUPercentage = currentCpuFan; } if (currentGpuFan != prevFanGPUPercentage) { fan?.SetFanSpeed(2, currentGpuFan); prevFanGPUPercentage = currentGpuFan; } timerTickCount++; if (timerTickCount == 100) { //GC.Collect(); timerTickCount = 0; } UpdateGui(); }
private void tmrMain_Tick(object sender, EventArgs e) { //fanUpdateTick = !fanUpdateTick; // Get CPU temperature and set fan speed currentCpuTemp = GetCurrentTemperature("CPU"); currentGpuTemp = GetCurrentTemperature("GPU"); if (currentCpuTemp > maxCpuTemp) { maxCpuTemp = currentCpuTemp; } if (currentGpuTemp > maxGpuTemp) { maxGpuTemp = currentGpuTemp; } //if (currentCpuTemp >= 80) { // tmrHighCpuDelay.Enabled = true; //} if (currentCpuTemp >= cpuSafetyTemp || currentGpuTemp >= gpuSafetyTemp) { currentCpuFan = 100; currentGpuFan = 100; } else { currentCpuFan = CalcFanPercentage("CPU", currentCpuTemp); currentGpuFan = CalcFanPercentage("GPU", currentGpuTemp); } if (btnACFans.Checked && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online) { if (currentCpuFan < 30) { currentCpuFan = 30; } if (currentGpuFan < 30) { currentGpuFan = 30; } } //if (currentCpuTemp >= 80 && currentGpuTemp >= 80) { // currentCpuFan = 100; // currentGpuFan = 100; //} //if (currentGpuTemp >= 80) { // currentCpuFan = currentGpuFan; //} if (!clevoAutoFans) { if (currentCpuFan != prevFanCPUPercentage || timerTickCount * tmrMain.Interval * 0.001 >= 60) { //if (prevCpuTemp < 80 && currentCpuTemp >= 80) { // if (highCpuDelayFinished) { fan?.SetFanSpeed(1, currentCpuFan); //RampFanSpeed(1, currentCpuFan); prevFanCPUPercentage = currentCpuFan; cpuSameTempTicks = 0; //highCpuDelayFinished = false; //tmrHighCpuDelay.Enabled = false; //} //} else { // fan?.SetFanSpeed(1, currentCpuFan); // //RampFanSpeed(1, currentCpuFan); // prevFanCPUPercentage = currentCpuFan; // cpuSameTempTicks = 0; //} } if (currentGpuFan != prevFanGPUPercentage || timerTickCount * tmrMain.Interval * 0.001 >= 60) { fan?.SetFanSpeed(2, currentGpuFan); //RampFanSpeed(2, currentCpuFan); prevFanGPUPercentage = currentGpuFan; gpuSameTempTicks = 0; } } timerTickCount++; if (timerTickCount * tmrMain.Interval * 0.001 > 60) { //GC.Collect(); timerTickCount = 0; } prevCpuTemp = currentCpuTemp; prevGpuTemp = currentGpuTemp; }