Skip to content

Commit

Permalink
Improved BtHrp device.
Browse files Browse the repository at this point in the history
Minor changes to Star/Stop logic.
Added CharacteristicIndex and InitDelay options.
Fixed packet number not incrementing.
  • Loading branch information
uwburn committed Jun 25, 2017
1 parent 6091ccc commit 718dc4e
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 35 deletions.
Binary file modified Cardia.v12.suo
Binary file not shown.
4 changes: 4 additions & 0 deletions Cardia/PresentationModel/Cardia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ private void LoadConfiguration()
}
}
}
((BtHrp)hrm).CharacteristicIndex = configuration.Device.BtHrp.CharacteristicIndex;
((BtHrp)hrm).InitDelay = configuration.Device.BtHrp.InitDelay;
break;
case Configuration.DeviceConfiguration.DeviceType.HRMEmulator:
hrm = Devices[3];
Expand Down Expand Up @@ -674,6 +676,8 @@ public void SaveConfig()
configuration.Device.Type = Configuration.DeviceConfiguration.DeviceType.BtHrp;
if (((BtHrp)hrm).Device != null)
configuration.Device.BtHrp.DeviceId = ((BtHrp)hrm).Device.Id;
configuration.Device.BtHrp.CharacteristicIndex = ((BtHrp)hrm).CharacteristicIndex;
configuration.Device.BtHrp.InitDelay = ((BtHrp)hrm).InitDelay;
}
else if (hrm is HRMEmulator)
{
Expand Down
2 changes: 2 additions & 0 deletions Cardia/Utils/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class CMS50Configuration
public class BtHrpConfiguration
{
public string DeviceId = null;
public int CharacteristicIndex = 0;
public int InitDelay = 500;
}

public class HRMEmulatorConfiguration
Expand Down
66 changes: 63 additions & 3 deletions Cardia/View/BtHrpFrm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 55 additions & 2 deletions Cardia/View/BtHrpFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public BtHrpFrm(Cardia cardia)
cardia.Stopped += cardia_Stopped;
cardia.PacketProcessed += cardia_OnPacketProcessed;
btHrp.DeviceChanged += btHrp_DeviceChanged;
btHrp.CharacteristicIndexChanged += btHrp_CharacteristicIndexChanged;
btHrp.InitDelayChanged += btHrp_InitDelayChanged;

cbDevices.DataSource = new BindingSource(devices, null);

Expand All @@ -54,26 +56,56 @@ public BtHrpFrm(Cardia cardia)
cbDevices.SelectedItem = devices[0];
}
}

nudCharacteristic.Value = btHrp.CharacteristicIndex;

nudInitDelay.Value = btHrp.InitDelay;
}

void cardia_Started(object sender)
{
LockConfigurationUI();
if (this.IsHandleCreated)
{
this.Invoke((MethodInvoker)delegate
{
LockConfigurationUI();
});
}
else
{
LockConfigurationUI();
}
}

void cardia_Stopped(object sender)
{
UnlockConfigurationUI();
if (this.IsHandleCreated)
{
this.Invoke((MethodInvoker)delegate
{
UnlockConfigurationUI();
tbHeartRate.Text = string.Empty;
});
}
else
{
UnlockConfigurationUI();
tbHeartRate.Text = string.Empty;
}
}

public override void LockConfigurationUI()
{
cbDevices.Enabled = false;
nudCharacteristic.Enabled = false;
nudInitDelay.Enabled = false;
}

public override void UnlockConfigurationUI()
{
cbDevices.Enabled = true;
nudCharacteristic.Enabled = true;
nudInitDelay.Enabled = true;
}

public override void ResetUI()
Expand Down Expand Up @@ -109,17 +141,38 @@ void btHrp_DeviceChanged(object sender, DeviceInformation device)
}
}

void btHrp_CharacteristicIndexChanged(object sender, int characteristicIndex)
{
nudCharacteristic.Value = characteristicIndex;
}

void btHrp_InitDelayChanged(object sender, int delay)
{
nudInitDelay.Value = delay;
}

private void cbDevices_SelectedIndexChanged(object sender, EventArgs e)
{
DeviceInformation device = (DeviceInformation)cbDevices.SelectedItem;

btHrp.Device = device;
}

private void nudCharacteristic_ValueChanged(object sender, EventArgs e)
{
btHrp.CharacteristicIndex = Decimal.ToInt32(nudCharacteristic.Value);
}

private void nudInitDelay_ValueChanged(object sender, EventArgs e)
{
btHrp.InitDelay = Decimal.ToInt32(nudInitDelay.Value);
}

private void BtHrpFrm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}

}
}
Loading

0 comments on commit 718dc4e

Please sign in to comment.