VoiceMotorParam.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Team.FFFeederService.Enums;
  10. namespace Team.FFFeederService.Models
  11. {
  12. /// <summary>
  13. /// 单个电机参数
  14. /// </summary>
  15. public class VoiceMotorParam:INotifyPropertyChanged
  16. {
  17. private ushort _Amplitude;
  18. /// <summary>
  19. /// 振幅(0-100%)
  20. /// </summary>
  21. public ushort Amplitude
  22. {
  23. get { return _Amplitude; }
  24. set { SetProperty(ref _Amplitude,value); }
  25. }
  26. private ushort _Frequency;
  27. /// <summary>
  28. /// 频率(0-250HZ)
  29. /// </summary>
  30. public ushort Frequency
  31. {
  32. get { return _Frequency; }
  33. set { SetProperty(ref _Frequency, value); }
  34. }
  35. private ushort _Phase;
  36. /// <summary>
  37. /// 相位(0-359deg)
  38. /// </summary>
  39. public ushort Phase
  40. {
  41. get { return _Phase; }
  42. set { SetProperty(ref _Phase, value); }
  43. }
  44. private WaveShape _WaveShape;
  45. /// <summary>
  46. /// 波形
  47. /// </summary>
  48. public WaveShape WaveShape
  49. {
  50. get { return _WaveShape; }
  51. set { SetProperty(ref _WaveShape, value); }
  52. }
  53. #region 属性更改通知
  54. /// <summary>
  55. /// Occurs when a property value changes.
  56. /// </summary>
  57. public event PropertyChangedEventHandler PropertyChanged;
  58. /// <summary>
  59. /// Checks if a property already matches a desired value. Sets the property and
  60. /// notifies listeners only when necessary.
  61. /// </summary>
  62. /// <typeparam name="T">Type of the property.</typeparam>
  63. /// <param name="storage">Reference to a property with both getter and setter.</param>
  64. /// <param name="value">Desired value for the property.</param>
  65. /// <param name="propertyName">Name of the property used to notify listeners. This
  66. /// value is optional and can be provided automatically when invoked from compilers that
  67. /// support CallerMemberName.</param>
  68. /// <returns>True if the value was changed, false if the existing value matched the
  69. /// desired value.</returns>
  70. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  71. {
  72. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  73. storage = value;
  74. RaisePropertyChanged(propertyName);
  75. return true;
  76. }
  77. /// <summary>
  78. /// Checks if a property already matches a desired value. Sets the property and
  79. /// notifies listeners only when necessary.
  80. /// </summary>
  81. /// <typeparam name="T">Type of the property.</typeparam>
  82. /// <param name="storage">Reference to a property with both getter and setter.</param>
  83. /// <param name="value">Desired value for the property.</param>
  84. /// <param name="propertyName">Name of the property used to notify listeners. This
  85. /// value is optional and can be provided automatically when invoked from compilers that
  86. /// support CallerMemberName.</param>
  87. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  88. /// <returns>True if the value was changed, false if the existing value matched the
  89. /// desired value.</returns>
  90. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  91. {
  92. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  93. storage = value;
  94. onChanged?.Invoke();
  95. RaisePropertyChanged(propertyName);
  96. return true;
  97. }
  98. /// <summary>
  99. /// Raises this object's PropertyChanged event.
  100. /// </summary>
  101. /// <param name="propertyName">Name of the property used to notify listeners. This
  102. /// value is optional and can be provided automatically when invoked from compilers
  103. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  104. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  105. {
  106. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  107. }
  108. /// <summary>
  109. /// Raises this object's PropertyChanged event.
  110. /// </summary>
  111. /// <param name="args">The PropertyChangedEventArgs</param>
  112. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  113. {
  114. PropertyChanged?.Invoke(this, args);
  115. }
  116. #endregion
  117. public VoiceMotorParam Clone()
  118. {
  119. return JsonConvert.DeserializeObject<VoiceMotorParam>(JsonConvert.SerializeObject(this));
  120. }
  121. }
  122. }