Files
HC_APTBS/ViewModels/FlowmeterChartViewModel.cs
LucianoDev e343006f45 feat: restore bench section UI with controls, PID RPM ramp, flowmeter charts, and fix CAN IDs
Restore the full bench control panel from the old source with MVVM architecture:

- Two-column left panel layout: bench info displays (RPM with target/voltage,
  temps, pressures, Q-flow, pump live values) and user commands (direction
  toggle, start/stop with RPM popup and quick-select buttons, oil pump toggle,
  turn downcounter with CAN send)
- PID RPM ramp controller (BenchPidController) with bumpless startup,
  anti-windup, and derivative-on-measurement for smooth motor speed transitions
- Real-time flowmeter charts (LiveChartsCore) for Q-Delivery and Q-Over
  with tolerance band overlays
- Bench/pump CAN liveness detection in PcanAdapter (receive-only IDs)
- K-Line connection status indicator (placeholder)
- Periodic relay bitmask sender (~21ms) and ElectronicMsg keepalive start
  on CAN connect, pump sender starts immediately on pump load

Fix critical CAN message ID bug: default bench XML values were incorrectly
converted from old source (decimal-notation hex parsed as actual hex digits,
e.g. "10" -> "A" instead of keeping "10" which parses as 0x10). Corrected
all IDs to match hardware: 0x10, 0x11, 0x13, 0x14, 0x15, 0x50, 0x51, 0x55.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 14:24:59 +02:00

52 lines
1.7 KiB
C#

using HC_APTBS.Models;
using SkiaSharp;
namespace HC_APTBS.ViewModels
{
/// <summary>
/// Container ViewModel holding two real-time flowmeter charts:
/// one for Q-Delivery and one for Q-Over.
/// </summary>
public sealed class FlowmeterChartViewModel
{
/// <summary>Chart for the Q-Delivery flowmeter (amber line).</summary>
public SingleFlowChartViewModel Delivery { get; }
= new("Q-Delivery", new SKColor(0xFF, 0xAE, 0x00));
/// <summary>Chart for the Q-Over flowmeter (blue line).</summary>
public SingleFlowChartViewModel Over { get; }
= new("Q-Over", new SKColor(0x40, 0x80, 0xFF));
/// <summary>
/// Appends a sample pair to both charts.
/// Must be called on the UI thread.
/// </summary>
public void AddSamples(double qDelivery, double qOver)
{
Delivery.AddValue(qDelivery);
Over.AddValue(qOver);
}
/// <summary>
/// Sets the tolerance band on the appropriate chart.
/// </summary>
/// <param name="paramName">Parameter name (use <see cref="BenchParameterNames"/>).</param>
/// <param name="target">Center value.</param>
/// <param name="tolerance">Half-width.</param>
public void SetTolerance(string paramName, double target, double tolerance)
{
if (paramName == BenchParameterNames.QDelivery)
Delivery.SetTolerance(target, tolerance);
else if (paramName == BenchParameterNames.QOver)
Over.SetTolerance(target, tolerance);
}
/// <summary>Clears both charts.</summary>
public void Clear()
{
Delivery.Clear();
Over.Clear();
}
}
}