using Aurora; using Aurora.Api; using Aurora.View; using AuroraLaser.Coherent; using System; using System.Windows.Input; using System.Windows.Threading; namespace AuroraLaser.Views { public class UCLaserCompactControlViewModel : NotifyPropertyChangedBase { private Logger Log = new Logger("Laser Compact Control VM"); private LaserCompact _laser; public ICommand CMD_VisibleChanged { get; } public ICommand CMD_LaserPowerSet { get; } public ICommand CMD_LaserPowerWattSet { get; } // 해당 뷰 enable 상태 private bool _isUCViewEnabled = true; public bool IsUCViewEnabled { get => _isUCViewEnabled; set => SetProperty(ref _isUCViewEnabled, value); } private double _laserTargetPower; public double LaserTargetPower { get => _laserTargetPower; set => SetProperty(ref _laserTargetPower, value); } private double _laserTargetPowerWatt; public double LaserTargetPowerWatt { get => _laserTargetPowerWatt; set => SetProperty(ref _laserTargetPowerWatt, value); } private double _laserActualPower; public double LaserActualPower { get => _laserActualPower; set => SetProperty(ref _laserActualPower, value); } private readonly DispatcherTimer MonitorTimer; public UCLaserCompactControlViewModel(IAuroraEnvironment aurora, string deviceId) { _laser = aurora.DeviceManager.GetDevice(deviceId) as LaserCompact; CMD_VisibleChanged = new DelegateCommand(VisibleChanged); CMD_LaserPowerSet = new DelegateCommand(LaserPowerSet); CMD_LaserPowerWattSet = new DelegateCommand(LaserPowerWattSet); IsUCViewEnabled = true; MonitorTimer = new DispatcherTimer(); MonitorTimer.Tick += OnMonitoring; MonitorTimer.Interval = TimeSpan.FromMilliseconds(100); // 10 [Hz] } private void VisibleChanged(object obj) // 화면 전환 시 동작하는 곳 { bool visible = (bool)obj; if (visible) { MonitorTimer.Start(); } else { MonitorTimer.Stop(); } } private void OnMonitoring(object sender, EventArgs e) { if (!_laser.IsActivated) { return; } var _laserStatus = _laser.GetLaserStatusInfo(); LaserActualPower = _laserStatus.PowerValue * 0.1; } private void LaserPowerWattSet(object obj) { LaserTargetPower = _laser.Watt2Power(LaserTargetPowerWatt); _laser.SetOutputPower(LaserTargetPower); Log.I($"[{_laser.DeviceId}] : [{LaserTargetPowerWatt:f1} [W] ({LaserTargetPower:f1} [%])]"); } private void LaserPowerSet(object obj) { _laser.SetOutputPower(LaserTargetPower); Log.I($"LASER {_laser.DeviceId} SET [{LaserTargetPower:f1}%]"); } } }