From 5e649039e5810d84cad70a3f1899532f192d8861 Mon Sep 17 00:00:00 2001 From: Bartosz Cichecki Date: Thu, 15 Dec 2022 21:51:36 +0100 Subject: [PATCH] Fix #449 --- .../Controllers/GodModeController.cs | 5 ++- LenovoLegionToolkit.Lib/Structs.cs | 34 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/LenovoLegionToolkit.Lib/Controllers/GodModeController.cs b/LenovoLegionToolkit.Lib/Controllers/GodModeController.cs index 875761bc53..afee2a6113 100644 --- a/LenovoLegionToolkit.Lib/Controllers/GodModeController.cs +++ b/LenovoLegionToolkit.Lib/Controllers/GodModeController.cs @@ -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) { @@ -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); } diff --git a/LenovoLegionToolkit.Lib/Structs.cs b/LenovoLegionToolkit.Lib/Structs.cs index 1eb950ce06..87b3870aa1 100644 --- a/LenovoLegionToolkit.Lib/Structs.cs +++ b/LenovoLegionToolkit.Lib/Structs.cs @@ -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) { @@ -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]);