FlutterViewModel.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Shaker.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ShakerService.ViewModel
  8. {
  9. internal sealed class FlutterViewModel:ViewModelBase<FlutterModel>
  10. {
  11. /// <summary>
  12. /// 频率(Hz)
  13. /// </summary>
  14. public double Frequency=>CurrentModel.Frequency;
  15. /// <summary>
  16. /// 幅值(V)
  17. /// </summary>
  18. public double Amplitude=>CurrentModel.Amplitude;
  19. private FlutterViewModel():base()
  20. {
  21. }
  22. static FlutterViewModel()
  23. {
  24. }
  25. private protected override void ReadModel()
  26. {
  27. base.ReadModel();
  28. Communication.Instance.DbConnection.CreateTable<FlutterModel>(tableName:nameof(FlutterModel));
  29. var model = Communication.Instance.DbConnection.Table<FlutterModel>().FirstOrDefault()?? new FlutterModel();
  30. CurrentModel = model;
  31. SaveModel();
  32. }
  33. private protected override void SaveModel()
  34. {
  35. base.SaveModel();
  36. Communication.Instance.DbConnection.DeleteAll<FlutterModel>();
  37. Communication.Instance.DbConnection.Insert(CurrentModel);
  38. }
  39. public override void SetFpga()
  40. {
  41. base.SetFpga();
  42. ShakerFpga.ShakerFpga.Instance.颤震频率.Value = CurrentModel.Frequency * 2 / ShakerConfigViewModel.Instance.SampleRate;
  43. ShakerFpga.ShakerFpga.Instance.颤振信号幅值.Value = CurrentModel.Amplitude;
  44. }
  45. public static FlutterViewModel Instance { get; } = new FlutterViewModel();
  46. }
  47. }