Example #1
0
        /// <summary>
        ///     [PRIVATE]
        ///     Gets the cooler policy table for the passed GPU handle.
        /// </summary>
        /// <param name="gpuHandle">The handle of the GPU to perform the operation on.</param>
        /// <param name="policy">The cooler policy to get the table for.</param>
        /// <param name="index">The cooler index.</param>
        /// <param name="count">Number of policy table entries retrieved.</param>
        /// <returns>The cooler policy table for the GPU.</returns>
        // ReSharper disable once TooManyArguments
        public static PrivateCoolerPolicyTableV1 GetCoolerPolicyTable(
            PhysicalGPUHandle gpuHandle,
            CoolerPolicy policy,
            uint index,
            out uint count)
        {
            var instance = typeof(PrivateCoolerPolicyTableV1).Instantiate <PrivateCoolerPolicyTableV1>();

            instance._Policy = policy;

            using (var policyTableReference = ValueTypeReference.FromValueType(instance))
            {
                var status = DelegateFactory.GetDelegate <Delegates.GPU.NvAPI_GPU_GetCoolerPolicyTable>()(
                    gpuHandle,
                    index,
                    policyTableReference,
                    out count
                    );

                if (status != Status.Ok)
                {
                    throw new NVIDIAApiException(status);
                }

                return(policyTableReference.ToValueType <PrivateCoolerPolicyTableV1>(typeof(PrivateCoolerPolicyTableV1)));
            }
        }
Example #2
0
        public override int setSpeed(int value)
        {
            if (value > mMaxSpeed)
            {
                Value = mMaxSpeed;

                mCurrentPolicy = CoolerPolicy.Manual;
            }
            else if (value < mMinSpeed)
            {
                Value = value;

                mCurrentPolicy = mDefaultPolicy;
            }
            else
            {
                Value = value;

                mCurrentPolicy = CoolerPolicy.Manual;
            }

            onSetNvAPIControlHandler(mIndex, mCoolerID, Value, mCurrentPolicy);

            LastValue = Value;
            return(Value);
        }
 /// <summary>
 ///     Creates a new instance of <see cref="CoolerLevel" />
 /// </summary>
 /// <param name="coolerPolicy">The cooler policy.</param>
 public CoolerLevel(CoolerPolicy coolerPolicy) : this(coolerPolicy, 0)
 {
     if (coolerPolicy == CoolerPolicy.Manual)
     {
         throw new ArgumentException(
                   "Manual policy is not valid when no level value is provided.",
                   nameof(coolerPolicy)
                   );
     }
 }
Example #4
0
 public NvAPIFanControl(string name, int index, int coolerID, int value, int minSpeed, int maxSpeed, CoolerPolicy defaultPolicy) : base()
 {
     Name           = name;
     mIndex         = index;
     mCoolerID      = coolerID;
     Value          = value;
     LastValue      = value;
     mMinSpeed      = minSpeed;
     mMaxSpeed      = maxSpeed;
     mDefaultPolicy = defaultPolicy;
 }
Example #5
0
        private void createGPUControl()
        {
            // Gigabyte
            if (mIsGigabyte == true)
            {
            }

            // LibreHardwareMonitor
            else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor)
            {
                mLHM.createGPUFanControl(ref mControlList);
            }

            // OpenHardwareMonitor
            else
            {
                mOHM.createGPUFanControl(ref mControlList);
            }

            if (OptionManager.getInstance().IsNvAPIWrapper == true)
            {
                this.lockBus();
                try
                {
                    int gpuFanNum = 1;
                    var gpuArray  = PhysicalGPU.GetPhysicalGPUs();
                    for (int i = 0; i < gpuArray.Length; i++)
                    {
                        var e = gpuArray[i].CoolerInformation.Coolers.GetEnumerator();
                        while (e.MoveNext())
                        {
                            var          value         = e.Current;
                            int          coolerID      = value.CoolerId;
                            int          speed         = value.CurrentLevel;
                            int          minSpeed      = value.DefaultMinimumLevel;
                            int          maxSpeed      = value.DefaultMaximumLevel;
                            CoolerPolicy defaultPolicy = value.DefaultPolicy;

                            var name = "GPU Fan Control #" + gpuFanNum++;
                            while (this.isExistControl(name) == true)
                            {
                                name = "GPU Fan Control #" + gpuFanNum++;
                            }

                            var control = new NvAPIFanControl(name, i, coolerID, speed, minSpeed, maxSpeed, defaultPolicy);
                            control.onSetNvAPIControlHandler += onSetNvApiControl;
                            mControlList.Add(control);
                        }
                    }
                }
                catch { }
                this.unlockBus();
            }
        }
Example #6
0
 public NvAPIFanControl(string id, string name, int index, int coolerID, int value, int minSpeed, int maxSpeed, CoolerPolicy defaultCoolerPolicy) : base(LIBRARY_TYPE.NvAPIWrapper)
 {
     ID                   = id;
     Name                 = name;
     mIndex               = index;
     mCoolerID            = coolerID;
     Value                = value;
     LastValue            = value;
     mMinSpeed            = minSpeed;
     mMaxSpeed            = maxSpeed;
     IsSetSpeed           = true;
     mDefaultCoolerPolicy = defaultCoolerPolicy;
     Console.WriteLine("NvAPIFanControl.NvAPIFanControl() : defaultCoolerPolicy({0})", (int)defaultCoolerPolicy);
 }
        /// <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);
        }
Example #8
0
        /// <summary>
        ///     [PRIVATE]
        ///     Restores the cooler policy table to default for the passed GPU handle and cooler index.
        /// </summary>
        /// <param name="gpuHandle">The handle of the GPU to perform the operation on.</param>
        /// <param name="policy">The cooler policy to restore to default.</param>
        /// <param name="indexes">The indexes of the coolers to restore their policy tables to default.</param>
        public static void RestoreCoolerPolicyTable(
            PhysicalGPUHandle gpuHandle,
            CoolerPolicy policy,
            uint[] indexes = null)
        {
            var status = DelegateFactory.GetDelegate <Delegates.GPU.NvAPI_GPU_RestoreCoolerPolicyTable>()(
                gpuHandle,
                indexes,
                (uint)(indexes?.Length ?? 0),
                policy
                );

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }
        }
Example #9
0
 private void onSetNvApiControl(int index, int coolerID, int value, CoolerPolicy policy)
 {
     this.lockBus();
     try
     {
         var gpuArray = PhysicalGPU.GetPhysicalGPUs();
         if (index >= gpuArray.Length)
         {
             this.unlockBus();
             return;
         }
         var info = gpuArray[index].CoolerInformation;
         info.SetCoolerSettings(coolerID, policy, value);
     }
     catch { }
     this.unlockBus();
 }
 /// <summary>
 ///     Creates a new instance of <see cref="CoolerLevel" />
 /// </summary>
 /// <param name="coolerPolicy">The cooler policy.</param>
 /// <param name="level">The cooler level in percentage.</param>
 public CoolerLevel(CoolerPolicy coolerPolicy, uint level)
 {
     _CurrentPolicy = coolerPolicy;
     _CurrentLevel  = level;
 }
Example #11
0
 public override void stop()
 {
     mCurrentPolicy = mDefaultPolicy;
     onSetNvAPIControlHandler(mIndex, mCoolerID, Value, mDefaultPolicy);
 }