Skip to content

Commit

Permalink
Fix #449
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Dec 15, 2022
1 parent 6856657 commit 5e64903
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion LenovoLegionToolkit.Lib/Controllers/GodModeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public async Task ApplyStateAsync()

try
{
await SetFanTable(fanTable.Value).ConfigureAwait(false);
var table = fanTable.Value.IsValid() ? fanTable.Value : GetDefaultFanTable();
await SetFanTable(table).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -257,6 +258,8 @@ public async Task ApplyStateAsync()
return null;

var fanTable = _settings.Store.FanTable ?? GetDefaultFanTable();
if (!fanTable.IsValid())
fanTable = GetDefaultFanTable();
return new FanTableInfo(fanTableData, fanTable);
}

Expand Down
34 changes: 21 additions & 13 deletions LenovoLegionToolkit.Lib/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,25 @@ public readonly struct FanTableData

public readonly struct FanTable
{
private byte FSTM { get; }
private byte FSID { get; }
private uint FSTL { get; }
private ushort FSS0 { get; }
private ushort FSS1 { get; }
private ushort FSS2 { get; }
private ushort FSS3 { get; }
private ushort FSS4 { get; }
private ushort FSS5 { get; }
private ushort FSS6 { get; }
private ushort FSS7 { get; }
private ushort FSS8 { get; }
private ushort FSS9 { get; }
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable MemberCanBePrivate.Global

public byte FSTM { get; init; }
public byte FSID { get; init; }
public uint FSTL { get; init; }
public ushort FSS0 { get; init; }
public ushort FSS1 { get; init; }
public ushort FSS2 { get; init; }
public ushort FSS3 { get; init; }
public ushort FSS4 { get; init; }
public ushort FSS5 { get; init; }
public ushort FSS6 { get; init; }
public ushort FSS7 { get; init; }
public ushort FSS8 { get; init; }
public ushort FSS9 { get; init; }

// ReSharper restore AutoPropertyCanBeMadeGetOnly.Global
// ReSharper restore MemberCanBePrivate.Global

public FanTable(ushort[] fanTable)
{
Expand All @@ -127,6 +133,8 @@ public FanTable(ushort[] fanTable)

public ushort[] GetTable() => new[] { FSS0, FSS1, FSS2, FSS3, FSS4, FSS5, FSS6, FSS7, FSS8, FSS9 };

public bool IsValid() => GetTable().All(t => t > 0);

public byte[] GetBytes()
{
using var ms = new MemoryStream(new byte[64]);
Expand Down

0 comments on commit 5e64903

Please sign in to comment.