using Aurora; using Aurora.View; using System; using System.Collections.Generic; using System.Linq; 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); } } 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 _lsChannel; public List lsChannel { get => _lsChannel; set => SetProperty(ref _lsChannel, value); } private int _cbChannel; //public int cbChannel { get => _cbChannel; set => SetProperty(ref _cbChannel, value); } public int cbChannel { get => _cbChannel; set { _cbChannel = value; if (buttonOnOffToggle[_cbChannel]) strButtonOnOff = "ON"; else strButtonOnOff = "OFF"; } } #endregion int nChannelMax; #region EventCommands public ICommand CMD_LightOnOff { get; } public ICommand CMD_ALLLightOn { get; } public ICommand CMD_ALLLightOff { get; } #endregion private LightDevice _LightDevice; public UCLightViewModel(IAuroraEnvironment aurora, string deviceId, int LightVal) { _LightDevice = aurora.DeviceManager[deviceId] as LightDevice; #region Initialize Binding Properties // config 에서 읽어와서 update 해야한다. device 등록할 때 config 만든 config 를 받아올 것. 임시로 고정값 입력 nSliderMax = 100; nSliderValue = 0; if (_LightDevice != null && _LightDevice._lightType == eLight.ERI) { // 안타깝게도 채널수나 config 는 추상화항목에 없다. 추후에 업데이트하겠음. 일단은 type convert 해서 가져옴 // activate 된 후에나 class 생성이 된다. 클래스에서 property 를 가져올수없음 //var lightdevice = _LightDevice as ERILight; //nChannel = lightdevice.GetChannelCount(); nChannel = 4; nSliderMax = 255; nSliderValue = LightVal; } else nChannel = 8; if (lsChannel != null) lsChannel.Clear(); else lsChannel = new List(); nChannelMax = nChannel; // default setting for (int i = 0; i < nChannelMax; i++) lsChannel.Add(i); buttonOnOffToggle = new bool[nChannel]; for (int channel = 0; channel < nChannelMax; channel++) { buttonOnOffToggle[channel] = false; if (_LightDevice != null && _LightDevice._light != null) { _LightDevice._light.SetLightValueInternal(channel, nSliderValue); } } strButtonOnOff = "OFF"; #endregion #region DelegateCommands CMD_LightOnOff = new DelegateCommand(LightOnOff); CMD_ALLLightOn = new DelegateCommand(ALLLightOn); CMD_ALLLightOff = new DelegateCommand(ALLLightOff); #endregion } private void LightOnOff(object obj) { if (_LightDevice != null && _LightDevice._light != null) { if (buttonOnOffToggle[cbChannel] == true) { // light on , button text on -> off toggle _LightDevice._light.SetLightValueInternal(cbChannel, nSliderValue); buttonOnOffToggle[cbChannel] = false; strButtonOnOff = "OFF"; } else { // light off , button text off -> on toggle _LightDevice._light.OffLightInternal(cbChannel); buttonOnOffToggle[cbChannel] = true; strButtonOnOff = "ON"; } } } private void ALLLightOn(object obj) { if (_LightDevice != null && _LightDevice._light != null) { for (int channel = 0; channel < nChannelMax; channel++) { _LightDevice._light.SetLightValueInternal(channel, nSliderValue); buttonOnOffToggle[channel] = false; strButtonOnOff = "OFF"; } } } private void ALLLightOff(object obj) { if (_LightDevice != null && _LightDevice._light != null) { for (int channel = 0; channel < nChannelMax; channel++) { _LightDevice._light.OffLightInternal(channel); buttonOnOffToggle[channel] = 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; } } }