/// <summary> /// Changes a cooler setting by modifying the policy /// </summary> /// <param name="coolerId">The cooler identification number (index) to change the settings.</param> /// <param name="policy">The new cooler policy.</param> // ReSharper disable once TooManyDeclarations public void SetCoolerSettings(int coolerId, CoolerPolicy policy) { 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) } ), 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) : entry ) .ToArray(), currentControl.UnknownUInt ); GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl); }
private bool NvFanCoolersGetControl(int busId, out PrivateFanCoolersControlV1 info) { info = new PrivateFanCoolersControlV1(); if (NvapiNativeMethods.NvFanCoolersGetControl == null) { return(false); } info.version = (uint)(VERSION1 | (Marshal.SizeOf(typeof(PrivateFanCoolersControlV1)))); var r = NvapiNativeMethods.NvFanCoolersGetControl(HandlesByBusId[busId], ref info); if (r != NvStatus.OK) { Write.DevError($"{nameof(NvapiNativeMethods.NvFanCoolersGetControl)} {r}"); return(false); } return(true); }
/// <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); }
private static bool NvFanCoolersGetControl(int busId, out PrivateFanCoolersControlV1 info) { info = PrivateFanCoolersControlV1.Create(); if (NvapiNativeMethods.NvFanCoolersGetControl == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvFanCoolersGetControl(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersGetControl)} {r.ToString()}"); return(false); } return(true); } catch { } return(false); }