113 lines
4.2 KiB
C#
113 lines
4.2 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);
|
|
}
|
|
} 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 => SetProperty(ref _cbChannel, value); }
|
|
#endregion
|
|
|
|
#region EventCommands
|
|
public ICommand CMD_LightOnOff { get; }
|
|
#endregion
|
|
|
|
private LightDevice _LightDevice;
|
|
|
|
public UCLightViewModel(IAuroraEnvironment aurora, string deviceId)
|
|
{
|
|
_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 = 180;
|
|
} 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);
|
|
|
|
buttonOnOffToggle = true;
|
|
strButtonOnOff = "ON";
|
|
|
|
#endregion
|
|
|
|
#region DelegateCommands
|
|
CMD_LightOnOff = new DelegateCommand(LightOnOff);
|
|
|
|
#endregion
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|