- 오토런 시작 시 RCC 패턴 폴더 변경 감지 → B2506 ON, PLC ACK(B2409) 수신 시 OFF - 서브 패턴 1~10, 패턴 목록에 서브 썸네일 표시(행 내 좌우 스크롤) - 서브 패턴 등록 직후 활성화 OFF - 패턴 파일이 다른 프로그램에서 열려 있으면 삭제하지 않고 안내 - 현장 소스 반영: Train ROI 슬라이더, KS 조명 밝기 저장/적용, 조명 ID 분리, 스캔 후 카메라 라이브 재시작, 레시피 21 RCC NG 우회, 오토런 상태 판단
157 lines
5.7 KiB
C#
157 lines
5.7 KiB
C#
using Aurora;
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Input;
|
|
|
|
namespace AuroraLight.View
|
|
{
|
|
public class UCLightViewModel : NotifyPropertyChangedBase
|
|
{
|
|
#region Binding Properties
|
|
private int _nSliderValue;
|
|
public int nSliderValue {
|
|
get => _nSliderValue;
|
|
set {
|
|
try {
|
|
if (SetProperty(ref _nSliderValue, value)) {
|
|
if (_LightDevice != null && _LightDevice._light != null)
|
|
_LightDevice._light.SetLightValueInternal(cbChannel, value);
|
|
|
|
var config = _aurora?.DeviceManager?.GetDeviceConfig(_deviceId) as LightConfig;
|
|
if (config != null)
|
|
{
|
|
config.SetChannelLevel(cbChannel, value);
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
}
|
|
|
|
}
|
|
}
|
|
private int _nSliderMax;
|
|
public int nSliderMax { get => _nSliderMax; set => SetProperty(ref _nSliderMax, value); }
|
|
private int _nChannel;
|
|
public int nChannel { get => _nChannel; set => SetProperty(ref _nChannel, value); }
|
|
private bool _buttonOnOffToggle;
|
|
public bool buttonOnOffToggle { get => _buttonOnOffToggle; set => SetProperty(ref _buttonOnOffToggle, value); }
|
|
private string _strButtonOnOff;
|
|
public string strButtonOnOff { get => _strButtonOnOff; set => SetProperty(ref _strButtonOnOff, value); }
|
|
private List<int> _lsChannel;
|
|
public List<int> lsChannel { get => _lsChannel; set => SetProperty(ref _lsChannel, value); }
|
|
private int _cbChannel;
|
|
public int cbChannel {
|
|
get => _cbChannel;
|
|
set {
|
|
if (SetProperty(ref _cbChannel, value)) {
|
|
var config = _aurora?.DeviceManager?.GetDeviceConfig(_deviceId) as LightConfig;
|
|
if (config != null) {
|
|
int chLevel = config.GetChannelLevel(value);
|
|
if (_nSliderValue != chLevel) {
|
|
_nSliderValue = chLevel;
|
|
NotifyPropertyChanged(nameof(nSliderValue));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region EventCommands
|
|
public ICommand CMD_LightOnOff { get; }
|
|
public ICommand CMD_Save { get; }
|
|
#endregion
|
|
|
|
private IAuroraEnvironment _aurora;
|
|
private string _deviceId;
|
|
private LightDevice _LightDevice;
|
|
|
|
public UCLightViewModel(IAuroraEnvironment aurora, string deviceId)
|
|
{
|
|
_aurora = aurora;
|
|
_deviceId = deviceId;
|
|
_LightDevice = aurora.DeviceManager[deviceId] as LightDevice;
|
|
|
|
#region Initialize Binding Properties
|
|
nSliderMax = 100;
|
|
_nSliderValue = 0;
|
|
|
|
if (_LightDevice != null && _LightDevice._lightType == eLight.ERI) {
|
|
nChannel = 4;
|
|
nSliderMax = 255;
|
|
} else nChannel = 8;
|
|
|
|
if (lsChannel != null)
|
|
lsChannel.Clear();
|
|
else lsChannel = new List<int>();
|
|
int nChannelMax = nChannel; // default setting
|
|
for (int i = 0; i < nChannelMax; i++)
|
|
lsChannel.Add(i);
|
|
|
|
var config = _aurora?.DeviceManager?.GetDeviceConfig(_deviceId) as LightConfig;
|
|
_nSliderValue = config != null ? config.GetChannelLevel(cbChannel) : 200;
|
|
NotifyPropertyChanged(nameof(nSliderValue));
|
|
|
|
if (_LightDevice != null && _LightDevice._light != null) {
|
|
_LightDevice._light.SetLightValueInternal(cbChannel, _nSliderValue);
|
|
}
|
|
|
|
buttonOnOffToggle = false;
|
|
strButtonOnOff = "OFF";
|
|
|
|
#endregion
|
|
|
|
#region DelegateCommands
|
|
CMD_LightOnOff = new DelegateCommand(LightOnOff);
|
|
CMD_Save = new DelegateCommand(Save);
|
|
|
|
#endregion
|
|
}
|
|
|
|
private void Save(object obj)
|
|
{
|
|
try {
|
|
if (_aurora != null && _aurora.DeviceManager != null) {
|
|
var config = _aurora.DeviceManager.GetDeviceConfig(_deviceId) as LightConfig;
|
|
if (config != null) {
|
|
config.SetChannelLevel(cbChannel, nSliderValue);
|
|
_aurora.DeviceManager.SaveDeviceConfig(_deviceId);
|
|
}
|
|
MessageUtil.ShowSuccessToast("Light configuration saved.");
|
|
}
|
|
} catch (Exception ex) {
|
|
MessageUtil.ShowErrorToast($"Failed to save light config: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void LightOnOff(object obj)
|
|
{
|
|
if (_LightDevice != null && _LightDevice._light != null) {
|
|
if (buttonOnOffToggle == true) {
|
|
// light on , button text on -> off toggle
|
|
_LightDevice._light.SetLightValueInternal(cbChannel, nSliderValue);
|
|
|
|
buttonOnOffToggle = false;
|
|
strButtonOnOff = "OFF";
|
|
} else {
|
|
// light off , button text off -> on toggle
|
|
_LightDevice._light.OffLightInternal(cbChannel);
|
|
buttonOnOffToggle = true;
|
|
strButtonOnOff = "ON";
|
|
}
|
|
}
|
|
}
|
|
private void SetChannelMax(int nChannelMax)
|
|
{
|
|
lsChannel.Clear();
|
|
for (int i = 0; i < nChannelMax; i++)
|
|
lsChannel.Add(i);
|
|
}
|
|
private void SetLightDevice(ILight LightDevice)
|
|
{
|
|
_LightDevice._light = LightDevice;
|
|
}
|
|
|
|
}
|
|
}
|