1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using Shaker.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShakerService.ViewModel
- {
- internal sealed class FlutterViewModel:ViewModelBase<FlutterModel>
- {
- /// <summary>
- /// 频率(Hz)
- /// </summary>
- public double Frequency=>CurrentModel.Frequency;
- /// <summary>
- /// 幅值(V)
- /// </summary>
- public double Amplitude=>CurrentModel.Amplitude;
- private FlutterViewModel():base()
- {
- }
- static FlutterViewModel()
- {
- }
- private protected override void ReadModel()
- {
- base.ReadModel();
- Communication.Instance.DbConnection.CreateTable<FlutterModel>(tableName:nameof(FlutterModel));
- var model = Communication.Instance.DbConnection.Table<FlutterModel>().FirstOrDefault()?? new FlutterModel();
- CurrentModel = model;
- SaveModel();
- }
- private protected override void SaveModel()
- {
- base.SaveModel();
- Communication.Instance.DbConnection.DeleteAll<FlutterModel>();
- Communication.Instance.DbConnection.Insert(CurrentModel);
- }
- public override void SetFpga()
- {
- base.SetFpga();
- ShakerFpga.ShakerFpga.Instance.颤震频率.Value = CurrentModel.Frequency * 2 / ShakerConfigViewModel.Instance.SampleRate;
- ShakerFpga.ShakerFpga.Instance.颤振信号幅值.Value = CurrentModel.Amplitude;
- }
- public static FlutterViewModel Instance { get; } = new FlutterViewModel();
- }
- }
|