‪Black Box
ControlFrame.cs
Go to the documentation of this file.
1 /*
2 * FILE : ControlFrame.cs
3 * PROJECT : Black Box
4 * PROGRAMMER : BRIAN HINDS
5 * FIRST VERSION : 1.0.0.0
6 * DATE : March 20, 2019
7 * DESCRIPTION : Used for authentication and sensor control
8 */
9 
11 using System;
12 using System.Windows.Forms;
13 
14 namespace ‪MiBand_Heartrate
15 {
16  public partial class ‪ControlFrame : Form
17  {
19  public static bool ‪isRunning = false;
20 
21  public ‪ControlFrame()
22  {
24  }
25 
31  private void ‪ControlFrame_Load(object sender, EventArgs e)
32  {
34  }
35 
41  private void ‪authButton_Click(object sender, EventArgs e)
42  {
44  }
45 
46  private delegate void ‪OnAuthHandler(‪MiBand d, bool s);
47 
53  private void ‪OnAuth(‪MiBand d, bool s)
54  {
55  if (InvokeRequired)
56  {
58  Invoke(c, new object[] { d, s });
59  }
60  else
61  {
62  if (s)
63  {
64  ‪connectionStatusLabel.Text = "Connected | Auth";
65  ‪startButton.Enabled = true;
66  ‪isRunning = true;
67  }
68  else
69  {
70  ‪isRunning = false;
71  MessageBox.Show("Auth failed !", "Device error", MessageBoxButtons.OK, MessageBoxIcon.Error);
72  ‪BBSensorErrorLog.‪SaveErrorData("Device error - Auth failed !");
73  }
74  }
75  }
76 
82  private void ‪startButton_Click(object sender, EventArgs e)
83  {
84  ‪startButton.Enabled = false;
89  ‪stopButton.Enabled = true;
90  ‪isRunning = true;
91  }
92 
98  private void ‪stopButton_Click(object sender, EventArgs e)
99  {
100  ‪stopButton.Enabled = false;
103  ‪heartrateLabel.Text = "--";
104  ‪startButton.Enabled = true;
105  }
106 
107  private delegate void ‪OnHeartrateChangeHandler(‪MiBand d, ushort v);
108 
114  private void ‪OnHeartrateChange(‪MiBand d, ushort v)
115  {
116  if (InvokeRequired)
117  {
119  Invoke(c, new object[] { d, v });
120  }
121  else
122  {
123  ‪heartrateLabel.Text = string.Format("{0} bpm", v);
124  }
125  }
126 
132  private void ‪ControlFrame_FormClosing(object sender, FormClosingEventArgs e)
133  {
136  {
138  }
139  }
140  }
141 }
‪System.Windows.Forms.Label heartrateLabel
‪void OnAuth(MiBand d, bool s)
‪Authenticate MiBand
Definition: ControlFrame.cs:53
‪OnHeartrateChangedHandler HeartrateChanged
Definition: MiBand.cs:49
‪System.Windows.Forms.ToolStripLabel connectionStatusLabel
‪delegate void OnAuthHandler(MiBand d, bool s)
‪delegate void OnHeartrateChangeHandler(MiBand d, ushort v)
‪static void SaveErrorData(string error)
‪Log all the error that occurs in the program
‪void WriteRealtimeHeartrateInFile(MiBand d, ushort v)
‪System.Windows.Forms.Button startButton
‪static DeviceControl Instance
‪void authButton_Click(object sender, EventArgs e)
‪Authentication button
Definition: ControlFrame.cs:41
‪System.Windows.Forms.Button stopButton
‪void InitializeComponent()
‪Required method for Designer support - do not modify the contents of this method with the code editor...
‪void OnHeartrateChange(MiBand d, ushort v)
‪Display heart rate change
‪void ControlFrame_Load(object sender, EventArgs e)
‪Load the selected MiBand
Definition: ControlFrame.cs:31
‪void StopMonitorHeartrate()
‪Stop heart rate reading
Definition: MiBand.cs:269
‪async void StartMonitorHeartrate()
Definition: MiBand.cs:188
‪void stopButton_Click(object sender, EventArgs e)
‪Stop Data Collection
Definition: ControlFrame.cs:98
‪void startButton_Click(object sender, EventArgs e)
‪Start Data collection
Definition: ControlFrame.cs:82
‪void ControlFrame_FormClosing(object sender, FormClosingEventArgs e)
‪Disconnect when application it closed
‪async void Authenticate(OnAuthHandler callback=null)
Definition: MiBand.cs:83