LightControllerConfig.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Prism.Mvvm;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using TeamAAS_VP.Core.Lights;
  9. using TeamAAS_VP.Enums;
  10. namespace TeamAAS_VP.Models.Lights
  11. {
  12. public class LightControllerConfig: BindableBase
  13. {
  14. private int _Id;
  15. public int Id
  16. {
  17. get { return _Id; }
  18. set { SetProperty(ref _Id, value); }
  19. }
  20. private string _Name;
  21. public string Name
  22. {
  23. get { return _Name; }
  24. set { SetProperty(ref _Name, value); }
  25. }
  26. private int _ChannelCount;
  27. public int ChannelCount
  28. {
  29. get { return _ChannelCount; }
  30. set { SetProperty(ref _ChannelCount, value); }
  31. }
  32. private LightModel _LightModel;
  33. public LightModel LightModel
  34. {
  35. get { return _LightModel; }
  36. set {
  37. if (SetProperty(ref _LightModel, value))
  38. {
  39. switch (value)
  40. {
  41. case LightModel.KCS_KDC_12V60W_4T:
  42. ChannelCount = 4;
  43. TcpConfig = null;
  44. if (SerialPortConfig == null)
  45. {
  46. SerialPortConfig = new SerialPortConfig();
  47. }
  48. ChannelConfigs = new ObservableCollection<ChannelConfig>();
  49. if (ChannelConfigs.Count != ChannelCount)
  50. {
  51. ChannelConfigs.Clear();
  52. for (int i = 0; i < ChannelCount; i++)
  53. {
  54. ChannelConfigs.Add(new ChannelConfig()
  55. {
  56. LocalIndex = i,
  57. GlobalIndex = i,
  58. Name = $"Channel {i + 1}",
  59. Description = $"Description for Channel {i + 1}",
  60. DefaultBrightness = 100
  61. });
  62. }
  63. }
  64. break;
  65. default:
  66. ChannelConfigs = new ObservableCollection<ChannelConfig>();
  67. SerialPortConfig = null;
  68. TcpConfig = null;
  69. break;
  70. }
  71. }
  72. }
  73. }
  74. private ObservableCollection<ChannelConfig> _ChannelConfigs;
  75. public ObservableCollection<ChannelConfig> ChannelConfigs
  76. {
  77. get { return _ChannelConfigs; }
  78. set { SetProperty(ref _ChannelConfigs, value); }
  79. }
  80. private TcpConfig _TcpConfig;
  81. public TcpConfig TcpConfig
  82. {
  83. get { return _TcpConfig; }
  84. set { SetProperty(ref _TcpConfig, value); }
  85. }
  86. private SerialPortConfig _SerialPortConfig;
  87. public SerialPortConfig SerialPortConfig
  88. {
  89. get { return _SerialPortConfig; }
  90. set { SetProperty(ref _SerialPortConfig, value); }
  91. }
  92. public LightControllerConfig()
  93. {
  94. ChannelConfigs = new ObservableCollection<ChannelConfig>();
  95. }
  96. public LightControllerConfig(int id, string name, LightModel model)
  97. {
  98. Id = id;
  99. Name = name;
  100. LightModel = model;
  101. switch (LightModel)
  102. {
  103. case LightModel.KCS_KDC_12V60W_4T:
  104. ChannelCount = 4;
  105. TcpConfig = null;
  106. SerialPortConfig = new SerialPortConfig();
  107. ChannelConfigs = new ObservableCollection<ChannelConfig>();
  108. for (int i = 0; i < ChannelCount; i++)
  109. {
  110. ChannelConfigs.Add(new ChannelConfig()
  111. {
  112. LocalIndex = i,
  113. GlobalIndex = i,
  114. Name = $"Channel {i + 1}",
  115. Description = $"Description for Channel {i + 1}",
  116. DefaultBrightness = 100
  117. });
  118. }
  119. break;
  120. default:
  121. ChannelConfigs = new ObservableCollection<ChannelConfig>();
  122. SerialPortConfig = null;
  123. TcpConfig = null;
  124. break;
  125. }
  126. }
  127. }
  128. }