/// <summary> /// Changes a cooler settings by modifying the policy and the current level /// </summary> /// <param name="coolerId">The cooler identification number (index) to change the settings.</param> /// <param name="policy">The new cooler policy.</param> /// <param name="newLevel">The new cooler level. Valid only if policy is set to manual.</param> // ReSharper disable once TooManyDeclarations public void SetCoolerSettings(int coolerId, CoolerPolicy policy, int newLevel) { if (Coolers.All(cooler => cooler.CoolerId != coolerId)) { throw new ArgumentException("Invalid cooler identification number provided.", nameof(coolerId)); } try { GPUApi.SetCoolerLevels( PhysicalGPU.Handle, (uint)coolerId, new PrivateCoolerLevelsV1(new[] { new PrivateCoolerLevelsV1.CoolerLevel(policy, (uint)newLevel) } ), 1 ); return; } catch (NVIDIAApiException e) { if (e.Status != Status.NotSupported) { throw; } } var currentControl = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle); var newControl = new PrivateFanCoolersControlV1( currentControl.FanCoolersControlEntries.Select( entry => entry.CoolerId == coolerId ? new PrivateFanCoolersControlV1.FanCoolersControlEntry( entry.CoolerId, policy == CoolerPolicy.Manual ? FanCoolersControlMode.Manual : FanCoolersControlMode.Auto, policy == CoolerPolicy.Manual ? (uint)newLevel : 0u) : entry ) .ToArray(), currentControl.UnknownUInt ); GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl); }
/// <summary> /// Resets one or more cooler settings to default. /// </summary> /// <param name="coolerIds">The cooler identification numbers (indexes) to reset their settings to default.</param> public void RestoreCoolerSettingsToDefault(params int[] coolerIds) { var availableCoolerIds = Coolers.Select(cooler => cooler.CoolerId).ToArray(); if (coolerIds.Any(i => !availableCoolerIds.Contains(i))) { throw new ArgumentException("Invalid cooler identification number provided.", nameof(coolerIds)); } try { GPUApi.RestoreCoolerSettings(PhysicalGPU.Handle, coolerIds.Select(i => (uint)i).ToArray()); return; } catch (NVIDIAApiException e) { if (e.Status != Status.NotSupported) { throw; } } var currentControl = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle); var newControl = new PrivateFanCoolersControlV1( currentControl.FanCoolersControlEntries.Select( entry => coolerIds.Contains((int)entry.CoolerId) ? new PrivateFanCoolersControlV1.FanCoolersControlEntry( entry.CoolerId, FanCoolersControlMode.Auto ) : entry ) .ToArray(), currentControl.UnknownUInt ); GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl); }
/// <summary> /// Resets all cooler settings to default. /// </summary> public void RestoreCoolerSettingsToDefault() { RestoreCoolerSettingsToDefault(Coolers.Select(cooler => cooler.CoolerId).ToArray()); }