diff --git a/AuroraDevices/AuroraLight/LightConfig.cs b/AuroraDevices/AuroraLight/LightConfig.cs index 65d51b9..efe3ea0 100644 --- a/AuroraDevices/AuroraLight/LightConfig.cs +++ b/AuroraDevices/AuroraLight/LightConfig.cs @@ -1,9 +1,9 @@ -using Aurora.Api; +using Aurora.Api; using Aurora.Api.DataType; using Aurora.Api.Devices; +using PropertyTools.DataAnnotations; using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO.Ports; using System.Linq; using System.Text; @@ -14,6 +14,50 @@ namespace AuroraLight public class LightConfig : IDeviceConfig { public IConnConfig ConnConfig { get; set; } + + [Category("Light Level")] + [DisplayName("Channel 1 Level (0~255)")] + [Description("Channel 1 Brightness")] + public int Ch1Level { get; set; } = 200; + + [Category("Light Level")] + [DisplayName("Channel 2 Level (0~255)")] + [Description("Channel 2 Brightness")] + public int Ch2Level { get; set; } = 200; + + [Category("Light Level")] + [DisplayName("Channel 3 Level (0~255)")] + [Description("Channel 3 Brightness")] + public int Ch3Level { get; set; } = 200; + + [Category("Light Level")] + [DisplayName("Channel 4 Level (0~255)")] + [Description("Channel 4 Brightness")] + public int Ch4Level { get; set; } = 200; + + public int GetChannelLevel(int channel) + { + switch (channel) + { + case 0: return Ch1Level; + case 1: return Ch2Level; + case 2: return Ch3Level; + case 3: return Ch4Level; + default: return Ch1Level; + } + } + + public void SetChannelLevel(int channel, int value) + { + switch (channel) + { + case 0: Ch1Level = value; break; + case 1: Ch2Level = value; break; + case 2: Ch3Level = value; break; + case 3: Ch4Level = value; break; + } + } + public LightConfig() { ConnConfig = new SerialConnConfig() { @@ -24,6 +68,10 @@ namespace AuroraLight DataBits = 8, ReadTimeout = 500 }; + Ch1Level = 200; + Ch2Level = 200; + Ch3Level = 200; + Ch4Level = 200; } public static LightConfig GetDefaultConfig() @@ -37,6 +85,10 @@ namespace AuroraLight DataBits = 8, ReadTimeout = 500 }; + config.Ch1Level = 200; + config.Ch2Level = 200; + config.Ch3Level = 200; + config.Ch4Level = 200; return config; } diff --git a/AuroraDevices/AuroraLight/LightDevice.cs b/AuroraDevices/AuroraLight/LightDevice.cs index dcfe5ca..dc34d33 100644 --- a/AuroraDevices/AuroraLight/LightDevice.cs +++ b/AuroraDevices/AuroraLight/LightDevice.cs @@ -1,4 +1,4 @@ -using Aurora.Api; +using Aurora.Api; using Aurora.Api.DataType; using Aurora.Api.Devices; using AuroraLight.ALT; @@ -25,6 +25,7 @@ namespace AuroraLight Logger Log; internal eLight _lightType; internal ILight _light; + public LightConfig Config { get; private set; } public LightDevice(string deviceId, eLight light) { @@ -38,6 +39,7 @@ namespace AuroraLight protected override int DoActivate(IDeviceConfig config) { var l_config = config as LightConfig; + Config = l_config; if (IsSimul) { return E1.OK; @@ -57,7 +59,15 @@ namespace AuroraLight break; } - return _light.InitInternal(config.ConnConfig as SerialConnConfig) ? E1.OK : E2.NOT_CONNECTED; + bool connected = _light.InitInternal(config.ConnConfig as SerialConnConfig); + if (connected && l_config != null) { + int chCount = _lightType == eLight.ALT_8CH ? 8 : 4; + for (int i = 0; i < chCount; i++) { + _light.SetLightValueInternal(i, l_config.GetChannelLevel(i)); + } + } + + return connected ? E1.OK : E2.NOT_CONNECTED; } } diff --git a/AuroraDevices/AuroraLight/View/KsLight.xaml b/AuroraDevices/AuroraLight/View/KsLight.xaml index 95341a4..adb6657 100644 --- a/AuroraDevices/AuroraLight/View/KsLight.xaml +++ b/AuroraDevices/AuroraLight/View/KsLight.xaml @@ -1,4 +1,4 @@ - - -