更新
This commit is contained in:
@@ -2,18 +2,16 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows.Threading;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ConeCalorimeter.Models;
|
||||
using ConeCalorimeter.Services;
|
||||
|
||||
namespace ConeCalorimeter.ViewModels;
|
||||
|
||||
public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||
{
|
||||
private const ushort CurrentTemperatureRegister = 26;
|
||||
private const ushort CurrentHeatFluxRegister = 32;
|
||||
private const ushort TargetTemperatureRegister = 400;
|
||||
private const ushort CurrentHeatFluxRegister = 410;
|
||||
private const ushort HeatTransferRegister = 418;
|
||||
private const double CurrentTemperatureMinimum = 0;
|
||||
private const double CurrentTemperatureMaximum = 1200;
|
||||
private const double CurrentHeatFluxMinimum = 0;
|
||||
private const double CurrentHeatFluxMaximum = 1000;
|
||||
private const double HeatTransferInputMinimum = 0;
|
||||
@@ -27,6 +25,7 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||
|
||||
private readonly Action _closeAction;
|
||||
private readonly Action _helpAction;
|
||||
private readonly IExperimentDataService _experimentDataService;
|
||||
private readonly ITcpDeviceConnectionService _tcpDeviceConnectionService;
|
||||
private readonly DispatcherTimer _refreshTimer;
|
||||
private readonly HashSet<ushort> _loggedFloatDiagnostics = [];
|
||||
@@ -45,16 +44,20 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||
public ConeRadiationSettingsViewModel(
|
||||
Action closeAction,
|
||||
Action helpAction,
|
||||
IExperimentDataService experimentDataService,
|
||||
ITcpDeviceConnectionService tcpDeviceConnectionService) : base("辐射锥设置")
|
||||
{
|
||||
_closeAction = closeAction;
|
||||
_helpAction = helpAction;
|
||||
_experimentDataService = experimentDataService;
|
||||
_tcpDeviceConnectionService = tcpDeviceConnectionService;
|
||||
CloseCommand = new RelayCommand(_closeAction);
|
||||
HelpCommand = new RelayCommand(_helpAction);
|
||||
ActionCommand = new RelayCommand<string>(ExecuteAction);
|
||||
SaveParametersCommand = new RelayCommand(SaveParameters);
|
||||
|
||||
UpdateCurrentReadings(_experimentDataService.CurrentSnapshot);
|
||||
_experimentDataService.SnapshotUpdated += (_, snapshot) => UpdateCurrentReadings(snapshot);
|
||||
RefreshDeviceValues();
|
||||
_refreshTimer = new DispatcherTimer
|
||||
{
|
||||
@@ -177,24 +180,17 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||
|
||||
private void RefreshDeviceValues()
|
||||
{
|
||||
CurrentTemperatureText = TryReadRangedFloatText(
|
||||
"ConeCurrentTemperature",
|
||||
CurrentTemperatureRegister,
|
||||
CurrentTemperatureMinimum,
|
||||
CurrentTemperatureMaximum,
|
||||
"0.0",
|
||||
out var currentTemperatureText)
|
||||
? currentTemperatureText
|
||||
: string.Empty;
|
||||
CurrentHeatFluxText = TryReadRangedFloatText(
|
||||
if (TryReadRangedFloatText(
|
||||
"ConeCurrentHeatFlux",
|
||||
CurrentHeatFluxRegister,
|
||||
CurrentHeatFluxMinimum,
|
||||
CurrentHeatFluxMaximum,
|
||||
"0.00",
|
||||
out var currentHeatFluxText)
|
||||
? currentHeatFluxText
|
||||
: string.Empty;
|
||||
out var currentHeatFluxText))
|
||||
{
|
||||
CurrentHeatFluxText = currentHeatFluxText;
|
||||
}
|
||||
|
||||
if (CanRefreshConeParameters())
|
||||
{
|
||||
TargetTemperatureText = ReadInt16Text(TargetTemperatureRegister);
|
||||
@@ -218,6 +214,24 @@ public sealed class ConeRadiationSettingsViewModel : PageViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCurrentReadings(RealtimeSnapshot snapshot)
|
||||
{
|
||||
if (double.IsFinite(snapshot.ConeTemperature))
|
||||
{
|
||||
CurrentTemperatureText = NormalizeDisplayValue(snapshot.ConeTemperature)
|
||||
.ToString("0.0", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
if (double.IsFinite(snapshot.Irradiance))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(CurrentHeatFluxText))
|
||||
{
|
||||
CurrentHeatFluxText = NormalizeDisplayValue(snapshot.Irradiance)
|
||||
.ToString("0.00", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryReadRangedFloatText(
|
||||
string label,
|
||||
ushort registerAddress,
|
||||
|
||||
@@ -40,6 +40,7 @@ public sealed class MainViewModel : ObservableObject
|
||||
new ConeRadiationSettingsViewModel(
|
||||
() => SelectPage(testItem),
|
||||
ShowConeRadiationHelp,
|
||||
experimentDataService,
|
||||
tcpDeviceConnectionService));
|
||||
var smokeDensityItem = new NavigationItemViewModel(
|
||||
"烟密度设置",
|
||||
|
||||
Reference in New Issue
Block a user