2026-01-26 14:51:28 +09:00

477 lines
15 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.View;
using Hermes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace AuroraLight.View
{
public class KsLightModel : NotifyPropertyChangedBase
{
#region Binding Properties
private bool _IsActive1;
public bool IsActive1
{
get { return _IsActive1; }
set
{
SetProperty(ref _IsActive1, value);
if (_IsActive1)
{
_IsActiveiconsC1 = Visibility.Visible;
_IsActiveiconsD1 = Visibility.Hidden;
}
else
{
_IsActiveiconsC1 = Visibility.Hidden;
_IsActiveiconsD1 = Visibility.Visible;
}
}
}
private Visibility _IsActiveiconsC1 = Visibility.Hidden;
public Visibility IsActiveiconsC1
{
get { return _IsActiveiconsC1; }
set
{
SetProperty(ref _IsActiveiconsC1, value);
}
}
private Visibility _IsActiveiconsD1 = Visibility.Hidden;
public Visibility IsActiveiconsD1
{
get { return _IsActiveiconsD1; }
set
{
SetProperty(ref _IsActiveiconsD1, value);
}
}
private string _SliderName1;
public string SliderName1
{
get => _SliderName1;
set
{
SetProperty(ref _SliderName1, value);
}
}
private bool _IsActive2;
public bool IsActive2
{
get { return _IsActive2; }
set
{
SetProperty(ref _IsActive2, value);
if (_IsActive2)
{
_IsActiveiconsC2 = Visibility.Visible;
_IsActiveiconsD2 = Visibility.Hidden;
}
else
{
_IsActiveiconsC2 = Visibility.Hidden;
_IsActiveiconsD2 = Visibility.Visible;
}
}
}
private bool _IsActiveALL;
public bool IsActiveALL
{
get { return _IsActiveALL; }
set { SetProperty(ref _IsActiveALL, value); }
}
private Visibility _IsActiveiconsC2 = Visibility.Hidden;
public Visibility IsActiveiconsC2
{
get { return _IsActiveiconsC2; }
set
{
SetProperty(ref _IsActiveiconsC2, value);
}
}
private Visibility _IsActiveiconsD2 = Visibility.Hidden;
public Visibility IsActiveiconsD2
{
get { return _IsActiveiconsD2; }
set
{
SetProperty(ref _IsActiveiconsD2, value);
}
}
private string _SliderName2;
public string SliderName2
{
get => _SliderName2;
set
{
SetProperty(ref _SliderName2, value);
}
}
private int _nSliderValue1;
public int nSliderValue1
{
get => _nSliderValue1;
set
{
try
{
if (SetProperty(ref _nSliderValue1, value))
{
if (_LightDevice1 != null && _LightDevice1._light != null)
_LightDevice1._light.SetLightValueInternal(cbChannel1, value);
}
}
catch (Exception ex)
{
}
}
}
private int _nSliderValue2;
public int nSliderValue2
{
get => _nSliderValue2;
set
{
try
{
if (SetProperty(ref _nSliderValue2, value))
{
if (_LightDevice2 != null && _LightDevice2._light != null)
_LightDevice2._light.SetLightValueInternal(cbChannel2, 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 _buttonOnOffToggle1;
public bool buttonOnOffToggle1 { get => _buttonOnOffToggle1; set => SetProperty(ref _buttonOnOffToggle1, value); }
private bool _buttonOnOffToggle2;
public bool buttonOnOffToggle2 { get => _buttonOnOffToggle2; set => SetProperty(ref _buttonOnOffToggle2, value); }
private string _strButtonOnOff1;
public string strButtonOnOff1 { get => _strButtonOnOff1; set => SetProperty(ref _strButtonOnOff1, value); }
private string _strButtonOnOff2;
public string strButtonOnOff2 { get => _strButtonOnOff2; set => SetProperty(ref _strButtonOnOff2, value); }
private List<int> _lsChannel1;
public List<int> lsChannel1 { get => _lsChannel1; set => SetProperty(ref _lsChannel1, value); }
private List<int> _lsChannel2;
public List<int> lsChannel2 { get => _lsChannel2; set => SetProperty(ref _lsChannel2, value); }
private int _cbChannel1;
public int cbChannel1 { get => _cbChannel1; set => SetProperty(ref _cbChannel1, value); }
private int _cbChannel2;
public int cbChannel2 { get => _cbChannel2; set => SetProperty(ref _cbChannel2, value); }
private bool _buttonOnOffToggleALL;
public bool buttonOnOffToggleALL { get => _buttonOnOffToggleALL; set => SetProperty(ref _buttonOnOffToggleALL, value); }
private int _nSliderValueALL;
public int nSliderValueALL
{
get => _nSliderValueALL;
set
{
try
{
if (SetProperty(ref _nSliderValueALL, value))
{
if (_LightDevice1 != null && _LightDevice1._light != null)
{
_LightDevice1._light.SetLightValueInternal(cbChannelALL, value);
}
if (_LightDevice2 != null && _LightDevice2._light != null)
{
_LightDevice2._light.SetLightValueInternal(cbChannelALL, value);
}
nSliderValue1 = value;
nSliderValue2 = value;
}
}
catch (Exception ex)
{
}
}
}
private List<int> _lsChannelALL;
public List<int> lsChannelALL { get => _lsChannelALL;
set
{
SetProperty(ref _lsChannelALL, value);
}
}
private int _cbChannelALL;
public int cbChannelALL { get => _cbChannelALL;
set
{
SetProperty(ref _cbChannelALL, value);
cbChannel1 = value;
cbChannel2 = value;
}
}
private string _strButtonOnOffALL;
public string strButtonOnOffALL { get => _strButtonOnOffALL; set => SetProperty(ref _strButtonOnOffALL, value); }
#endregion
#region EventCommands
public ICommand CMD_LightOnOff1 { get; }
public ICommand CMD_LightOnOff2 { get; }
public ICommand CMD_LightOnOffALL { get; }
public ICommand CMD_Reload { get; }
public ICommand CMD_GetStat { get; }
#endregion
private LightDevice _LightDevice1;
private LightDevice _LightDevice2;
public KsLightModel()
{
}
public KsLightModel(IAuroraEnvironment aurora, string deviceId1, string deviceId2)
{
_LightDevice1 = aurora.DeviceManager[deviceId1] as LightDevice;
_LightDevice2 = aurora.DeviceManager[deviceId2] as LightDevice;
IsActive1 = true;
IsActive2 = true;
IsActiveALL = true;
SliderName1 = _LightDevice1.DeviceId;
SliderName2 = _LightDevice2.DeviceId;
#region Initialize Binding Properties
// config 에서 읽어와서 update 해야한다. device 등록할 때 config 만든 config 를 받아올 것. 임시로 고정값 입력
nSliderMax = 100;
nSliderValue1 = 0;
nSliderValue2 = 0;
nSliderValueALL = 0;
if ((_LightDevice1 != null && _LightDevice1._lightType == eLight.ERI) && (_LightDevice2 != null && _LightDevice2._lightType == eLight.ERI))
{
// 안타깝게도 채널수나 config 는 추상화항목에 없다. 추후에 업데이트하겠음. 일단은 type convert 해서 가져옴
// activate 된 후에나 class 생성이 된다. 클래스에서 property 를 가져올수없음
//var lightdevice = _LightDevice as ERILight;
//nChannel = lightdevice.GetChannelCount();
nChannel = 4;
nSliderMax = 255;
nSliderValue1 = 200;
nSliderValue2 = 200;
nSliderValueALL = 200;
}
else nChannel = 8;
if (lsChannel1 != null)
lsChannel1.Clear();
else lsChannel1 = new List<int>();
int nChannelMax1 = nChannel; // default setting
for (int i = 0; i < nChannelMax1; i++) lsChannel1.Add(i);
if (lsChannel2 != null)
lsChannel2.Clear();
else lsChannel2 = new List<int>();
int nChannelMax2 = nChannel; // default setting
for (int i = 0; i < nChannelMax2; i++) lsChannel2.Add(i);
buttonOnOffToggle1 = true;
strButtonOnOff1 = "ON";
buttonOnOffToggle2 = true;
strButtonOnOff2 = "ON";
lsChannelALL = new List<int>();
int nChannelMaxALL = nChannel; // default setting
for (int i = 0; i < nChannelMaxALL; i++) lsChannelALL.Add(i);
strButtonOnOffALL = "ON";
#endregion
#region DelegateCommands
CMD_LightOnOff1 = new DelegateCommand(LightOnOff1);
CMD_LightOnOff2 = new DelegateCommand(LightOnOff2);
CMD_LightOnOffALL = new DelegateCommand(LightOnOffALL);
CMD_Reload = new DelegateCommand(ReLoad);
CMD_GetStat = new DelegateCommand(GetStat);
#endregion
}
private void GetStat(object obj)
{
MessageUtil.ShowErrorToast($"Unexpected Error : Duplicated Header : {IsActive1}");
}
private void ReLoad(object obj)
{
if (_LightDevice1.IsActivated)
{
IsActive1 = true;
}
else
{
IsActive1 = false;
}
if (_LightDevice2.IsActivated)
{
IsActive2 = true;
}
else
{
IsActive2 = false;
}
if(IsActive1 && IsActive2)
{
IsActiveALL = true;
}
else
{
IsActiveALL = false;
}
}
private void LightOnOff1(object obj)
{
if (_LightDevice1 != null && _LightDevice1._light != null)
{
if (_buttonOnOffToggle1 == true)
{
// light on , button text on -> off toggle
_LightDevice1._light.SetLightValueInternal(cbChannel1, nSliderValue1);
_buttonOnOffToggle1 = false;
strButtonOnOff1 = "OFF";
}
else
{
// light off , button text off -> on toggle
_LightDevice1._light.OffLightInternal(cbChannel1);
_buttonOnOffToggle1 = true;
strButtonOnOff1 = "ON";
}
}
}
private void LightOnOff2(object obj)
{
if (_LightDevice2 != null && _LightDevice2._light != null)
{
if (_buttonOnOffToggle2 == true)
{
// light on , button text on -> off toggle
_LightDevice2._light.SetLightValueInternal(cbChannel2, nSliderValue2);
buttonOnOffToggle2 = false;
strButtonOnOff2 = "OFF";
}
else
{
// light off , button text off -> on toggle
_LightDevice2._light.OffLightInternal(cbChannel2);
buttonOnOffToggle2 = true;
strButtonOnOff2 = "ON";
}
}
}
private void LightOnOffALL(object obj)
{
if (_LightDevice1.IsActivated && _LightDevice2.IsActivated)
{
if (_buttonOnOffToggleALL == true)
{
_LightDevice1._light.SetLightValueInternal(cbChannel1, nSliderValue1);
_LightDevice2._light.SetLightValueInternal(cbChannel2, nSliderValue2);
buttonOnOffToggle1 = false;
buttonOnOffToggle2 = false;
buttonOnOffToggleALL = false;
strButtonOnOff1 = "OFF";
strButtonOnOff2 = "OFF";
strButtonOnOffALL = "OFF";
}
else
{
_LightDevice1._light.OffLightInternal(cbChannel1);
_LightDevice2._light.OffLightInternal(cbChannel2);
buttonOnOffToggle1 = true;
buttonOnOffToggle2 = true;
buttonOnOffToggleALL = true;
strButtonOnOff1 = "ON";
strButtonOnOff2 = "ON";
strButtonOnOffALL = "ON";
}
}
else
{
MessageUtil.ShowErrorToast($"Deivce Light Not Active: Device 1[{_LightDevice1.IsActivated}] / Device 2[{_LightDevice2.IsActivated}]");
}
}
//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;
//}
}
}