Skip to content

Commit d004df4

Browse files
committed
Fix PortConfig and SensorConfig resetting to default
1 parent 175cb49 commit d004df4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Source/TTController.Service/Manager/SensorManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public sealed class SensorManager : IDataProvider, IDisposable
2121
private readonly Dictionary<Identifier, ISensorValueProvider> _sensorValueProviders;
2222
private readonly HashSet<IHardware> _hardware;
2323

24+
private bool _cacheInitialized;
25+
2426
public IEnumerable<Identifier> EnabledSensors => _sensorValueProviders.Keys;
2527

2628
public SensorManager(ISensorValueProviderFactory sensorValueProviderFactory, IReadOnlyDictionary<Identifier, SensorConfig> sensorConfigs)
@@ -33,6 +35,8 @@ public SensorManager(ISensorValueProviderFactory sensorValueProviderFactory, IRe
3335
_sensorValueProviders = new Dictionary<Identifier, ISensorValueProvider>();
3436
_hardware = new HashSet<IHardware>();
3537

38+
_cacheInitialized = false;
39+
3640
EnableSensors(sensorConfigs.Keys);
3741
}
3842

@@ -112,6 +116,13 @@ public void DisableSensors(IEnumerable<Identifier> identifiers)
112116

113117
public void Accept(ICacheCollector collector)
114118
{
119+
if (!_cacheInitialized)
120+
{
121+
_cacheInitialized = true;
122+
foreach (var sensor in EnabledSensors)
123+
collector.StoreSensorConfig(sensor, SensorConfig.Default);
124+
}
125+
115126
foreach (var (sensor, provider) in _sensorValueProviders)
116127
collector.StoreSensorValue(sensor, provider.Value());
117128
}

Source/TTController.Service/TTService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public bool Initialize()
5252
return false;
5353

5454
_cache = new DataCache();
55-
_configManager.Accept(_cache.AsWriteOnly());
5655

5756
var alpha = Math.Exp(-_configManager.CurrentConfig.SensorTimerInterval / (double)_configManager.CurrentConfig.DeviceSpeedTimerInterval);
5857
var providerFactory = new MovingAverageSensorValueProviderFactory(alpha);
@@ -61,7 +60,6 @@ public bool Initialize()
6160
_effectManager = new EffectManager();
6261
_speedControllerManager = new SpeedControllerManager();
6362
_deviceManager = new DeviceManager();
64-
_deviceManager.Accept(_cache.AsWriteOnly());
6563

6664
foreach (var profile in _configManager.CurrentConfig.Profiles)
6765
{
@@ -75,6 +73,10 @@ public bool Initialize()
7573
_sensorManager.EnableSensors(_effectManager.GetEffects(profile.Guid)?.SelectMany(e => e.UsedSensors));
7674
}
7775

76+
_sensorManager.Accept(_cache.AsWriteOnly());
77+
_deviceManager.Accept(_cache.AsWriteOnly());
78+
_configManager.Accept(_cache.AsWriteOnly());
79+
7880
ApplyComputerStateProfile(ComputerStateType.Boot);
7981

8082
_timerManager = new TimerManager();

0 commit comments

Comments
 (0)