2011-02-14 10:48:47 -04:00
|
|
|
using System;
|
2011-02-24 13:13:02 -04:00
|
|
|
using System.ComponentModel;
|
2011-02-14 10:48:47 -04:00
|
|
|
|
|
|
|
namespace ArducopterConfigurator.PresentationModels
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Common base for the simple VMs that deal with an update from APM and Get and Update them
|
|
|
|
/// </summary>
|
2011-02-16 18:19:32 -04:00
|
|
|
public abstract class CrudVm : NotifyProperyChangedBase, IPresentationModel
|
2011-02-14 10:48:47 -04:00
|
|
|
{
|
|
|
|
protected string updateString;
|
|
|
|
protected string refreshString;
|
|
|
|
|
2011-02-24 13:13:02 -04:00
|
|
|
// true when we are populating the properties from a serial command
|
|
|
|
protected bool _apmUpdatingProperties;
|
|
|
|
|
2011-02-14 10:48:47 -04:00
|
|
|
protected CrudVm()
|
|
|
|
{
|
|
|
|
RefreshCommand = new DelegateCommand(_ => RefreshValues());
|
|
|
|
UpdateCommand = new DelegateCommand(_ => UpdateValues());
|
2011-02-24 13:13:02 -04:00
|
|
|
PropertyChanged += AltitudeHoldConfigVm_PropertyChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AltitudeHoldConfigVm_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
// When this happens, a property has been set either when the user has adjusted it,
|
|
|
|
// or when the APM has sent us an update, probably due to an refresh command.
|
|
|
|
if (!_apmUpdatingProperties)
|
|
|
|
{
|
|
|
|
// Since here we know it was the user updating. Send to the apm
|
|
|
|
UpdateValues();
|
|
|
|
}
|
2011-02-14 10:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public string[] PropsInUpdateOrder { get; protected set; }
|
|
|
|
|
|
|
|
public ICommand RefreshCommand { get; private set; }
|
|
|
|
|
|
|
|
public ICommand UpdateCommand { get; private set; }
|
|
|
|
|
|
|
|
protected void RefreshValues()
|
|
|
|
{
|
|
|
|
if (sendTextToApm != null)
|
|
|
|
sendTextToApm(this, new sendTextToApmEventArgs(refreshString));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void UpdateValues()
|
|
|
|
{
|
|
|
|
if (sendTextToApm != null)
|
|
|
|
{
|
2011-02-16 18:19:32 -04:00
|
|
|
var apmString = PropertyHelper.ComposePropValuesWithCommand(this, PropsInUpdateOrder, updateString);
|
2011-02-14 10:48:47 -04:00
|
|
|
sendTextToApm(this, new sendTextToApmEventArgs(apmString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract string Name { get; }
|
|
|
|
|
|
|
|
public void Activate()
|
|
|
|
{
|
|
|
|
RefreshValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DeActivate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleLineOfText(string strRx)
|
|
|
|
{
|
2011-02-24 13:13:02 -04:00
|
|
|
_apmUpdatingProperties = true;
|
2011-02-24 18:12:17 -04:00
|
|
|
PropertyHelper.PopulatePropsFromUpdate(this,PropsInUpdateOrder, strRx,false);
|
|
|
|
_apmUpdatingProperties = false;
|
2011-02-14 10:48:47 -04:00
|
|
|
|
|
|
|
if (updatedByApm != null)
|
|
|
|
updatedByApm(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
public event EventHandler<sendTextToApmEventArgs> sendTextToApm;
|
|
|
|
|
|
|
|
public event EventHandler updatedByApm;
|
|
|
|
}
|
|
|
|
}
|