Skip to content

Commit

Permalink
Merge pull request #2868 from nicehash/NL-2065_GPUStatus
Browse files Browse the repository at this point in the history
gpu statuses now saving on toggle
  • Loading branch information
object05 authored Mar 14, 2023
2 parents 4994c1f + 697c519 commit 43122a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/NHMCore/ApplicationState/MiningState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public int DisabledDeviceStateCount
#endregion DeviceState Counts

public bool MiningManuallyStarted { get; set; }
public bool MiningStoppedByToggle { get; set; } = false;

// poor mans way
public void CalculateDevicesStateChange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using NHM.Common.Enums;
using NHMCore.ApplicationState;

namespace NHMCore
{
Expand Down Expand Up @@ -31,6 +32,32 @@ public static async Task SetDeviceEnabledState(object sender, (string uuid, bool
.Distinct()
.Select(dev => SetDeviceEnabledState(dev, enabled))
.ToArray();

var thisDevice = AvailableDevices.GetDeviceWithUuidOrB64Uuid(uuid);
var isAnyOtherDeviceMining = AvailableDevices.Devices?.Where(d => d.Enabled)?
.SelectMany(d => d.AlgorithmSettings)?
.Where(a => a.ComputeDevice.B64Uuid != thisDevice.B64Uuid)?
.Any(a => a.IsCurrentlyMining);
var isThisDeviceMining = thisDevice.AlgorithmSettings?.Any(a => a.IsCurrentlyMining);
if (isAnyOtherDeviceMining != null && isThisDeviceMining != null) //when mining and stop by toggle, this device mining is false...
{
if (enabled)
{
if ((bool)!isThisDeviceMining && !(bool)isAnyOtherDeviceMining && MiningState.Instance.MiningStoppedByToggle)
{
MiningState.Instance.MiningStoppedByToggle = false;
_ = StartAllAvailableDevicesTask();
}
}
else
{
if ((bool)isThisDeviceMining && !(bool)isAnyOtherDeviceMining) //todo check if this device not mining by now
{
MiningState.Instance.MiningStoppedByToggle = true;
}
}
}

// await tasks
await Task.WhenAll(tasks);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NHM.Common;
using NHM.Common.Configs;
using NHM.Common.Enums;
using NHMCore.ApplicationState;
using NHMCore.Mining;
using System;
using System.Collections.Generic;
Expand All @@ -17,6 +18,7 @@ static partial class ApplicationStateManager
// TODO add check for any enabled algorithms
public static async Task<(bool started, string failReason)> StartAllAvailableDevicesTask()
{
MiningState.Instance.MiningStoppedByToggle = false;
// TODO consider trying to start the error state devices as well
var devicesToStart = AvailableDevices.Devices.Where(dev => dev.State == DeviceState.Stopped);
if (devicesToStart.Count() == 0)
Expand Down

0 comments on commit 43122a9

Please sign in to comment.