‪Black Box
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes
MiBand_Heartrate.ControlFrame Class Reference
Inheritance diagram for MiBand_Heartrate.ControlFrame:

Public Member Functions

 ControlFrame ()
 

Static Public Attributes

static bool isRunning = false
 

Protected Member Functions

override void Dispose (bool disposing)
 ‪Clean up any resources being used. More...
 

Private Member Functions

void ControlFrame_Load (object sender, EventArgs e)
 ‪Load the selected MiBand More...
 
void authButton_Click (object sender, EventArgs e)
 ‪Authentication button More...
 
delegate void OnAuthHandler (MiBand d, bool s)
 
void OnAuth (MiBand d, bool s)
 ‪Authenticate MiBand More...
 
void startButton_Click (object sender, EventArgs e)
 ‪Start Data collection More...
 
void stopButton_Click (object sender, EventArgs e)
 ‪Stop Data Collection More...
 
delegate void OnHeartrateChangeHandler (MiBand d, ushort v)
 
void OnHeartrateChange (MiBand d, ushort v)
 ‪Display heart rate change More...
 
void ControlFrame_FormClosing (object sender, FormClosingEventArgs e)
 ‪Disconnect when application it closed More...
 
void InitializeComponent ()
 ‪Required method for Designer support - do not modify the contents of this method with the code editor. More...
 

Private Attributes

MiBand device
 
System.ComponentModel.IContainer components = null
 ‪Required designer variable. More...
 
System.Windows.Forms.ToolStrip toolStrip1
 
System.Windows.Forms.ToolStripButton authButton
 
System.Windows.Forms.ToolStripLabel connectionStatusLabel
 
System.Windows.Forms.ToolStripSeparator toolStripSeparator2
 
System.Windows.Forms.GroupBox groupBox1
 
System.Windows.Forms.Label heartrateLabel
 
System.Windows.Forms.Button startButton
 
System.Windows.Forms.Button stopButton
 

Detailed Description

Definition at line 16 of file ControlFrame.cs.

Constructor & Destructor Documentation

◆ ControlFrame()

MiBand_Heartrate.ControlFrame.ControlFrame ( )

Definition at line 21 of file ControlFrame.cs.

22  {
24  }
‪void InitializeComponent()
‪Required method for Designer support - do not modify the contents of this method with the code editor...

Member Function Documentation

◆ authButton_Click()

void MiBand_Heartrate.ControlFrame.authButton_Click ( object  sender,
EventArgs  e 
)
private

‪Authentication button

Parameters
sender
e

Definition at line 41 of file ControlFrame.cs.

42  {
44  }
‪void OnAuth(MiBand d, bool s)
‪Authenticate MiBand
Definition: ControlFrame.cs:53
‪async void Authenticate(OnAuthHandler callback=null)
Definition: MiBand.cs:83

Referenced by MiBand_Heartrate.ControlFrame.InitializeComponent().

◆ ControlFrame_FormClosing()

void MiBand_Heartrate.ControlFrame.ControlFrame_FormClosing ( object  sender,
FormClosingEventArgs  e 
)
private

‪Disconnect when application it closed

Parameters
sender
e

Definition at line 132 of file ControlFrame.cs.

133  {
135  if (DeviceControl.Instance.BluetoothManager.HasDeviceConnected())
136  {
137  DeviceControl.Instance.BluetoothManager.Disconnect();
138  }
139  }
‪void StopMonitorHeartrate()
‪Stop heart rate reading
Definition: MiBand.cs:269

Referenced by MiBand_Heartrate.ControlFrame.InitializeComponent().

◆ ControlFrame_Load()

void MiBand_Heartrate.ControlFrame.ControlFrame_Load ( object  sender,
EventArgs  e 
)
private

‪Load the selected MiBand

Parameters
sender
e

Definition at line 31 of file ControlFrame.cs.

32  {
33  ‪device = new MiBand(DeviceControl.Instance.BluetoothManager);
34  }

Referenced by MiBand_Heartrate.ControlFrame.InitializeComponent().

◆ Dispose()

override void MiBand_Heartrate.ControlFrame.Dispose ( bool  disposing)
protected

‪Clean up any resources being used.

Parameters
disposing‪true if managed resources should be disposed; otherwise, false.

Definition at line 14 of file ControlFrame.Designer.cs.

15  {
16  if (disposing && (‪components != null))
17  {
18  ‪components.Dispose();
19  }
20  base.Dispose(disposing);
21  }
‪System.ComponentModel.IContainer components
‪Required designer variable.

◆ InitializeComponent()

void MiBand_Heartrate.ControlFrame.InitializeComponent ( )
private

‪Required method for Designer support - do not modify the contents of this method with the code editor.

Definition at line 29 of file ControlFrame.Designer.cs.

30  {
31  System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(‪ControlFrame));
32  this.‪toolStrip1 = new System.Windows.Forms.ToolStrip();
33  this.‪authButton = new System.Windows.Forms.ToolStripButton();
34  this.‪toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
35  this.‪connectionStatusLabel = new System.Windows.Forms.ToolStripLabel();
36  this.‪groupBox1 = new System.Windows.Forms.GroupBox();
37  this.‪heartrateLabel = new System.Windows.Forms.Label();
38  this.‪startButton = new System.Windows.Forms.Button();
39  this.‪stopButton = new System.Windows.Forms.Button();
40  this.‪toolStrip1.SuspendLayout();
41  this.‪groupBox1.SuspendLayout();
42  this.SuspendLayout();
43  //
44  // toolStrip1
45  //
46  this.‪toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
47  this.authButton,
48  this.toolStripSeparator2,
49  this.connectionStatusLabel});
50  this.‪toolStrip1.Location = new System.Drawing.Point(0, 0);
51  this.‪toolStrip1.Name = "toolStrip1";
52  this.‪toolStrip1.Size = new System.Drawing.Size(239, 25);
53  this.‪toolStrip1.TabIndex = 0;
54  this.‪toolStrip1.Text = "toolStrip1";
55  //
56  // authButton
57  //
58  this.‪authButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
59  this.‪authButton.Image = ((System.Drawing.Image)(resources.GetObject("authButton.Image")));
60  this.‪authButton.ImageTransparentColor = System.Drawing.Color.Magenta;
61  this.‪authButton.Name = "authButton";
62  this.‪authButton.Size = new System.Drawing.Size(23, 22);
63  this.‪authButton.Text = "Authenticate device";
64  this.‪authButton.ToolTipText = "Auth device";
65  this.‪authButton.Click += new System.EventHandler(this.‪authButton_Click);
66  //
67  // toolStripSeparator2
68  //
69  this.‪toolStripSeparator2.Name = "toolStripSeparator2";
70  this.‪toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
71  //
72  // connectionStatusLabel
73  //
74  this.‪connectionStatusLabel.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
75  this.‪connectionStatusLabel.Name = "connectionStatusLabel";
76  this.‪connectionStatusLabel.Size = new System.Drawing.Size(123, 22);
77  this.‪connectionStatusLabel.Text = "Connected | Not Auth";
78  //
79  // groupBox1
80  //
81  this.‪groupBox1.Controls.Add(this.‪heartrateLabel);
82  this.‪groupBox1.Location = new System.Drawing.Point(12, 28);
83  this.‪groupBox1.Name = "groupBox1";
84  this.‪groupBox1.Size = new System.Drawing.Size(62, 63);
85  this.‪groupBox1.TabIndex = 1;
86  this.‪groupBox1.TabStop = false;
87  this.‪groupBox1.Text = "Heartrate";
88  //
89  // heartrateLabel
90  //
91  this.‪heartrateLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
92  this.‪heartrateLabel.Location = new System.Drawing.Point(6, 16);
93  this.‪heartrateLabel.Name = "heartrateLabel";
94  this.‪heartrateLabel.Size = new System.Drawing.Size(50, 35);
95  this.‪heartrateLabel.TabIndex = 0;
96  this.‪heartrateLabel.Text = "--";
97  this.‪heartrateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
98  //
99  // startButton
100  //
101  this.‪startButton.Enabled = false;
102  this.‪startButton.Location = new System.Drawing.Point(89, 38);
103  this.‪startButton.Name = "startButton";
104  this.‪startButton.Size = new System.Drawing.Size(120, 22);
105  this.‪startButton.TabIndex = 3;
106  this.‪startButton.Text = "Start sensor";
107  this.‪startButton.UseVisualStyleBackColor = true;
108  this.‪startButton.Click += new System.EventHandler(this.‪startButton_Click);
109  //
110  // stopButton
111  //
112  this.‪stopButton.Enabled = false;
113  this.‪stopButton.Location = new System.Drawing.Point(89, 66);
114  this.‪stopButton.Name = "stopButton";
115  this.‪stopButton.Size = new System.Drawing.Size(120, 22);
116  this.‪stopButton.TabIndex = 4;
117  this.‪stopButton.Text = "Stop";
118  this.‪stopButton.UseVisualStyleBackColor = true;
119  this.‪stopButton.Click += new System.EventHandler(this.‪stopButton_Click);
120  //
121  // ControlFrame
122  //
123  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
124  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
125  this.BackColor = System.Drawing.SystemColors.Highlight;
126  this.ClientSize = new System.Drawing.Size(239, 100);
127  this.Controls.Add(this.‪stopButton);
128  this.Controls.Add(this.‪startButton);
129  this.Controls.Add(this.‪groupBox1);
130  this.Controls.Add(this.‪toolStrip1);
131  this.ForeColor = System.Drawing.SystemColors.Desktop;
132  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
133  this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
134  this.Name = "ControlFrame";
135  this.ShowIcon = false;
136  this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
137  this.Text = "Mi Band - Heartrate";
138  this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.‪ControlFrame_FormClosing);
139  this.Load += new System.EventHandler(this.‪ControlFrame_Load);
140  this.‪toolStrip1.ResumeLayout(false);
141  this.‪toolStrip1.PerformLayout();
142  this.‪groupBox1.ResumeLayout(false);
143  this.ResumeLayout(false);
144  this.PerformLayout();
145 
146  }
‪System.Windows.Forms.Label heartrateLabel
‪System.Windows.Forms.GroupBox groupBox1
‪System.Windows.Forms.ToolStripLabel connectionStatusLabel
‪System.Windows.Forms.ToolStrip toolStrip1
‪System.Windows.Forms.Button startButton
‪void authButton_Click(object sender, EventArgs e)
‪Authentication button
Definition: ControlFrame.cs:41
‪System.Windows.Forms.Button stopButton
‪System.Windows.Forms.ToolStripSeparator toolStripSeparator2
‪void ControlFrame_Load(object sender, EventArgs e)
‪Load the selected MiBand
Definition: ControlFrame.cs:31
‪System.Windows.Forms.ToolStripButton authButton
‪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

Referenced by MiBand_Heartrate.ControlFrame.ControlFrame().

◆ OnAuth()

void MiBand_Heartrate.ControlFrame.OnAuth ( MiBand  d,
bool  s 
)
private

‪Authenticate MiBand

Parameters
d
s

Definition at line 53 of file ControlFrame.cs.

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  }
‪void OnAuth(MiBand d, bool s)
‪Authenticate MiBand
Definition: ControlFrame.cs:53
‪System.Windows.Forms.ToolStripLabel connectionStatusLabel
‪delegate void OnAuthHandler(MiBand d, bool s)
‪static void SaveErrorData(string error)
‪Log all the error that occurs in the program
‪System.Windows.Forms.Button startButton

Referenced by MiBand_Heartrate.ControlFrame.authButton_Click().

◆ OnAuthHandler()

delegate void MiBand_Heartrate.ControlFrame.OnAuthHandler ( MiBand  d,
bool  s 
)
private

◆ OnHeartrateChange()

void MiBand_Heartrate.ControlFrame.OnHeartrateChange ( MiBand  d,
ushort  v 
)
private

‪Display heart rate change

Parameters
d
v

Definition at line 114 of file ControlFrame.cs.

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  }
‪System.Windows.Forms.Label heartrateLabel
‪delegate void OnHeartrateChangeHandler(MiBand d, ushort v)
‪void OnHeartrateChange(MiBand d, ushort v)
‪Display heart rate change

Referenced by MiBand_Heartrate.ControlFrame.startButton_Click(), and MiBand_Heartrate.ControlFrame.stopButton_Click().

◆ OnHeartrateChangeHandler()

delegate void MiBand_Heartrate.ControlFrame.OnHeartrateChangeHandler ( MiBand  d,
ushort  v 
)
private

◆ startButton_Click()

void MiBand_Heartrate.ControlFrame.startButton_Click ( object  sender,
EventArgs  e 
)
private

‪Start Data collection

Parameters
sender
e

Definition at line 82 of file ControlFrame.cs.

83  {
84  ‪startButton.Enabled = false;
87  ‪device.‪HeartrateChanged += DeviceControl.Instance.WriteRealtimeHeartrateInFile;
89  ‪stopButton.Enabled = true;
90  ‪isRunning = true;
91  }
‪OnHeartrateChangedHandler HeartrateChanged
Definition: MiBand.cs:49
‪System.Windows.Forms.Button startButton
‪System.Windows.Forms.Button stopButton
‪void OnHeartrateChange(MiBand d, ushort v)
‪Display heart rate change
‪async void StartMonitorHeartrate()
Definition: MiBand.cs:188

Referenced by MiBand_Heartrate.ControlFrame.InitializeComponent().

◆ stopButton_Click()

void MiBand_Heartrate.ControlFrame.stopButton_Click ( object  sender,
EventArgs  e 
)
private

‪Stop Data Collection

Parameters
sender
e

Definition at line 98 of file ControlFrame.cs.

99  {
100  ‪stopButton.Enabled = false;
103  ‪heartrateLabel.Text = "--";
104  ‪startButton.Enabled = true;
105  }
‪System.Windows.Forms.Label heartrateLabel
‪OnHeartrateChangedHandler HeartrateChanged
Definition: MiBand.cs:49
‪System.Windows.Forms.Button startButton
‪System.Windows.Forms.Button stopButton
‪void OnHeartrateChange(MiBand d, ushort v)
‪Display heart rate change
‪void StopMonitorHeartrate()
‪Stop heart rate reading
Definition: MiBand.cs:269

Referenced by MiBand_Heartrate.ControlFrame.InitializeComponent().

Field Documentation

◆ authButton

System.Windows.Forms.ToolStripButton MiBand_Heartrate.ControlFrame.authButton
private

◆ components

System.ComponentModel.IContainer MiBand_Heartrate.ControlFrame.components = null
private

‪Required designer variable.

Definition at line 8 of file ControlFrame.Designer.cs.

Referenced by MiBand_Heartrate.ControlFrame.Dispose().

◆ connectionStatusLabel

System.Windows.Forms.ToolStripLabel MiBand_Heartrate.ControlFrame.connectionStatusLabel
private

◆ device

MiBand MiBand_Heartrate.ControlFrame.device
private

◆ groupBox1

System.Windows.Forms.GroupBox MiBand_Heartrate.ControlFrame.groupBox1
private

◆ heartrateLabel

System.Windows.Forms.Label MiBand_Heartrate.ControlFrame.heartrateLabel
private

◆ isRunning

bool MiBand_Heartrate.ControlFrame.isRunning = false
static

◆ startButton

System.Windows.Forms.Button MiBand_Heartrate.ControlFrame.startButton
private

◆ stopButton

System.Windows.Forms.Button MiBand_Heartrate.ControlFrame.stopButton
private

◆ toolStrip1

System.Windows.Forms.ToolStrip MiBand_Heartrate.ControlFrame.toolStrip1
private

◆ toolStripSeparator2

System.Windows.Forms.ToolStripSeparator MiBand_Heartrate.ControlFrame.toolStripSeparator2
private

The documentation for this class was generated from the following files: