repo time

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Committer:
darienf
Date:
Tue Apr 06 06:41:40 2021 +0000
Revision:
20:6d2af70c92ab
another repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 20:6d2af70c92ab 1 /*******************************************************************************
darienf 20:6d2af70c92ab 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
darienf 20:6d2af70c92ab 3 *
darienf 20:6d2af70c92ab 4 * This software is protected by copyright laws of the United States and
darienf 20:6d2af70c92ab 5 * of foreign countries. This material may also be protected by patent laws
darienf 20:6d2af70c92ab 6 * and technology transfer regulations of the United States and of foreign
darienf 20:6d2af70c92ab 7 * countries. This software is furnished under a license agreement and/or a
darienf 20:6d2af70c92ab 8 * nondisclosure agreement and may only be used or reproduced in accordance
darienf 20:6d2af70c92ab 9 * with the terms of those agreements. Dissemination of this information to
darienf 20:6d2af70c92ab 10 * any party or parties not specified in the license agreement and/or
darienf 20:6d2af70c92ab 11 * nondisclosure agreement is expressly prohibited.
darienf 20:6d2af70c92ab 12 *
darienf 20:6d2af70c92ab 13 * The above copyright notice and this permission notice shall be included
darienf 20:6d2af70c92ab 14 * in all copies or substantial portions of the Software.
darienf 20:6d2af70c92ab 15 *
darienf 20:6d2af70c92ab 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 20:6d2af70c92ab 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 20:6d2af70c92ab 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 20:6d2af70c92ab 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 20:6d2af70c92ab 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 20:6d2af70c92ab 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 20:6d2af70c92ab 22 * OTHER DEALINGS IN THE SOFTWARE.
darienf 20:6d2af70c92ab 23 *
darienf 20:6d2af70c92ab 24 * Except as contained in this notice, the name of Maxim Integrated
darienf 20:6d2af70c92ab 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 20:6d2af70c92ab 26 * Products, Inc. Branding Policy.
darienf 20:6d2af70c92ab 27 *
darienf 20:6d2af70c92ab 28 * The mere transfer of this software does not imply any licenses
darienf 20:6d2af70c92ab 29 * of trade secrets, proprietary technology, copyrights, patents,
darienf 20:6d2af70c92ab 30 * trademarks, maskwork rights, or any other form of intellectual
darienf 20:6d2af70c92ab 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 20:6d2af70c92ab 32 * ownership rights.
darienf 20:6d2af70c92ab 33 *******************************************************************************
darienf 20:6d2af70c92ab 34 */
darienf 20:6d2af70c92ab 35
darienf 20:6d2af70c92ab 36 //#define CES_DEMO
darienf 20:6d2af70c92ab 37 //#define FILE_LOG
darienf 20:6d2af70c92ab 38
darienf 20:6d2af70c92ab 39 using System;
darienf 20:6d2af70c92ab 40 using System.Collections.Generic;
darienf 20:6d2af70c92ab 41 using System.ComponentModel;
darienf 20:6d2af70c92ab 42 using System.Drawing;
darienf 20:6d2af70c92ab 43 using System.Data;
darienf 20:6d2af70c92ab 44 using System.Linq;
darienf 20:6d2af70c92ab 45 using System.Text;
darienf 20:6d2af70c92ab 46 using System.Windows.Forms;
darienf 20:6d2af70c92ab 47 using System.Windows.Forms.DataVisualization.Charting;
darienf 20:6d2af70c92ab 48 using RPCSupport.Streaming;
darienf 20:6d2af70c92ab 49 using RPCSupport.Devices;
darienf 20:6d2af70c92ab 50
darienf 20:6d2af70c92ab 51 using HealthSensorPlatform.View;
darienf 20:6d2af70c92ab 52 using HealthSensorPlatform.Presenter;
darienf 20:6d2af70c92ab 53 using HealthSensorPlatform.Model;
darienf 20:6d2af70c92ab 54
darienf 20:6d2af70c92ab 55 #if CES_DEMO
darienf 20:6d2af70c92ab 56 using System.Collections;
darienf 20:6d2af70c92ab 57 #endif
darienf 20:6d2af70c92ab 58
darienf 20:6d2af70c92ab 59 // DEBUG
darienf 20:6d2af70c92ab 60 using System.IO;
darienf 20:6d2af70c92ab 61
darienf 20:6d2af70c92ab 62
darienf 20:6d2af70c92ab 63 namespace HealthSensorPlatform.CustomControls
darienf 20:6d2af70c92ab 64 {
darienf 20:6d2af70c92ab 65 public partial class EcgView : UserControl, IDeviceView, IEcgView
darienf 20:6d2af70c92ab 66 {
darienf 20:6d2af70c92ab 67 /* Constants */
darienf 20:6d2af70c92ab 68 const int Rbias_FMSTR_Init = 0;
darienf 20:6d2af70c92ab 69 const int CAL_init = 1;
darienf 20:6d2af70c92ab 70 const int ECG_InitStart = 2;
darienf 20:6d2af70c92ab 71 const int PACE_InitStart = 3;
darienf 20:6d2af70c92ab 72 const int BIOZ_InitStart = 4;
darienf 20:6d2af70c92ab 73 const int ECGFast_Init = 5;
darienf 20:6d2af70c92ab 74 const int RtoR_InitStart = 6;
darienf 20:6d2af70c92ab 75
darienf 20:6d2af70c92ab 76 const int RToRMaxValue = 0x3FFF;
darienf 20:6d2af70c92ab 77
darienf 20:6d2af70c92ab 78 #if CES_DEMO
darienf 20:6d2af70c92ab 79 const int[] averageOptions = new int[] { 1, 2, 4, 8, 10 };
darienf 20:6d2af70c92ab 80 #endif
darienf 20:6d2af70c92ab 81
darienf 20:6d2af70c92ab 82 /* Fields */
darienf 20:6d2af70c92ab 83 public InitArgs.RbiasInit rbiasInit;
darienf 20:6d2af70c92ab 84 public InitArgs.EcgInitStart ecgArgs;
darienf 20:6d2af70c92ab 85 public InitArgs.EcgFastInit ecgFastArgs;
darienf 20:6d2af70c92ab 86 public InitArgs.PACEInitStart paceArgs;
darienf 20:6d2af70c92ab 87 public InitArgs.BIOZInitStart biozArgs;
darienf 20:6d2af70c92ab 88 public InitArgs.RToRInitStart rtorArgs;
darienf 20:6d2af70c92ab 89 public InitArgs.CalInitStart calArgs;
darienf 20:6d2af70c92ab 90
darienf 20:6d2af70c92ab 91 public GetEcgInitArgs GetEcgInitArgsPointer;
darienf 20:6d2af70c92ab 92 public GetRToRInitArgs GetRToRInitArgsPointer;
darienf 20:6d2af70c92ab 93 public GetBioZInitArgs GetBioZInitArgsPointer;
darienf 20:6d2af70c92ab 94 public GetPaceInitArgs GetPaceInitArgsPointer;
darienf 20:6d2af70c92ab 95
darienf 20:6d2af70c92ab 96 /// <summary>
darienf 20:6d2af70c92ab 97 /// Number of R To R points which need to be removed from the chart
darienf 20:6d2af70c92ab 98 /// </summary>
darienf 20:6d2af70c92ab 99 int rToRRemoveOffset;
darienf 20:6d2af70c92ab 100
darienf 20:6d2af70c92ab 101 long lastRToRTime;
darienf 20:6d2af70c92ab 102
darienf 20:6d2af70c92ab 103 double timeResolution = 0.00001525878;
darienf 20:6d2af70c92ab 104
darienf 20:6d2af70c92ab 105 double[] clockFreq = { 32768, 32000, 32000, 32768 * 640 / 656 }; // 31968.7804878 = 32768 * 640 / 656
darienf 20:6d2af70c92ab 106
darienf 20:6d2af70c92ab 107 int frequencyMasterField = 0;
darienf 20:6d2af70c92ab 108
darienf 20:6d2af70c92ab 109 public double masterClockFrequency = 32768;
darienf 20:6d2af70c92ab 110
darienf 20:6d2af70c92ab 111 #if CES_DEMO
darienf 20:6d2af70c92ab 112 public int AverageECG = 1;
darienf 20:6d2af70c92ab 113 #endif
darienf 20:6d2af70c92ab 114
darienf 20:6d2af70c92ab 115 private RPCSupport.RPCClient rpcClient;
darienf 20:6d2af70c92ab 116 private bool connected = false;
darienf 20:6d2af70c92ab 117 //private bool stream = true;
darienf 20:6d2af70c92ab 118
darienf 20:6d2af70c92ab 119 /// <summary>
darienf 20:6d2af70c92ab 120 /// Use to scale the bioZ chart data to milliohm range
darienf 20:6d2af70c92ab 121 /// </summary>
darienf 20:6d2af70c92ab 122 private int bioZRangeMultiplier = 1;
darienf 20:6d2af70c92ab 123
darienf 20:6d2af70c92ab 124 bool startedCal = false;
darienf 20:6d2af70c92ab 125 bool startedEcg = false;
darienf 20:6d2af70c92ab 126 bool startedPace = false;
darienf 20:6d2af70c92ab 127 bool startedBioz = false;
darienf 20:6d2af70c92ab 128 bool startedRtoR = false;
darienf 20:6d2af70c92ab 129
darienf 20:6d2af70c92ab 130 private bool enableECG = false;
darienf 20:6d2af70c92ab 131 private bool enableRToR = false;
darienf 20:6d2af70c92ab 132 private bool enableBioZ = false;
darienf 20:6d2af70c92ab 133 private bool enablePace = false;
darienf 20:6d2af70c92ab 134
darienf 20:6d2af70c92ab 135 int rToRInterval = -1;
darienf 20:6d2af70c92ab 136
darienf 20:6d2af70c92ab 137 ChartInfo ecgInfo;
darienf 20:6d2af70c92ab 138 ChartInfo rToRInfo;
darienf 20:6d2af70c92ab 139 ChartInfo bioZInfo;
darienf 20:6d2af70c92ab 140 ChartInfo paceInfo;
darienf 20:6d2af70c92ab 141
darienf 20:6d2af70c92ab 142 Queue<int> paceTag = new Queue<int>();
darienf 20:6d2af70c92ab 143 public PaceData paceData; // TODO: public for testing only
darienf 20:6d2af70c92ab 144 RToRCalculator rToRCalculator;
darienf 20:6d2af70c92ab 145
darienf 20:6d2af70c92ab 146 List<double> heartRateList = new List<double>(10);
darienf 20:6d2af70c92ab 147
darienf 20:6d2af70c92ab 148 /* CES DEMO average feature, normal operation average is 1 */
darienf 20:6d2af70c92ab 149 //int averageEcgCount = 0;
darienf 20:6d2af70c92ab 150 //int averageEcgSum = 0;
darienf 20:6d2af70c92ab 151
darienf 20:6d2af70c92ab 152 StringBuilder fileLogData = new StringBuilder();
darienf 20:6d2af70c92ab 153
darienf 20:6d2af70c92ab 154 int[, ,] ecgDecimationDelay = new int[,,] { {{650, 1034}, {2922, 3690}, {3370, 4906}, {3370, 4906}},
darienf 20:6d2af70c92ab 155 {{650, 1034}, {2922, 3690}, {3370, 4906}, {3370, 4906}},
darienf 20:6d2af70c92ab 156 {{1242, 2202}, {1242, 2202}, {1242, 2202}, {1242, 2202}},
darienf 20:6d2af70c92ab 157 {{1242, 2202}, {1242, 2202}, {1242, 2202}, {1242, 2202}}
darienf 20:6d2af70c92ab 158 };
darienf 20:6d2af70c92ab 159
darienf 20:6d2af70c92ab 160 public int RToRWindowField = 0;
darienf 20:6d2af70c92ab 161
darienf 20:6d2af70c92ab 162 #if CES_DEMO
darienf 20:6d2af70c92ab 163 FirFilter hpf;
darienf 20:6d2af70c92ab 164 #endif
darienf 20:6d2af70c92ab 165
darienf 20:6d2af70c92ab 166 #if FILE_LOG
darienf 20:6d2af70c92ab 167 // DEBUG
darienf 20:6d2af70c92ab 168 StreamWriter file; //= new StreamWriter("hsp_ecg_output_data.csv");
darienf 20:6d2af70c92ab 169 #endif
darienf 20:6d2af70c92ab 170
darienf 20:6d2af70c92ab 171 /* Constructor */
darienf 20:6d2af70c92ab 172 public EcgView()
darienf 20:6d2af70c92ab 173 {
darienf 20:6d2af70c92ab 174 InitializeComponent();
darienf 20:6d2af70c92ab 175
darienf 20:6d2af70c92ab 176 //paceInfo = ecgInfo;
darienf 20:6d2af70c92ab 177
darienf 20:6d2af70c92ab 178 /*foreach(int item in averageOptions)
darienf 20:6d2af70c92ab 179 {
darienf 20:6d2af70c92ab 180 cboAverageEcg.Items.Add(item.ToString());
darienf 20:6d2af70c92ab 181 }*/
darienf 20:6d2af70c92ab 182 //cboAverageEcg.SelectedIndex = 0;
darienf 20:6d2af70c92ab 183 //cboMaxScale.SelectedIndex = 1;
darienf 20:6d2af70c92ab 184
darienf 20:6d2af70c92ab 185 chartRtoR.ChartAreas[0].AxisY.Maximum = 100;
darienf 20:6d2af70c92ab 186
darienf 20:6d2af70c92ab 187 ecgInfo = new ChartInfo
darienf 20:6d2af70c92ab 188 {
darienf 20:6d2af70c92ab 189 SampleRate = 128, // Power on defaults for ECG
darienf 20:6d2af70c92ab 190 Length = 10,
darienf 20:6d2af70c92ab 191 Average = 1,
darienf 20:6d2af70c92ab 192 Shift = 6,
darienf 20:6d2af70c92ab 193 Gain = 20,
darienf 20:6d2af70c92ab 194 // ECG is 18 bits, with MSB as sign bit
darienf 20:6d2af70c92ab 195 Threshold = 0x1ffff,
darienf 20:6d2af70c92ab 196 Offset = 0x40000,
darienf 20:6d2af70c92ab 197 Chart = chartECG,
darienf 20:6d2af70c92ab 198 SeriesName = "Series",
darienf 20:6d2af70c92ab 199 };
darienf 20:6d2af70c92ab 200 rToRInfo = new ChartInfo
darienf 20:6d2af70c92ab 201 {
darienf 20:6d2af70c92ab 202 SampleRate = 128,
darienf 20:6d2af70c92ab 203 Length = 10,
darienf 20:6d2af70c92ab 204 Chart = chartECG,
darienf 20:6d2af70c92ab 205 SeriesName = "SeriesRToR",
darienf 20:6d2af70c92ab 206 };
darienf 20:6d2af70c92ab 207 bioZInfo = new ChartInfo
darienf 20:6d2af70c92ab 208 {
darienf 20:6d2af70c92ab 209 SampleRate = 64,
darienf 20:6d2af70c92ab 210 Length = 10,
darienf 20:6d2af70c92ab 211 Shift = 4,
darienf 20:6d2af70c92ab 212 Gain = 20,
darienf 20:6d2af70c92ab 213 // BioZ is 20 bits, with MSB as sign bit
darienf 20:6d2af70c92ab 214 Threshold = 0x7ffff,
darienf 20:6d2af70c92ab 215 Offset = 0x100000,
darienf 20:6d2af70c92ab 216 Chart = chartBioz,
darienf 20:6d2af70c92ab 217 SeriesName = "Series",
darienf 20:6d2af70c92ab 218 };
darienf 20:6d2af70c92ab 219 paceInfo = new ChartInfo
darienf 20:6d2af70c92ab 220 {
darienf 20:6d2af70c92ab 221 SampleRate = 65536 * ecgInfo.SampleRate, // 2 * fMSTR
darienf 20:6d2af70c92ab 222 Length = 10,
darienf 20:6d2af70c92ab 223 Average = 1,
darienf 20:6d2af70c92ab 224 Shift = 0, // Keep tag info
darienf 20:6d2af70c92ab 225 Chart = chartECG,
darienf 20:6d2af70c92ab 226 SeriesName = "SeriesPace",
darienf 20:6d2af70c92ab 227 };
darienf 20:6d2af70c92ab 228
darienf 20:6d2af70c92ab 229 NamedImage paceFalling = new NamedImage("PaceFallingImage", HealthSensorPlatform.Properties.Resources.pace_falling);
darienf 20:6d2af70c92ab 230 chartECG.Images.Add(paceFalling);
darienf 20:6d2af70c92ab 231 NamedImage paceRising = new NamedImage("PaceRisingImage", HealthSensorPlatform.Properties.Resources.pace_rising);
darienf 20:6d2af70c92ab 232 chartECG.Images.Add(paceRising);
darienf 20:6d2af70c92ab 233 #if CES_DEMO
darienf 20:6d2af70c92ab 234 //grpAverage.Visible = true;
darienf 20:6d2af70c92ab 235
darienf 20:6d2af70c92ab 236 hpf = new FirFilter();
darienf 20:6d2af70c92ab 237 //cboEcgHpf.SelectedIndex = 0;
darienf 20:6d2af70c92ab 238 #endif
darienf 20:6d2af70c92ab 239 }
darienf 20:6d2af70c92ab 240
darienf 20:6d2af70c92ab 241 /* Delegates */
darienf 20:6d2af70c92ab 242 public delegate InitArgs.EcgInitStart GetEcgInitArgs();
darienf 20:6d2af70c92ab 243 public delegate InitArgs.RToRInitStart GetRToRInitArgs();
darienf 20:6d2af70c92ab 244 public delegate InitArgs.BIOZInitStart GetBioZInitArgs();
darienf 20:6d2af70c92ab 245 public delegate InitArgs.PACEInitStart GetPaceInitArgs();
darienf 20:6d2af70c92ab 246 //public delegate void StreamingStartStopEventHandler(StreamingStartStopEventArgs e);
darienf 20:6d2af70c92ab 247
darienf 20:6d2af70c92ab 248 /* Events */
darienf 20:6d2af70c92ab 249 /// <summary>
darienf 20:6d2af70c92ab 250 /// Streaming event
darienf 20:6d2af70c92ab 251 /// </summary>
darienf 20:6d2af70c92ab 252 public event EventHandler<StreamingStartStopEventArgs> StreamingStartStop;
darienf 20:6d2af70c92ab 253
darienf 20:6d2af70c92ab 254 /* Enums */
darienf 20:6d2af70c92ab 255 public enum StreamDataType
darienf 20:6d2af70c92ab 256 {
darienf 20:6d2af70c92ab 257 Ecg,
darienf 20:6d2af70c92ab 258 RToR,
darienf 20:6d2af70c92ab 259 Pace,
darienf 20:6d2af70c92ab 260 BioZ
darienf 20:6d2af70c92ab 261 };
darienf 20:6d2af70c92ab 262
darienf 20:6d2af70c92ab 263 /* Properties */
darienf 20:6d2af70c92ab 264 public RPCSupport.RPCClient RPCClient
darienf 20:6d2af70c92ab 265 {
darienf 20:6d2af70c92ab 266 set
darienf 20:6d2af70c92ab 267 {
darienf 20:6d2af70c92ab 268 rpcClient = value;
darienf 20:6d2af70c92ab 269 //streamHandler = new EventHandler<PartialArrayIntAvailableEventArgs>(On_AppendChart);
darienf 20:6d2af70c92ab 270 //rpcClient.streaming.PartialArrayIntAvailable += streamHandler;
darienf 20:6d2af70c92ab 271 }
darienf 20:6d2af70c92ab 272 }
darienf 20:6d2af70c92ab 273 /*
darienf 20:6d2af70c92ab 274 public bool Stream
darienf 20:6d2af70c92ab 275 {
darienf 20:6d2af70c92ab 276 get
darienf 20:6d2af70c92ab 277 {
darienf 20:6d2af70c92ab 278 return stream;
darienf 20:6d2af70c92ab 279 }
darienf 20:6d2af70c92ab 280 set
darienf 20:6d2af70c92ab 281 {
darienf 20:6d2af70c92ab 282 stream = value;
darienf 20:6d2af70c92ab 283 if (stream == true)
darienf 20:6d2af70c92ab 284 rpcClient.streaming.PartialArrayIntAvailable += streamHandler;
darienf 20:6d2af70c92ab 285 else
darienf 20:6d2af70c92ab 286 rpcClient.streaming.PartialArrayIntAvailable -= streamHandler;
darienf 20:6d2af70c92ab 287 }
darienf 20:6d2af70c92ab 288 }
darienf 20:6d2af70c92ab 289 */
darienf 20:6d2af70c92ab 290 public bool Connected
darienf 20:6d2af70c92ab 291 {
darienf 20:6d2af70c92ab 292 get
darienf 20:6d2af70c92ab 293 {
darienf 20:6d2af70c92ab 294 return connected;
darienf 20:6d2af70c92ab 295 }
darienf 20:6d2af70c92ab 296 set
darienf 20:6d2af70c92ab 297 {
darienf 20:6d2af70c92ab 298 connected = value;
darienf 20:6d2af70c92ab 299 }
darienf 20:6d2af70c92ab 300 }
darienf 20:6d2af70c92ab 301 public bool EnableECG
darienf 20:6d2af70c92ab 302 {
darienf 20:6d2af70c92ab 303 get
darienf 20:6d2af70c92ab 304 {
darienf 20:6d2af70c92ab 305 return enableECG;
darienf 20:6d2af70c92ab 306 }
darienf 20:6d2af70c92ab 307 set
darienf 20:6d2af70c92ab 308 {
darienf 20:6d2af70c92ab 309 enableECG = value;
darienf 20:6d2af70c92ab 310 chartECG.Enabled = value;
darienf 20:6d2af70c92ab 311 }
darienf 20:6d2af70c92ab 312 }
darienf 20:6d2af70c92ab 313 public bool EnableRToR
darienf 20:6d2af70c92ab 314 {
darienf 20:6d2af70c92ab 315 get
darienf 20:6d2af70c92ab 316 {
darienf 20:6d2af70c92ab 317 return enableRToR;
darienf 20:6d2af70c92ab 318 }
darienf 20:6d2af70c92ab 319 set
darienf 20:6d2af70c92ab 320 {
darienf 20:6d2af70c92ab 321 enableRToR = value;
darienf 20:6d2af70c92ab 322 chartRtoR.Enabled = value;
darienf 20:6d2af70c92ab 323 grpBxHeartRate.Enabled = value;
darienf 20:6d2af70c92ab 324 }
darienf 20:6d2af70c92ab 325 }
darienf 20:6d2af70c92ab 326 public bool EnableBioZ
darienf 20:6d2af70c92ab 327 {
darienf 20:6d2af70c92ab 328 get
darienf 20:6d2af70c92ab 329 {
darienf 20:6d2af70c92ab 330 return enableBioZ;
darienf 20:6d2af70c92ab 331 }
darienf 20:6d2af70c92ab 332 set
darienf 20:6d2af70c92ab 333 {
darienf 20:6d2af70c92ab 334 enableBioZ = value;
darienf 20:6d2af70c92ab 335 chartBioz.Enabled = value;
darienf 20:6d2af70c92ab 336 }
darienf 20:6d2af70c92ab 337 }
darienf 20:6d2af70c92ab 338 public bool EnablePace
darienf 20:6d2af70c92ab 339 {
darienf 20:6d2af70c92ab 340 get
darienf 20:6d2af70c92ab 341 {
darienf 20:6d2af70c92ab 342 return enablePace;
darienf 20:6d2af70c92ab 343 }
darienf 20:6d2af70c92ab 344 set
darienf 20:6d2af70c92ab 345 {
darienf 20:6d2af70c92ab 346 enablePace = value;
darienf 20:6d2af70c92ab 347 chartPace.Enabled = value;
darienf 20:6d2af70c92ab 348 }
darienf 20:6d2af70c92ab 349 }
darienf 20:6d2af70c92ab 350 public bool EnableDCLeadOff
darienf 20:6d2af70c92ab 351 {
darienf 20:6d2af70c92ab 352 get
darienf 20:6d2af70c92ab 353 {
darienf 20:6d2af70c92ab 354 return grpBxDCLeadOff.Enabled;
darienf 20:6d2af70c92ab 355 }
darienf 20:6d2af70c92ab 356 set
darienf 20:6d2af70c92ab 357 {
darienf 20:6d2af70c92ab 358 grpBxDCLeadOff.Enabled = value;
darienf 20:6d2af70c92ab 359 }
darienf 20:6d2af70c92ab 360
darienf 20:6d2af70c92ab 361 }
darienf 20:6d2af70c92ab 362 public bool EnableEcgDCLeadOff { get; set; }
darienf 20:6d2af70c92ab 363 public bool EnableBioZOverUnderRange
darienf 20:6d2af70c92ab 364 {
darienf 20:6d2af70c92ab 365 get
darienf 20:6d2af70c92ab 366 {
darienf 20:6d2af70c92ab 367 return grpBxBioZOverUnderRange.Enabled;
darienf 20:6d2af70c92ab 368 }
darienf 20:6d2af70c92ab 369 set
darienf 20:6d2af70c92ab 370 {
darienf 20:6d2af70c92ab 371 grpBxBioZOverUnderRange.Enabled = value;
darienf 20:6d2af70c92ab 372 }
darienf 20:6d2af70c92ab 373 }
darienf 20:6d2af70c92ab 374
darienf 20:6d2af70c92ab 375 public bool BioZMilliOhmRange
darienf 20:6d2af70c92ab 376 {
darienf 20:6d2af70c92ab 377 get
darienf 20:6d2af70c92ab 378 {
darienf 20:6d2af70c92ab 379 return (bioZRangeMultiplier == 1000);
darienf 20:6d2af70c92ab 380 }
darienf 20:6d2af70c92ab 381
darienf 20:6d2af70c92ab 382 set
darienf 20:6d2af70c92ab 383 {
darienf 20:6d2af70c92ab 384 if (value)
darienf 20:6d2af70c92ab 385 {
darienf 20:6d2af70c92ab 386 bioZRangeMultiplier = 1000;
darienf 20:6d2af70c92ab 387 chartBioz.ChartAreas["ChartArea"].AxisY.Title = "Bioz (m‎Ω)";
darienf 20:6d2af70c92ab 388 }
darienf 20:6d2af70c92ab 389 else
darienf 20:6d2af70c92ab 390 {
darienf 20:6d2af70c92ab 391 bioZRangeMultiplier = 1;
darienf 20:6d2af70c92ab 392 chartBioz.ChartAreas["ChartArea"].AxisY.Title = "Bioz (‎Ω)";
darienf 20:6d2af70c92ab 393 }
darienf 20:6d2af70c92ab 394 }
darienf 20:6d2af70c92ab 395 }
darienf 20:6d2af70c92ab 396
darienf 20:6d2af70c92ab 397 public double SampleRateEcg // Human readable sample rate
darienf 20:6d2af70c92ab 398 {
darienf 20:6d2af70c92ab 399 get
darienf 20:6d2af70c92ab 400 {
darienf 20:6d2af70c92ab 401 return ecgInfo.SampleRate;
darienf 20:6d2af70c92ab 402 }
darienf 20:6d2af70c92ab 403 set
darienf 20:6d2af70c92ab 404 {
darienf 20:6d2af70c92ab 405 ecgInfo.SampleRate = value;
darienf 20:6d2af70c92ab 406 //rToRInfo.SampleRate = value;
darienf 20:6d2af70c92ab 407 paceInfo.SampleRate = MasterClockFrequency * 2 * value;
darienf 20:6d2af70c92ab 408 }
darienf 20:6d2af70c92ab 409 }
darienf 20:6d2af70c92ab 410 public double SampleRateBioZ // Human readable sample rate
darienf 20:6d2af70c92ab 411 {
darienf 20:6d2af70c92ab 412 get
darienf 20:6d2af70c92ab 413 {
darienf 20:6d2af70c92ab 414 return bioZInfo.SampleRate;
darienf 20:6d2af70c92ab 415 }
darienf 20:6d2af70c92ab 416 set
darienf 20:6d2af70c92ab 417 {
darienf 20:6d2af70c92ab 418 bioZInfo.SampleRate = value;
darienf 20:6d2af70c92ab 419 }
darienf 20:6d2af70c92ab 420 }
darienf 20:6d2af70c92ab 421 public int GainECG // Human readable gain
darienf 20:6d2af70c92ab 422 {
darienf 20:6d2af70c92ab 423 get
darienf 20:6d2af70c92ab 424 {
darienf 20:6d2af70c92ab 425 return ecgInfo.Gain;
darienf 20:6d2af70c92ab 426 }
darienf 20:6d2af70c92ab 427 set
darienf 20:6d2af70c92ab 428 {
darienf 20:6d2af70c92ab 429 ecgInfo.Gain = value;
darienf 20:6d2af70c92ab 430 }
darienf 20:6d2af70c92ab 431 }
darienf 20:6d2af70c92ab 432 public int GainBioZ // Human readable gain
darienf 20:6d2af70c92ab 433 {
darienf 20:6d2af70c92ab 434 get
darienf 20:6d2af70c92ab 435 {
darienf 20:6d2af70c92ab 436 return bioZInfo.Gain;
darienf 20:6d2af70c92ab 437 }
darienf 20:6d2af70c92ab 438 set
darienf 20:6d2af70c92ab 439 {
darienf 20:6d2af70c92ab 440 bioZInfo.Gain = value;
darienf 20:6d2af70c92ab 441 }
darienf 20:6d2af70c92ab 442 }
darienf 20:6d2af70c92ab 443 public int CurrentBioZ // Human readable bioZ current generator magnitude
darienf 20:6d2af70c92ab 444 {
darienf 20:6d2af70c92ab 445 get
darienf 20:6d2af70c92ab 446 {
darienf 20:6d2af70c92ab 447 return bioZInfo.CurrentGenerator;
darienf 20:6d2af70c92ab 448 }
darienf 20:6d2af70c92ab 449 set
darienf 20:6d2af70c92ab 450 {
darienf 20:6d2af70c92ab 451 bioZInfo.CurrentGenerator = value;
darienf 20:6d2af70c92ab 452 }
darienf 20:6d2af70c92ab 453 }
darienf 20:6d2af70c92ab 454 /// <summary>
darienf 20:6d2af70c92ab 455 /// This value is t_RES = 1 / (2 * fMSTR) = 1 / (2 * 32768). For R-to-R the LSB time is 512*t_RES, while for
darienf 20:6d2af70c92ab 456 /// PACE, the value is t_RES.
darienf 20:6d2af70c92ab 457 /// </summary>
darienf 20:6d2af70c92ab 458 public double TimeResolution
darienf 20:6d2af70c92ab 459 {
darienf 20:6d2af70c92ab 460 get
darienf 20:6d2af70c92ab 461 {
darienf 20:6d2af70c92ab 462 return timeResolution;
darienf 20:6d2af70c92ab 463 }
darienf 20:6d2af70c92ab 464 }
darienf 20:6d2af70c92ab 465
darienf 20:6d2af70c92ab 466 public ChartInfo EcgInfo { get { return ecgInfo; } }
darienf 20:6d2af70c92ab 467 public ChartInfo RToRInfo { get { return rToRInfo; } }
darienf 20:6d2af70c92ab 468 public ChartInfo BioZInfo { get { return bioZInfo; } }
darienf 20:6d2af70c92ab 469 public ChartInfo PaceInfo { get { return paceInfo; } }
darienf 20:6d2af70c92ab 470
darienf 20:6d2af70c92ab 471 public InitArgs.EcgInitStart EcgArgs { get { return ecgArgs; } }
darienf 20:6d2af70c92ab 472 public InitArgs.RToRInitStart RToRArgs { get { return rtorArgs; } }
darienf 20:6d2af70c92ab 473
darienf 20:6d2af70c92ab 474 public int MasterClockField { get { return frequencyMasterField; } }
darienf 20:6d2af70c92ab 475 public int FrequencyMasterField
darienf 20:6d2af70c92ab 476 {
darienf 20:6d2af70c92ab 477 get
darienf 20:6d2af70c92ab 478 {
darienf 20:6d2af70c92ab 479 return frequencyMasterField;
darienf 20:6d2af70c92ab 480 }
darienf 20:6d2af70c92ab 481
darienf 20:6d2af70c92ab 482 set
darienf 20:6d2af70c92ab 483 {
darienf 20:6d2af70c92ab 484 frequencyMasterField = value;
darienf 20:6d2af70c92ab 485 masterClockFrequency = clockFreq[frequencyMasterField];
darienf 20:6d2af70c92ab 486 paceInfo.SampleRate = 2 * masterClockFrequency;
darienf 20:6d2af70c92ab 487 rToRInfo.SampleRate = masterClockFrequency / 256.0;
darienf 20:6d2af70c92ab 488 timeResolution = 1.0 / (2 * masterClockFrequency);
darienf 20:6d2af70c92ab 489 }
darienf 20:6d2af70c92ab 490 }
darienf 20:6d2af70c92ab 491 public double MasterClockFrequency
darienf 20:6d2af70c92ab 492 {
darienf 20:6d2af70c92ab 493 get
darienf 20:6d2af70c92ab 494 {
darienf 20:6d2af70c92ab 495 return masterClockFrequency;
darienf 20:6d2af70c92ab 496 }
darienf 20:6d2af70c92ab 497 /*
darienf 20:6d2af70c92ab 498 set
darienf 20:6d2af70c92ab 499 {
darienf 20:6d2af70c92ab 500 masterClockFrequency = value;
darienf 20:6d2af70c92ab 501 paceInfo.SampleRate = 2 * value;
darienf 20:6d2af70c92ab 502 TimeResolution = 1 / (2 * value);
darienf 20:6d2af70c92ab 503 }*/
darienf 20:6d2af70c92ab 504 }
darienf 20:6d2af70c92ab 505
darienf 20:6d2af70c92ab 506 public int EcgDecimationDelay
darienf 20:6d2af70c92ab 507 {
darienf 20:6d2af70c92ab 508 get
darienf 20:6d2af70c92ab 509 {
darienf 20:6d2af70c92ab 510 int fmstr = frequencyMasterField;
darienf 20:6d2af70c92ab 511 int ecgRate = ecgArgs.Rate;
darienf 20:6d2af70c92ab 512 int lpf = ecgArgs.Dlpf > 0 ? 1 : 0;
darienf 20:6d2af70c92ab 513
darienf 20:6d2af70c92ab 514 return ecgDecimationDelay[fmstr, ecgRate, lpf];
darienf 20:6d2af70c92ab 515 }
darienf 20:6d2af70c92ab 516 }
darienf 20:6d2af70c92ab 517 public int RToRDelay
darienf 20:6d2af70c92ab 518 {
darienf 20:6d2af70c92ab 519 get
darienf 20:6d2af70c92ab 520 {
darienf 20:6d2af70c92ab 521
darienf 20:6d2af70c92ab 522 return 5376 + 3370 + 256 * RToRWindowField;
darienf 20:6d2af70c92ab 523 }
darienf 20:6d2af70c92ab 524 }
darienf 20:6d2af70c92ab 525
darienf 20:6d2af70c92ab 526 public Chart ChartECG { get { return chartECG; } } // Testing
darienf 20:6d2af70c92ab 527 public IHspSetting HspSetting
darienf 20:6d2af70c92ab 528 {
darienf 20:6d2af70c92ab 529 get;
darienf 20:6d2af70c92ab 530 set;
darienf 20:6d2af70c92ab 531 }
darienf 20:6d2af70c92ab 532
darienf 20:6d2af70c92ab 533 private void EcgView_Load(object sender, EventArgs e)
darienf 20:6d2af70c92ab 534 {
darienf 20:6d2af70c92ab 535 InitChart();
darienf 20:6d2af70c92ab 536 }
darienf 20:6d2af70c92ab 537
darienf 20:6d2af70c92ab 538 String ValueToBits(int value, int width)
darienf 20:6d2af70c92ab 539 {
darienf 20:6d2af70c92ab 540 String str = "";
darienf 20:6d2af70c92ab 541 String val = "";
darienf 20:6d2af70c92ab 542 int mask = 1;
darienf 20:6d2af70c92ab 543 for (int i = 0; i < width; i++)
darienf 20:6d2af70c92ab 544 {
darienf 20:6d2af70c92ab 545 if ((mask & value) == mask)
darienf 20:6d2af70c92ab 546 {
darienf 20:6d2af70c92ab 547 val = "1";
darienf 20:6d2af70c92ab 548 }
darienf 20:6d2af70c92ab 549 else
darienf 20:6d2af70c92ab 550 {
darienf 20:6d2af70c92ab 551 val = "0";
darienf 20:6d2af70c92ab 552 }
darienf 20:6d2af70c92ab 553 mask = mask << 1;
darienf 20:6d2af70c92ab 554 str = val + str;
darienf 20:6d2af70c92ab 555 }
darienf 20:6d2af70c92ab 556 return str;
darienf 20:6d2af70c92ab 557 }
darienf 20:6d2af70c92ab 558
darienf 20:6d2af70c92ab 559 String[] ValueToBitStringArray(int width)
darienf 20:6d2af70c92ab 560 {
darienf 20:6d2af70c92ab 561 List<String> stringList = new List<string>();
darienf 20:6d2af70c92ab 562 for (int i = 0; i < Math.Pow(2, width); i++)
darienf 20:6d2af70c92ab 563 {
darienf 20:6d2af70c92ab 564 stringList.Add(ValueToBits(i, width));
darienf 20:6d2af70c92ab 565 }
darienf 20:6d2af70c92ab 566 return stringList.ToArray();
darienf 20:6d2af70c92ab 567 }
darienf 20:6d2af70c92ab 568
darienf 20:6d2af70c92ab 569 private void InitChart()
darienf 20:6d2af70c92ab 570 {
darienf 20:6d2af70c92ab 571 // Reset Averaging
darienf 20:6d2af70c92ab 572 //averageEcgSum = 0;
darienf 20:6d2af70c92ab 573 //averageEcgCount = 0;
darienf 20:6d2af70c92ab 574
darienf 20:6d2af70c92ab 575 //ecgInfo.Average = averageOptions[cboAverageEcg.SelectedIndex];
darienf 20:6d2af70c92ab 576 ecgInfo.Average = 1;
darienf 20:6d2af70c92ab 577
darienf 20:6d2af70c92ab 578 // Rest Pace Tags
darienf 20:6d2af70c92ab 579 paceTag.Clear();
darienf 20:6d2af70c92ab 580
darienf 20:6d2af70c92ab 581 //UpdateChart(chartPace, new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
darienf 20:6d2af70c92ab 582 //paceData = new PaceData(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
darienf 20:6d2af70c92ab 583 //UpdateChart(StreamDataType.Ecg, new int[] {1});
darienf 20:6d2af70c92ab 584 DisplayEcg(new double[] { 0 }, null, null);
darienf 20:6d2af70c92ab 585 //UpdateChart(chartECG, "SeriesRToR", new int[] {0});
darienf 20:6d2af70c92ab 586 //UpdateChart(StreamDataType.BioZ, new int[] {0});
darienf 20:6d2af70c92ab 587 DisplayBioZ(new double[] { 0 });
darienf 20:6d2af70c92ab 588 UpdateChartAxis(chartECG);
darienf 20:6d2af70c92ab 589 //UpdateChartAxis(chartRtoR);
darienf 20:6d2af70c92ab 590 UpdateChartAxis(chartBioz);
darienf 20:6d2af70c92ab 591 //UpdateChartAxis(chartPace);
darienf 20:6d2af70c92ab 592
darienf 20:6d2af70c92ab 593 paceData = null;
darienf 20:6d2af70c92ab 594
darienf 20:6d2af70c92ab 595 //chartRtoR.ChartAreas[0].AxisY.Maximum = 100;
darienf 20:6d2af70c92ab 596 }
darienf 20:6d2af70c92ab 597
darienf 20:6d2af70c92ab 598 private void ResetChart()
darienf 20:6d2af70c92ab 599 {
darienf 20:6d2af70c92ab 600 paceData = null;
darienf 20:6d2af70c92ab 601 }
darienf 20:6d2af70c92ab 602
darienf 20:6d2af70c92ab 603 private void UpdateChartAxis(System.Windows.Forms.DataVisualization.Charting.Chart chart)
darienf 20:6d2af70c92ab 604 {
darienf 20:6d2af70c92ab 605 ChartInfo chartInfo = new ChartInfo();
darienf 20:6d2af70c92ab 606
darienf 20:6d2af70c92ab 607 if (chart.Name == "chartECG")
darienf 20:6d2af70c92ab 608 {
darienf 20:6d2af70c92ab 609 chartInfo = ecgInfo;
darienf 20:6d2af70c92ab 610 }
darienf 20:6d2af70c92ab 611 else if (chart.Name == "chartBioz")
darienf 20:6d2af70c92ab 612 {
darienf 20:6d2af70c92ab 613 chartInfo = bioZInfo;
darienf 20:6d2af70c92ab 614 }
darienf 20:6d2af70c92ab 615 else if (chart.Name == "chartPace")
darienf 20:6d2af70c92ab 616 {
darienf 20:6d2af70c92ab 617 chartInfo = paceInfo;
darienf 20:6d2af70c92ab 618 }
darienf 20:6d2af70c92ab 619 else if (chart.Name == "chartRtoR")
darienf 20:6d2af70c92ab 620 {
darienf 20:6d2af70c92ab 621 chartInfo = rToRInfo;
darienf 20:6d2af70c92ab 622 }
darienf 20:6d2af70c92ab 623
darienf 20:6d2af70c92ab 624 chart.SuspendLayout();
darienf 20:6d2af70c92ab 625 chart.ChartAreas[0].AxisX.Minimum = 0;
darienf 20:6d2af70c92ab 626 chart.ChartAreas[0].AxisX.Maximum = chartInfo.Points;
darienf 20:6d2af70c92ab 627 chart.ChartAreas[0].AxisX.Interval = (float)chartInfo.Points / chartInfo.Length;
darienf 20:6d2af70c92ab 628
darienf 20:6d2af70c92ab 629 if (chart.Name != "chartRtoR")
darienf 20:6d2af70c92ab 630 {
darienf 20:6d2af70c92ab 631 chart.ChartAreas[0].AxisX.CustomLabels.Clear();
darienf 20:6d2af70c92ab 632 // Set X-axis range in seconds
darienf 20:6d2af70c92ab 633 for (int i = 0; i < 11; i ++ )
darienf 20:6d2af70c92ab 634 {
darienf 20:6d2af70c92ab 635 chart.ChartAreas[0].AxisX.CustomLabels.Add(Math.Ceiling(((float)chartInfo.SampleRate / chartInfo.Average) * (2 * i - 1) / 2),
darienf 20:6d2af70c92ab 636 Math.Floor(((float)chartInfo.SampleRate / chartInfo.Average) * (2 * i + 1) / 2), i.ToString());
darienf 20:6d2af70c92ab 637 }
darienf 20:6d2af70c92ab 638 }
darienf 20:6d2af70c92ab 639
darienf 20:6d2af70c92ab 640 chart.ResumeLayout();
darienf 20:6d2af70c92ab 641 }
darienf 20:6d2af70c92ab 642
darienf 20:6d2af70c92ab 643 public void DisplayEcg(double[] ecg, PacePoint[] pace, double[] rToR)
darienf 20:6d2af70c92ab 644 {
darienf 20:6d2af70c92ab 645 List<double> xList = new List<double>();
darienf 20:6d2af70c92ab 646 List<double> yList = new List<double>();
darienf 20:6d2af70c92ab 647 List<double> xListFalling = new List<double>();
darienf 20:6d2af70c92ab 648 List<double> yListFalling = new List<double>();
darienf 20:6d2af70c92ab 649
darienf 20:6d2af70c92ab 650 int offset = chartECG.Series["Series"].Points.Count; // Pace Offset
darienf 20:6d2af70c92ab 651
darienf 20:6d2af70c92ab 652 chartECG.SuspendLayout();
darienf 20:6d2af70c92ab 653
darienf 20:6d2af70c92ab 654 for(int i = 0; i < ecg.Length; i++ )
darienf 20:6d2af70c92ab 655 {
darienf 20:6d2af70c92ab 656 chartECG.Series["Series"].Points.Add(ecg[i]);
darienf 20:6d2af70c92ab 657 }
darienf 20:6d2af70c92ab 658
darienf 20:6d2af70c92ab 659 if (pace != null)
darienf 20:6d2af70c92ab 660 {
darienf 20:6d2af70c92ab 661 // Shift Old Points - Rising
darienf 20:6d2af70c92ab 662 for (int i = 0; i < chartECG.Series["SeriesPace"].Points.Count; i++)
darienf 20:6d2af70c92ab 663 {
darienf 20:6d2af70c92ab 664 double xValue = chartECG.Series["SeriesPace"].Points[i].XValue;
darienf 20:6d2af70c92ab 665
darienf 20:6d2af70c92ab 666 if (offset > ecgInfo.Points) // Do not shift until chart is full
darienf 20:6d2af70c92ab 667 xValue -= ecg.Length;
darienf 20:6d2af70c92ab 668
darienf 20:6d2af70c92ab 669 if (xValue >= 0)
darienf 20:6d2af70c92ab 670 {
darienf 20:6d2af70c92ab 671 xList.Add(xValue);
darienf 20:6d2af70c92ab 672 yList.Add(chartECG.Series["SeriesPace"].Points[i].YValues[0]);
darienf 20:6d2af70c92ab 673 }
darienf 20:6d2af70c92ab 674 }
darienf 20:6d2af70c92ab 675 // Shift Old Points - Falling
darienf 20:6d2af70c92ab 676 for (int i = 0; i < chartECG.Series["SeriesPaceFalling"].Points.Count; i++ )
darienf 20:6d2af70c92ab 677 {
darienf 20:6d2af70c92ab 678 double xValueFalling = chartECG.Series["SeriesPaceFalling"].Points[i].XValue;
darienf 20:6d2af70c92ab 679
darienf 20:6d2af70c92ab 680 if (offset > ecgInfo.Points)
darienf 20:6d2af70c92ab 681 xValueFalling -= ecg.Length;
darienf 20:6d2af70c92ab 682
darienf 20:6d2af70c92ab 683 if (xValueFalling >= 0)
darienf 20:6d2af70c92ab 684 {
darienf 20:6d2af70c92ab 685 xListFalling.Add(xValueFalling);
darienf 20:6d2af70c92ab 686 yListFalling.Add(chartECG.Series["SeriesPaceFalling"].Points[i].YValues[0]);
darienf 20:6d2af70c92ab 687 }
darienf 20:6d2af70c92ab 688 }
darienf 20:6d2af70c92ab 689
darienf 20:6d2af70c92ab 690 // Add New Points
darienf 20:6d2af70c92ab 691 for (int i = 0; i < pace.Length; i++)
darienf 20:6d2af70c92ab 692 {
darienf 20:6d2af70c92ab 693 if (pace[i].Polarity == true)
darienf 20:6d2af70c92ab 694 {
darienf 20:6d2af70c92ab 695 //xList.Add(pace[i].Time + offset);
darienf 20:6d2af70c92ab 696 //yList.Add(0.05);
darienf 20:6d2af70c92ab 697 chartECG.Series["SeriesPace"].Points.AddXY(pace[i].Time + offset, 0.05*(0+1));
darienf 20:6d2af70c92ab 698 //System.Diagnostics.Debug.Print("Rising: " + (pace[i].Time + offset));
darienf 20:6d2af70c92ab 699 }
darienf 20:6d2af70c92ab 700 else
darienf 20:6d2af70c92ab 701 {
darienf 20:6d2af70c92ab 702 //xListFalling.Add(pace[i].Time + offset);
darienf 20:6d2af70c92ab 703 //yListFalling.Add(-0.05);
darienf 20:6d2af70c92ab 704 chartECG.Series["SeriesPaceFalling"].Points.AddXY(pace[i].Time + offset, -0.08*(0+1));
darienf 20:6d2af70c92ab 705 //System.Diagnostics.Debug.Print("Falling: " + (pace[i].Time + offset));
darienf 20:6d2af70c92ab 706 }
darienf 20:6d2af70c92ab 707 }
darienf 20:6d2af70c92ab 708
darienf 20:6d2af70c92ab 709 // Bind data to chart
darienf 20:6d2af70c92ab 710 //chartECG.Series["SeriesPace"].Points.DataBindXY(xList, yList);
darienf 20:6d2af70c92ab 711 //chartECG.Series["SeriesPaceFalling"].Points.DataBindXY(xListFalling, yListFalling);
darienf 20:6d2af70c92ab 712 }
darienf 20:6d2af70c92ab 713
darienf 20:6d2af70c92ab 714 UpdateChartFormat(StreamDataType.Ecg, ecgInfo);
darienf 20:6d2af70c92ab 715 //if (rToR != null) // Remove extra points
darienf 20:6d2af70c92ab 716 // UpdateChartFormat(StreamDataType.RToR, rToRInfo);
darienf 20:6d2af70c92ab 717 if (pace != null) // Not needed anymore due to new plot style
darienf 20:6d2af70c92ab 718 UpdateChartFormat(StreamDataType.Pace, PaceInfo, offset + ecg.Length - ecgInfo.Points);
darienf 20:6d2af70c92ab 719 chartECG.ResumeLayout();
darienf 20:6d2af70c92ab 720 }
darienf 20:6d2af70c92ab 721
darienf 20:6d2af70c92ab 722 public void DisplayBioZ(double[] bioZ)
darienf 20:6d2af70c92ab 723 {
darienf 20:6d2af70c92ab 724 chartBioz.SuspendLayout();
darienf 20:6d2af70c92ab 725
darienf 20:6d2af70c92ab 726 for(int i = 0; i < bioZ.Length; i++)
darienf 20:6d2af70c92ab 727 {
darienf 20:6d2af70c92ab 728 chartBioz.Series["Series"].Points.Add(bioZ[i] * bioZRangeMultiplier);
darienf 20:6d2af70c92ab 729 }
darienf 20:6d2af70c92ab 730
darienf 20:6d2af70c92ab 731 UpdateChartFormat(StreamDataType.BioZ, bioZInfo);
darienf 20:6d2af70c92ab 732
darienf 20:6d2af70c92ab 733 chartBioz.ResumeLayout();
darienf 20:6d2af70c92ab 734 }
darienf 20:6d2af70c92ab 735
darienf 20:6d2af70c92ab 736 public double DisplayRToR(int rToR)
darienf 20:6d2af70c92ab 737 {
darienf 20:6d2af70c92ab 738 double rate;
darienf 20:6d2af70c92ab 739 int rToREcg;
darienf 20:6d2af70c92ab 740
darienf 20:6d2af70c92ab 741 long now = DateTime.Now.Ticks;
darienf 20:6d2af70c92ab 742
darienf 20:6d2af70c92ab 743 if (rToR == RToRMaxValue) // Ignore the max value, counter overflow condition
darienf 20:6d2af70c92ab 744 return 0;
darienf 20:6d2af70c92ab 745
darienf 20:6d2af70c92ab 746 rate = rToRCalculator.BeatsPerMinute(rToR); // RToRBeatsPerMinute(rToR);
darienf 20:6d2af70c92ab 747
darienf 20:6d2af70c92ab 748 if (heartRateList.Count < 10)
darienf 20:6d2af70c92ab 749 heartRateList.Add(rate);
darienf 20:6d2af70c92ab 750 else if (heartRateList.Count == 10)
darienf 20:6d2af70c92ab 751 {
darienf 20:6d2af70c92ab 752 heartRateList.RemoveAt(0);
darienf 20:6d2af70c92ab 753 heartRateList.Add(rate);
darienf 20:6d2af70c92ab 754
darienf 20:6d2af70c92ab 755 double sum = 0;
darienf 20:6d2af70c92ab 756 foreach (double d in heartRateList)
darienf 20:6d2af70c92ab 757 sum += d;
darienf 20:6d2af70c92ab 758
darienf 20:6d2af70c92ab 759 lblHeartRateAverage10.Text = (sum / 10).ToString("F1");
darienf 20:6d2af70c92ab 760
darienf 20:6d2af70c92ab 761 }
darienf 20:6d2af70c92ab 762
darienf 20:6d2af70c92ab 763 lblHeartRateBeatToBeat.Text = rate.ToString("F1");
darienf 20:6d2af70c92ab 764
darienf 20:6d2af70c92ab 765 if (heartRateList.Count != 1)
darienf 20:6d2af70c92ab 766 {
darienf 20:6d2af70c92ab 767 rToREcg = rToRCalculator.EcgPoints(rToR, false); // RToREcgPoints(rToR, false);
darienf 20:6d2af70c92ab 768 }
darienf 20:6d2af70c92ab 769 else
darienf 20:6d2af70c92ab 770 {
darienf 20:6d2af70c92ab 771 // First Point delay by Tdrtor_ecg
darienf 20:6d2af70c92ab 772 //rToREcg = RToREcgPoints(rToR, true) + 1; // DEBUG 3 extra 0x07 are sent from FW at start of stream, 1 extra point for GUI chart init
darienf 20:6d2af70c92ab 773 int rToRInEcg = rToRCalculator.EcgPoints(rToR, true);
darienf 20:6d2af70c92ab 774 rToREcg = rToRInEcg + 1;
darienf 20:6d2af70c92ab 775 }
darienf 20:6d2af70c92ab 776
darienf 20:6d2af70c92ab 777 if (lastRToRTime < 0)
darienf 20:6d2af70c92ab 778 lastRToRTime = now;
darienf 20:6d2af70c92ab 779 else
darienf 20:6d2af70c92ab 780 {
darienf 20:6d2af70c92ab 781 long diff = now - lastRToRTime;
darienf 20:6d2af70c92ab 782 TimeSpan elaspedTicks = new TimeSpan(diff);
darienf 20:6d2af70c92ab 783
darienf 20:6d2af70c92ab 784 int fullScaleTime = (int)(Math.Pow(2, 14) * 512 * TimeResolution + 0.5);
darienf 20:6d2af70c92ab 785
darienf 20:6d2af70c92ab 786 if (elaspedTicks.TotalSeconds > fullScaleTime)
darienf 20:6d2af70c92ab 787 {
darienf 20:6d2af70c92ab 788 int overflowCount = (int)(elaspedTicks.TotalSeconds / fullScaleTime);
darienf 20:6d2af70c92ab 789
darienf 20:6d2af70c92ab 790 for (int i = 0; i < overflowCount; i++ )
darienf 20:6d2af70c92ab 791 rToREcg += rToRCalculator.EcgPoints(EcgDelay.RToRMaxValue, false); //RToREcgPoints(0x3FFF, false);
darienf 20:6d2af70c92ab 792 }
darienf 20:6d2af70c92ab 793
darienf 20:6d2af70c92ab 794 lastRToRTime = now;
darienf 20:6d2af70c92ab 795 }
darienf 20:6d2af70c92ab 796
darienf 20:6d2af70c92ab 797 for (int i = 1; i < rToREcg - rToRRemoveOffset; i++ )
darienf 20:6d2af70c92ab 798 {
darienf 20:6d2af70c92ab 799 chartECG.Series["SeriesRToR"].Points.Add(-5000);
darienf 20:6d2af70c92ab 800 }
darienf 20:6d2af70c92ab 801 int rToRCount = chartECG.Series["SeriesRToR"].Points.Count;
darienf 20:6d2af70c92ab 802
darienf 20:6d2af70c92ab 803 if (rToRCount < chartECG.Series["Series"].Points.Count)
darienf 20:6d2af70c92ab 804 chartECG.Series["SeriesRToR"].Points.Add(chartECG.Series["Series"].Points[rToRCount].YValues[0]); // R to R comes in after ECG
darienf 20:6d2af70c92ab 805 else
darienf 20:6d2af70c92ab 806 chartECG.Series["SeriesRToR"].Points.Add(0); // R to R comes in faster than ECG, add as 0 for now
darienf 20:6d2af70c92ab 807
darienf 20:6d2af70c92ab 808 rToRRemoveOffset = 0;
darienf 20:6d2af70c92ab 809
darienf 20:6d2af70c92ab 810 return rate;
darienf 20:6d2af70c92ab 811 }
darienf 20:6d2af70c92ab 812
darienf 20:6d2af70c92ab 813 public void BioZFunction(bool enable)
darienf 20:6d2af70c92ab 814 {
darienf 20:6d2af70c92ab 815 chartBioz.Visible = enable;
darienf 20:6d2af70c92ab 816
darienf 20:6d2af70c92ab 817 if (enable == false)
darienf 20:6d2af70c92ab 818 {
darienf 20:6d2af70c92ab 819 //tableLayoutPanelCharts.RowCount = 1;
darienf 20:6d2af70c92ab 820 tableLayoutPanelCharts.RowStyles[1] = new RowStyle(SizeType.Percent, 0);
darienf 20:6d2af70c92ab 821 tableLayoutPanelCharts.RowStyles[0] = new RowStyle(SizeType.Percent, 100);
darienf 20:6d2af70c92ab 822 }
darienf 20:6d2af70c92ab 823 else
darienf 20:6d2af70c92ab 824 {
darienf 20:6d2af70c92ab 825 tableLayoutPanelCharts.RowStyles[0] = new RowStyle(SizeType.Percent, 50);
darienf 20:6d2af70c92ab 826 tableLayoutPanelCharts.RowStyles[1] = new RowStyle(SizeType.Percent, 50);
darienf 20:6d2af70c92ab 827 }
darienf 20:6d2af70c92ab 828
darienf 20:6d2af70c92ab 829 }
darienf 20:6d2af70c92ab 830
darienf 20:6d2af70c92ab 831
darienf 20:6d2af70c92ab 832 /*
darienf 20:6d2af70c92ab 833 public double RToRBeatsPerMinute(int rToRCode)
darienf 20:6d2af70c92ab 834 {
darienf 20:6d2af70c92ab 835 return 60 * 1000/ RToRMillisecond(rToRCode);
darienf 20:6d2af70c92ab 836 }
darienf 20:6d2af70c92ab 837
darienf 20:6d2af70c92ab 838 public double RToRMillisecond(int rToRCode)
darienf 20:6d2af70c92ab 839 {
darienf 20:6d2af70c92ab 840 return rToRCode * 512.0 * 1000 / (2 * MasterClockFrequency);
darienf 20:6d2af70c92ab 841 }
darienf 20:6d2af70c92ab 842
darienf 20:6d2af70c92ab 843 public int RToREcgPoints(int rToR, bool first)
darienf 20:6d2af70c92ab 844 {
darienf 20:6d2af70c92ab 845 double sampleRateRToR = MasterClockFrequency / 256;
darienf 20:6d2af70c92ab 846 int rToRDifferentialDelay = RToRDelay - EcgDecimationDelay;
darienf 20:6d2af70c92ab 847
darienf 20:6d2af70c92ab 848 double rToRInEcgSamples;
darienf 20:6d2af70c92ab 849 int rToRInEcgSamplesInt;
darienf 20:6d2af70c92ab 850
darienf 20:6d2af70c92ab 851 if (first)
darienf 20:6d2af70c92ab 852 {
darienf 20:6d2af70c92ab 853 rToRInEcgSamples = (rToR - rToRDifferentialDelay / 256.0) * (SampleRateECG / sampleRateRToR);
darienf 20:6d2af70c92ab 854 rToRInEcgSamplesInt = (int)(rToRInEcgSamples + 0.5);
darienf 20:6d2af70c92ab 855
darienf 20:6d2af70c92ab 856 rToRInEcgSampleError = rToRInEcgSamplesInt - rToRInEcgSamples;
darienf 20:6d2af70c92ab 857
darienf 20:6d2af70c92ab 858 return rToRInEcgSamplesInt;
darienf 20:6d2af70c92ab 859 }
darienf 20:6d2af70c92ab 860 else
darienf 20:6d2af70c92ab 861 {
darienf 20:6d2af70c92ab 862 rToRInEcgSamples = rToR * (SampleRateECG / sampleRateRToR) - rToRInEcgSampleError;
darienf 20:6d2af70c92ab 863 rToRInEcgSamplesInt = (int)(rToRInEcgSamples + 0.5);
darienf 20:6d2af70c92ab 864
darienf 20:6d2af70c92ab 865 rToRInEcgSampleError = rToRInEcgSamplesInt - rToRInEcgSamples;
darienf 20:6d2af70c92ab 866
darienf 20:6d2af70c92ab 867 return rToRInEcgSamplesInt;
darienf 20:6d2af70c92ab 868
darienf 20:6d2af70c92ab 869 }
darienf 20:6d2af70c92ab 870 }
darienf 20:6d2af70c92ab 871 */
darienf 20:6d2af70c92ab 872
darienf 20:6d2af70c92ab 873 private double[] UpdateChartFormat(StreamDataType dataType, ChartInfo chartInfo)
darienf 20:6d2af70c92ab 874 {
darienf 20:6d2af70c92ab 875 Chart chart = null;
darienf 20:6d2af70c92ab 876 String series = "";
darienf 20:6d2af70c92ab 877 double[] chartData;
darienf 20:6d2af70c92ab 878 int minRound = 0, maxRound = 0;
darienf 20:6d2af70c92ab 879 double min = Double.MaxValue, max = Double.MinValue;
darienf 20:6d2af70c92ab 880 int count;
darienf 20:6d2af70c92ab 881
darienf 20:6d2af70c92ab 882 switch (dataType)
darienf 20:6d2af70c92ab 883 {
darienf 20:6d2af70c92ab 884 case StreamDataType.Ecg:
darienf 20:6d2af70c92ab 885 chart = chartECG;
darienf 20:6d2af70c92ab 886 series = "Series";
darienf 20:6d2af70c92ab 887 break;
darienf 20:6d2af70c92ab 888 case StreamDataType.BioZ:
darienf 20:6d2af70c92ab 889 chart = chartBioz;
darienf 20:6d2af70c92ab 890 series = "Series";
darienf 20:6d2af70c92ab 891 break;
darienf 20:6d2af70c92ab 892 case StreamDataType.RToR:
darienf 20:6d2af70c92ab 893 chart = chartECG;
darienf 20:6d2af70c92ab 894 series = "SeriesRToR";
darienf 20:6d2af70c92ab 895 break;
darienf 20:6d2af70c92ab 896 case StreamDataType.Pace:
darienf 20:6d2af70c92ab 897 chart = chartECG;
darienf 20:6d2af70c92ab 898 series = "SeriesPace";
darienf 20:6d2af70c92ab 899 break;
darienf 20:6d2af70c92ab 900
darienf 20:6d2af70c92ab 901 }
darienf 20:6d2af70c92ab 902
darienf 20:6d2af70c92ab 903 count = chart.Series[series].Points.Count;
darienf 20:6d2af70c92ab 904
darienf 20:6d2af70c92ab 905 // Remove extra points
darienf 20:6d2af70c92ab 906 while (count > chartInfo.Points)
darienf 20:6d2af70c92ab 907 {
darienf 20:6d2af70c92ab 908 chart.Series[series].Points.RemoveAt(0);
darienf 20:6d2af70c92ab 909 if (dataType == StreamDataType.Ecg && EnableRToR) // Scroll R To R with ECG
darienf 20:6d2af70c92ab 910 if (chart.Series["SeriesRToR"].Points.Count > 0) // TODO
darienf 20:6d2af70c92ab 911 chart.Series["SeriesRToR"].Points.RemoveAt(0);
darienf 20:6d2af70c92ab 912 else
darienf 20:6d2af70c92ab 913 rToRRemoveOffset++;
darienf 20:6d2af70c92ab 914
darienf 20:6d2af70c92ab 915 count = chart.Series[series].Points.Count;
darienf 20:6d2af70c92ab 916 }
darienf 20:6d2af70c92ab 917
darienf 20:6d2af70c92ab 918 chartData = new double[chart.Series[series].Points.Count];
darienf 20:6d2af70c92ab 919
darienf 20:6d2af70c92ab 920 // Copy data points and find min/max value
darienf 20:6d2af70c92ab 921 for (int i = count / 2; i < count; i++) // Autoscale on last half of data only
darienf 20:6d2af70c92ab 922 {
darienf 20:6d2af70c92ab 923 chartData[i] = chart.Series[series].Points[i].YValues[0];
darienf 20:6d2af70c92ab 924
darienf 20:6d2af70c92ab 925 if (chartData[i] < min)
darienf 20:6d2af70c92ab 926 min = chartData[i];
darienf 20:6d2af70c92ab 927 if (chartData[i] > max)
darienf 20:6d2af70c92ab 928 max = chartData[i];
darienf 20:6d2af70c92ab 929 }
darienf 20:6d2af70c92ab 930
darienf 20:6d2af70c92ab 931 if (min == max) // prevent any invalid ranges
darienf 20:6d2af70c92ab 932 max = max + 1;
darienf 20:6d2af70c92ab 933
darienf 20:6d2af70c92ab 934 if (chartInfo == ecgInfo)
darienf 20:6d2af70c92ab 935 {
darienf 20:6d2af70c92ab 936 // Round to 1mV for ECG
darienf 20:6d2af70c92ab 937 minRound = ((int)(min / 1) - 1) * 1;
darienf 20:6d2af70c92ab 938 maxRound = ((int)(max / 1) + 1) * 1;
darienf 20:6d2af70c92ab 939
darienf 20:6d2af70c92ab 940 if (minRound == -1 && maxRound == 1) // Manual control of auto interval
darienf 20:6d2af70c92ab 941 chart.ChartAreas[0].AxisY.Interval = 0.5;
darienf 20:6d2af70c92ab 942 else
darienf 20:6d2af70c92ab 943 chart.ChartAreas[0].AxisY.Interval = 0;
darienf 20:6d2af70c92ab 944 }
darienf 20:6d2af70c92ab 945 else if (chartInfo == bioZInfo)
darienf 20:6d2af70c92ab 946 {
darienf 20:6d2af70c92ab 947 // Round to 100's for automatic axis scaling - for raw codes
darienf 20:6d2af70c92ab 948 minRound = (((int)min / 100 - 1) * 100);
darienf 20:6d2af70c92ab 949 maxRound = (((int)max / 100 + 1) * 100);
darienf 20:6d2af70c92ab 950 }
darienf 20:6d2af70c92ab 951 /*else if (chartInfo == rToRInfo)
darienf 20:6d2af70c92ab 952 {
darienf 20:6d2af70c92ab 953 // Round to 100ms
darienf 20:6d2af70c92ab 954 minRound = 0; // R to R rate should never be negative;
darienf 20:6d2af70c92ab 955 maxRound = ((int)(max / 100) + 1) * 100;
darienf 20:6d2af70c92ab 956 }
darienf 20:6d2af70c92ab 957 else
darienf 20:6d2af70c92ab 958 {
darienf 20:6d2af70c92ab 959 // Round to 100's for automatic axis scaling - for us of Pace length
darienf 20:6d2af70c92ab 960 minRound = (((int)min / 100 - 1) * 100);
darienf 20:6d2af70c92ab 961 maxRound = (((int)max / 100 + 1) * 100);
darienf 20:6d2af70c92ab 962 }*/
darienf 20:6d2af70c92ab 963
darienf 20:6d2af70c92ab 964 if (chartInfo == ecgInfo || chartInfo == bioZInfo)
darienf 20:6d2af70c92ab 965 {
darienf 20:6d2af70c92ab 966 // Set full Y-axis range
darienf 20:6d2af70c92ab 967 chart.ChartAreas[0].AxisY.Minimum = minRound;
darienf 20:6d2af70c92ab 968 chart.ChartAreas[0].AxisY.Maximum = maxRound;
darienf 20:6d2af70c92ab 969 }
darienf 20:6d2af70c92ab 970
darienf 20:6d2af70c92ab 971 return chartData;
darienf 20:6d2af70c92ab 972 }
darienf 20:6d2af70c92ab 973
darienf 20:6d2af70c92ab 974 private double[] UpdateChartFormat(StreamDataType dataType, ChartInfo chartInfo, int shift)
darienf 20:6d2af70c92ab 975 {
darienf 20:6d2af70c92ab 976 List<double> xList = new List<double>();
darienf 20:6d2af70c92ab 977 List<double> yList = new List<double>();
darienf 20:6d2af70c92ab 978 List<double> xListFalling = new List<double>();
darienf 20:6d2af70c92ab 979 List<double> yListFalling = new List<double>();
darienf 20:6d2af70c92ab 980
darienf 20:6d2af70c92ab 981 int offset = chartECG.Series["Series"].Points.Count; // Pace Offset
darienf 20:6d2af70c92ab 982
darienf 20:6d2af70c92ab 983 // Shift Old Points - Rising
darienf 20:6d2af70c92ab 984 for (int i = 0; i < chartECG.Series["SeriesPace"].Points.Count; i++)
darienf 20:6d2af70c92ab 985 {
darienf 20:6d2af70c92ab 986 double xValue = chartECG.Series["SeriesPace"].Points[i].XValue;
darienf 20:6d2af70c92ab 987
darienf 20:6d2af70c92ab 988 if (offset >= ecgInfo.Points) // Do not shift until chart is full
darienf 20:6d2af70c92ab 989 xValue -= shift;
darienf 20:6d2af70c92ab 990
darienf 20:6d2af70c92ab 991 if (xValue >= 0)
darienf 20:6d2af70c92ab 992 {
darienf 20:6d2af70c92ab 993 xList.Add(xValue);
darienf 20:6d2af70c92ab 994 yList.Add(chartECG.Series["SeriesPace"].Points[i].YValues[0]);
darienf 20:6d2af70c92ab 995 }
darienf 20:6d2af70c92ab 996 }
darienf 20:6d2af70c92ab 997 // Shift Old Points - Falling
darienf 20:6d2af70c92ab 998 for (int i = 0; i < chartECG.Series["SeriesPaceFalling"].Points.Count; i++)
darienf 20:6d2af70c92ab 999 {
darienf 20:6d2af70c92ab 1000 double xValueFalling = chartECG.Series["SeriesPaceFalling"].Points[i].XValue;
darienf 20:6d2af70c92ab 1001
darienf 20:6d2af70c92ab 1002 if (offset >= ecgInfo.Points)
darienf 20:6d2af70c92ab 1003 xValueFalling -= shift;
darienf 20:6d2af70c92ab 1004
darienf 20:6d2af70c92ab 1005 if (xValueFalling >= 0)
darienf 20:6d2af70c92ab 1006 {
darienf 20:6d2af70c92ab 1007 xListFalling.Add(xValueFalling);
darienf 20:6d2af70c92ab 1008 yListFalling.Add(chartECG.Series["SeriesPaceFalling"].Points[i].YValues[0]);
darienf 20:6d2af70c92ab 1009 }
darienf 20:6d2af70c92ab 1010 }
darienf 20:6d2af70c92ab 1011
darienf 20:6d2af70c92ab 1012 chartECG.Series["SeriesPace"].Points.DataBindXY(xList, yList);
darienf 20:6d2af70c92ab 1013 chartECG.Series["SeriesPaceFalling"].Points.DataBindXY(xListFalling, yListFalling);
darienf 20:6d2af70c92ab 1014
darienf 20:6d2af70c92ab 1015 return yList.ToArray();
darienf 20:6d2af70c92ab 1016 }
darienf 20:6d2af70c92ab 1017
darienf 20:6d2af70c92ab 1018 /*
darienf 20:6d2af70c92ab 1019 public EcgFifo[] ConvertEcg(int[] data)
darienf 20:6d2af70c92ab 1020 {
darienf 20:6d2af70c92ab 1021 EcgFifo[] voltage = new EcgFifo[data.Length];
darienf 20:6d2af70c92ab 1022 ChartInfo chartInfo = ecgInfo;
darienf 20:6d2af70c92ab 1023 int dataShift;
darienf 20:6d2af70c92ab 1024
darienf 20:6d2af70c92ab 1025 for (int i = 0; i < data.Length; i++ )
darienf 20:6d2af70c92ab 1026 {
darienf 20:6d2af70c92ab 1027 dataShift = data[i] >> chartInfo.Shift;
darienf 20:6d2af70c92ab 1028
darienf 20:6d2af70c92ab 1029 // Two's Complement Conversions
darienf 20:6d2af70c92ab 1030 if (dataShift > chartInfo.Threshold)
darienf 20:6d2af70c92ab 1031 {
darienf 20:6d2af70c92ab 1032 dataShift -= chartInfo.Offset;
darienf 20:6d2af70c92ab 1033 }
darienf 20:6d2af70c92ab 1034
darienf 20:6d2af70c92ab 1035 voltage[i].Data = 1000 * 7.62939453125e-6 * dataShift / chartInfo.Gain;
darienf 20:6d2af70c92ab 1036 voltage[i].PTag = data[i] & 0x07;
darienf 20:6d2af70c92ab 1037 voltage[i].ETag = (data[i] >> 3) & 0x07;
darienf 20:6d2af70c92ab 1038 }
darienf 20:6d2af70c92ab 1039
darienf 20:6d2af70c92ab 1040 return voltage;
darienf 20:6d2af70c92ab 1041 }
darienf 20:6d2af70c92ab 1042
darienf 20:6d2af70c92ab 1043 public BioZFifo[] ConvertBioZ(int[] data)
darienf 20:6d2af70c92ab 1044 {
darienf 20:6d2af70c92ab 1045 BioZFifo[] impedence = new BioZFifo[data.Length];
darienf 20:6d2af70c92ab 1046 ChartInfo chartInfo = bioZInfo;
darienf 20:6d2af70c92ab 1047 int dataShift;
darienf 20:6d2af70c92ab 1048 int dataPoint;
darienf 20:6d2af70c92ab 1049
darienf 20:6d2af70c92ab 1050 for (int i = 0; i < data.Length; i ++)
darienf 20:6d2af70c92ab 1051 {
darienf 20:6d2af70c92ab 1052 dataShift = data[i] >> chartInfo.Shift;
darienf 20:6d2af70c92ab 1053
darienf 20:6d2af70c92ab 1054 // Two's Complement Conversions
darienf 20:6d2af70c92ab 1055 if (dataShift > chartInfo.Threshold)
darienf 20:6d2af70c92ab 1056 {
darienf 20:6d2af70c92ab 1057 dataShift -= chartInfo.Offset;
darienf 20:6d2af70c92ab 1058 }
darienf 20:6d2af70c92ab 1059
darienf 20:6d2af70c92ab 1060 // 1.9734 = 1/2^19 * 1e-6
darienf 20:6d2af70c92ab 1061 impedence[i].Data = dataShift * bioZRangeMultiplier * 1.9073486328125 /
darienf 20:6d2af70c92ab 1062 (chartInfo.Gain * ((chartInfo.CurrentGenerator == 0) ? 1 : chartInfo.CurrentGenerator));
darienf 20:6d2af70c92ab 1063 impedence[i].BTag = data[i] & 0x07;
darienf 20:6d2af70c92ab 1064 }
darienf 20:6d2af70c92ab 1065
darienf 20:6d2af70c92ab 1066 return impedence;
darienf 20:6d2af70c92ab 1067 }
darienf 20:6d2af70c92ab 1068
darienf 20:6d2af70c92ab 1069 public PaceData ConvertPace(int[] data)
darienf 20:6d2af70c92ab 1070 {
darienf 20:6d2af70c92ab 1071 paceData = new PaceData(data);
darienf 20:6d2af70c92ab 1072
darienf 20:6d2af70c92ab 1073 return paceData;
darienf 20:6d2af70c92ab 1074 }
darienf 20:6d2af70c92ab 1075
darienf 20:6d2af70c92ab 1076 public double ConvertRToR(int data)
darienf 20:6d2af70c92ab 1077 {
darienf 20:6d2af70c92ab 1078 rToRInterval = data;
darienf 20:6d2af70c92ab 1079
darienf 20:6d2af70c92ab 1080 return rToRInterval;
darienf 20:6d2af70c92ab 1081 }
darienf 20:6d2af70c92ab 1082 */
darienf 20:6d2af70c92ab 1083
darienf 20:6d2af70c92ab 1084 int[] ProcessRToR(int[] ecgData)
darienf 20:6d2af70c92ab 1085 {
darienf 20:6d2af70c92ab 1086 int[] rToRArray;
darienf 20:6d2af70c92ab 1087
darienf 20:6d2af70c92ab 1088 rToRArray = new int[ecgData.Length];
darienf 20:6d2af70c92ab 1089 for (int i = 0; i < rToRArray.Length; i++)
darienf 20:6d2af70c92ab 1090 rToRArray[i] = Int32.MinValue;
darienf 20:6d2af70c92ab 1091
darienf 20:6d2af70c92ab 1092 if (rToRInterval > 0) // Valid R to R
darienf 20:6d2af70c92ab 1093 {
darienf 20:6d2af70c92ab 1094 var ecgCode = EcgMaximumCode(ecgData);
darienf 20:6d2af70c92ab 1095 rToRArray[ecgCode.Item1] = ecgCode.Item2;
darienf 20:6d2af70c92ab 1096 }
darienf 20:6d2af70c92ab 1097
darienf 20:6d2af70c92ab 1098 return rToRArray;
darienf 20:6d2af70c92ab 1099 }
darienf 20:6d2af70c92ab 1100
darienf 20:6d2af70c92ab 1101 public Tuple<int, int> EcgMaximumCode(int[] data)
darienf 20:6d2af70c92ab 1102 {
darienf 20:6d2af70c92ab 1103 int i;
darienf 20:6d2af70c92ab 1104 int max = Int32.MinValue;
darienf 20:6d2af70c92ab 1105 int maxCode = 0;
darienf 20:6d2af70c92ab 1106 int maxIndex = 0;
darienf 20:6d2af70c92ab 1107 int point;
darienf 20:6d2af70c92ab 1108
darienf 20:6d2af70c92ab 1109 for (i = 0; i < data.Length; i++ )
darienf 20:6d2af70c92ab 1110 {
darienf 20:6d2af70c92ab 1111 point = data[i] >> ecgInfo.Shift;
darienf 20:6d2af70c92ab 1112 if (data[i] > ecgInfo.Threshold)
darienf 20:6d2af70c92ab 1113 point -= ecgInfo.Offset;
darienf 20:6d2af70c92ab 1114
darienf 20:6d2af70c92ab 1115 if (point > max) // Two's complement offset
darienf 20:6d2af70c92ab 1116 {
darienf 20:6d2af70c92ab 1117 max = point;
darienf 20:6d2af70c92ab 1118 maxCode = data[i];
darienf 20:6d2af70c92ab 1119 maxIndex = i;
darienf 20:6d2af70c92ab 1120 }
darienf 20:6d2af70c92ab 1121 }
darienf 20:6d2af70c92ab 1122
darienf 20:6d2af70c92ab 1123 return new Tuple<int, int>(maxIndex, maxCode);
darienf 20:6d2af70c92ab 1124 }
darienf 20:6d2af70c92ab 1125
darienf 20:6d2af70c92ab 1126 private bool LeadOffBit(int value, int bit)
darienf 20:6d2af70c92ab 1127 {
darienf 20:6d2af70c92ab 1128 int state;
darienf 20:6d2af70c92ab 1129 int mask = 1 << bit;
darienf 20:6d2af70c92ab 1130 state = ((value & mask) == mask) ? 1 : 0;
darienf 20:6d2af70c92ab 1131 return state == 1;
darienf 20:6d2af70c92ab 1132 }
darienf 20:6d2af70c92ab 1133
darienf 20:6d2af70c92ab 1134 //public void On_AppendChart(object sender, PartialArrayIntAvailableEventArgs e)
darienf 20:6d2af70c92ab 1135 //{
darienf 20:6d2af70c92ab 1136 /*
darienf 20:6d2af70c92ab 1137 int leadOffState;
darienf 20:6d2af70c92ab 1138
darienf 20:6d2af70c92ab 1139 if (e.array1.Length > 0) // Occurs with streaming from flash
darienf 20:6d2af70c92ab 1140 {
darienf 20:6d2af70c92ab 1141 leadOffState = e.array1[0];
darienf 20:6d2af70c92ab 1142
darienf 20:6d2af70c92ab 1143 switch (e.reportID)
darienf 20:6d2af70c92ab 1144 {
darienf 20:6d2af70c92ab 1145 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_LEADOFF_DC:
darienf 20:6d2af70c92ab 1146 if (LeadOffBit(leadOffState, 8)) // check for ECG
darienf 20:6d2af70c92ab 1147 {
darienf 20:6d2af70c92ab 1148 UpdateLeadOffState(lblLdoffPh, LeadOffBit(leadOffState, 3));
darienf 20:6d2af70c92ab 1149 UpdateLeadOffState(lblLdoffPl, LeadOffBit(leadOffState, 2));
darienf 20:6d2af70c92ab 1150 UpdateLeadOffState(lblLdoffNh, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1151 UpdateLeadOffState(lblLdoffNl, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1152 }
darienf 20:6d2af70c92ab 1153 if (LeadOffBit(leadOffState, 9)) // check for BIOZ
darienf 20:6d2af70c92ab 1154 {
darienf 20:6d2af70c92ab 1155 UpdateLeadOffState(lblLdoffPh, LeadOffBit(leadOffState, 3));
darienf 20:6d2af70c92ab 1156 UpdateLeadOffState(lblLdoffPl, LeadOffBit(leadOffState, 2));
darienf 20:6d2af70c92ab 1157 UpdateLeadOffState(lblLdoffNh, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1158 UpdateLeadOffState(lblLdoffNl, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1159 }
darienf 20:6d2af70c92ab 1160 break;
darienf 20:6d2af70c92ab 1161 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_LEADOFF_AC:
darienf 20:6d2af70c92ab 1162 UpdateLeadOffState(lblBioZACOver, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1163 UpdateLeadOffState(lblBioZACUnder, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1164 break;
darienf 20:6d2af70c92ab 1165 }
darienf 20:6d2af70c92ab 1166 }
darienf 20:6d2af70c92ab 1167 */
darienf 20:6d2af70c92ab 1168 /*
darienf 20:6d2af70c92ab 1169 StringBuilder outputData = new StringBuilder();
darienf 20:6d2af70c92ab 1170
darienf 20:6d2af70c92ab 1171 if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG)
darienf 20:6d2af70c92ab 1172 {
darienf 20:6d2af70c92ab 1173 if (e.array1.Length != 0)
darienf 20:6d2af70c92ab 1174 {
darienf 20:6d2af70c92ab 1175 if (ecgBuffer != null)
darienf 20:6d2af70c92ab 1176 {
darienf 20:6d2af70c92ab 1177 UpdateChart(StreamDataType.Ecg, ecgBuffer);
darienf 20:6d2af70c92ab 1178
darienf 20:6d2af70c92ab 1179 if (EnableRToR)
darienf 20:6d2af70c92ab 1180 {
darienf 20:6d2af70c92ab 1181 int[] rToRArray = ProcessRToR(ecgBuffer);
darienf 20:6d2af70c92ab 1182
darienf 20:6d2af70c92ab 1183 UpdateChart(StreamDataType.RToR, rToRArray);
darienf 20:6d2af70c92ab 1184 rToRInterval = -1; // R to R processed reset value
darienf 20:6d2af70c92ab 1185 }
darienf 20:6d2af70c92ab 1186 }
darienf 20:6d2af70c92ab 1187
darienf 20:6d2af70c92ab 1188 ecgBuffer = ecgBuffer1;
darienf 20:6d2af70c92ab 1189 ecgBuffer1 = e.array1;
darienf 20:6d2af70c92ab 1190 // DEBUG
darienf 20:6d2af70c92ab 1191 foreach (int data in e.array1)
darienf 20:6d2af70c92ab 1192 {
darienf 20:6d2af70c92ab 1193 outputData.Append(data.ToString());
darienf 20:6d2af70c92ab 1194 outputData.Append(Environment.NewLine);
darienf 20:6d2af70c92ab 1195 }
darienf 20:6d2af70c92ab 1196
darienf 20:6d2af70c92ab 1197 file.Write(outputData.ToString());
darienf 20:6d2af70c92ab 1198
darienf 20:6d2af70c92ab 1199 ConvertEcg(e.array1);
darienf 20:6d2af70c92ab 1200 }
darienf 20:6d2af70c92ab 1201 }
darienf 20:6d2af70c92ab 1202 if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_MAX30001_PACE)
darienf 20:6d2af70c92ab 1203 {
darienf 20:6d2af70c92ab 1204 if (e.array1.Length != 0)
darienf 20:6d2af70c92ab 1205 {
darienf 20:6d2af70c92ab 1206 // Store Pace data for update with ECG PTAGs
darienf 20:6d2af70c92ab 1207 ConvertPace(e.array1);
darienf 20:6d2af70c92ab 1208 }
darienf 20:6d2af70c92ab 1209 }
darienf 20:6d2af70c92ab 1210 if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_MAX30001_RTOR)
darienf 20:6d2af70c92ab 1211 {
darienf 20:6d2af70c92ab 1212 if (e.array1.Length != 0)
darienf 20:6d2af70c92ab 1213 {
darienf 20:6d2af70c92ab 1214 ConvertRToR(e.array1[0]);
darienf 20:6d2af70c92ab 1215 }
darienf 20:6d2af70c92ab 1216 }
darienf 20:6d2af70c92ab 1217 if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_MAX30001_BIOZ)
darienf 20:6d2af70c92ab 1218 {
darienf 20:6d2af70c92ab 1219 if (e.array1.Length != 0)
darienf 20:6d2af70c92ab 1220 {
darienf 20:6d2af70c92ab 1221 ConvertBioZ(e.array1);
darienf 20:6d2af70c92ab 1222 //UpdateChart(StreamDataType.BioZ, e.array1);
darienf 20:6d2af70c92ab 1223 }
darienf 20:6d2af70c92ab 1224 }*/
darienf 20:6d2af70c92ab 1225 //}
darienf 20:6d2af70c92ab 1226
darienf 20:6d2af70c92ab 1227 private void Start()
darienf 20:6d2af70c92ab 1228 {
darienf 20:6d2af70c92ab 1229 //ParseRbiasArgs();
darienf 20:6d2af70c92ab 1230 /*rpcClient.MAX30001.Rbias_FMSTR_Init(
darienf 20:6d2af70c92ab 1231 rbiasInit.En_rbias,
darienf 20:6d2af70c92ab 1232 rbiasInit.Rbias,
darienf 20:6d2af70c92ab 1233 rbiasInit.Rbiasp,
darienf 20:6d2af70c92ab 1234 rbiasInit.Rbiasn,
darienf 20:6d2af70c92ab 1235 rbiasInit.Fmstr
darienf 20:6d2af70c92ab 1236 );*/
darienf 20:6d2af70c92ab 1237
darienf 20:6d2af70c92ab 1238
darienf 20:6d2af70c92ab 1239 //if (ckbxCal.Checked)
darienf 20:6d2af70c92ab 1240 /*{
darienf 20:6d2af70c92ab 1241 startedCal = true;
darienf 20:6d2af70c92ab 1242 //ParseCalArgs();
darienf 20:6d2af70c92ab 1243 calArgs.En_Vcal = 0;
darienf 20:6d2af70c92ab 1244 calArgs.Vmode = 0;
darienf 20:6d2af70c92ab 1245 calArgs.Vmag = 1;
darienf 20:6d2af70c92ab 1246 calArgs.Fcal = 3;
darienf 20:6d2af70c92ab 1247 calArgs.Thigh = 0x1F;
darienf 20:6d2af70c92ab 1248 calArgs.Fifty = 0;
darienf 20:6d2af70c92ab 1249 rpcClient.MAX30001.CAL_InitStart(
darienf 20:6d2af70c92ab 1250 calArgs.En_Vcal,
darienf 20:6d2af70c92ab 1251 calArgs.Vmode,
darienf 20:6d2af70c92ab 1252 calArgs.Vmag,
darienf 20:6d2af70c92ab 1253 calArgs.Fcal,
darienf 20:6d2af70c92ab 1254 calArgs.Thigh,
darienf 20:6d2af70c92ab 1255 calArgs.Fifty);
darienf 20:6d2af70c92ab 1256 }*/
darienf 20:6d2af70c92ab 1257
darienf 20:6d2af70c92ab 1258 /*
darienf 20:6d2af70c92ab 1259 rpcClient.MAX30001.INT_assignment(MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc,
darienf 20:6d2af70c92ab 1260 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc,
darienf 20:6d2af70c92ab 1261 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc,
darienf 20:6d2af70c92ab 1262 MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc,
darienf 20:6d2af70c92ab 1263 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc,
darienf 20:6d2af70c92ab 1264 MAX30001.max30001_intrpt_type.MAX30001_INT_ODNR, MAX30001.max30001_intrpt_type.MAX30001_INT_ODNR); // intb_Type, int2b_Type)
darienf 20:6d2af70c92ab 1265 */
darienf 20:6d2af70c92ab 1266 if (connected)
darienf 20:6d2af70c92ab 1267 {
darienf 20:6d2af70c92ab 1268 rpcClient.MAX30001.WriteReg(0x02, 0x03); // Stop Interrupts
darienf 20:6d2af70c92ab 1269 rpcClient.MAX30001.WriteReg(0x03, 0x03); // Stop Interrupts
darienf 20:6d2af70c92ab 1270 }
darienf 20:6d2af70c92ab 1271
darienf 20:6d2af70c92ab 1272 if (enableECG)
darienf 20:6d2af70c92ab 1273 {
darienf 20:6d2af70c92ab 1274 startedEcg = true;
darienf 20:6d2af70c92ab 1275 if (GetEcgInitArgsPointer != null)
darienf 20:6d2af70c92ab 1276 {
darienf 20:6d2af70c92ab 1277 ecgArgs = GetEcgInitArgsPointer();
darienf 20:6d2af70c92ab 1278 rpcClient.MAX30001.ECG_InitStart(
darienf 20:6d2af70c92ab 1279 ecgArgs.En_ecg,
darienf 20:6d2af70c92ab 1280 ecgArgs.Openp,
darienf 20:6d2af70c92ab 1281 ecgArgs.Openn,
darienf 20:6d2af70c92ab 1282 ecgArgs.Pol,
darienf 20:6d2af70c92ab 1283 ecgArgs.Calp_sel,
darienf 20:6d2af70c92ab 1284 ecgArgs.Caln_sel,
darienf 20:6d2af70c92ab 1285 ecgArgs.E_fit,
darienf 20:6d2af70c92ab 1286 ecgArgs.Rate,
darienf 20:6d2af70c92ab 1287 ecgArgs.Gain,
darienf 20:6d2af70c92ab 1288 ecgArgs.Dhpf,
darienf 20:6d2af70c92ab 1289 ecgArgs.Dlpf);
darienf 20:6d2af70c92ab 1290 }
darienf 20:6d2af70c92ab 1291
darienf 20:6d2af70c92ab 1292 /* rpcClient.MAX30001.ECGFast_Init(
darienf 20:6d2af70c92ab 1293 ecgFastArgs.Clr_Fast,
darienf 20:6d2af70c92ab 1294 ecgFastArgs.Fast,
darienf 20:6d2af70c92ab 1295 ecgFastArgs.Fast_Th);*/
darienf 20:6d2af70c92ab 1296 }
darienf 20:6d2af70c92ab 1297
darienf 20:6d2af70c92ab 1298 if (enablePace)
darienf 20:6d2af70c92ab 1299 {
darienf 20:6d2af70c92ab 1300 startedPace = true;
darienf 20:6d2af70c92ab 1301 if (GetPaceInitArgsPointer != null)
darienf 20:6d2af70c92ab 1302 {
darienf 20:6d2af70c92ab 1303 paceArgs = GetPaceInitArgsPointer();
darienf 20:6d2af70c92ab 1304 rpcClient.MAX30001.PACE_InitStart(
darienf 20:6d2af70c92ab 1305 paceArgs.En_pace,
darienf 20:6d2af70c92ab 1306 paceArgs.Clr_pedge,
darienf 20:6d2af70c92ab 1307 paceArgs.Pol,
darienf 20:6d2af70c92ab 1308 paceArgs.Gn_diff_off,
darienf 20:6d2af70c92ab 1309 paceArgs.Gain,
darienf 20:6d2af70c92ab 1310 paceArgs.Aout_lbw,
darienf 20:6d2af70c92ab 1311 paceArgs.Aout,
darienf 20:6d2af70c92ab 1312 paceArgs.Dacp,
darienf 20:6d2af70c92ab 1313 paceArgs.Dacn);
darienf 20:6d2af70c92ab 1314 }
darienf 20:6d2af70c92ab 1315 }
darienf 20:6d2af70c92ab 1316 if (enableBioZ)
darienf 20:6d2af70c92ab 1317 {
darienf 20:6d2af70c92ab 1318 startedBioz = true;
darienf 20:6d2af70c92ab 1319 if (GetBioZInitArgsPointer != null)
darienf 20:6d2af70c92ab 1320 {
darienf 20:6d2af70c92ab 1321 biozArgs = GetBioZInitArgsPointer();
darienf 20:6d2af70c92ab 1322 rpcClient.MAX30001.BIOZ_InitStart(
darienf 20:6d2af70c92ab 1323 biozArgs.En_bioz,
darienf 20:6d2af70c92ab 1324 biozArgs.Openp,
darienf 20:6d2af70c92ab 1325 biozArgs.Openn,
darienf 20:6d2af70c92ab 1326 biozArgs.Calp_sel,
darienf 20:6d2af70c92ab 1327 biozArgs.Caln_sel,
darienf 20:6d2af70c92ab 1328 biozArgs.CG_mode,
darienf 20:6d2af70c92ab 1329 biozArgs.B_fit,
darienf 20:6d2af70c92ab 1330 biozArgs.Rate,
darienf 20:6d2af70c92ab 1331 biozArgs.Ahpf,
darienf 20:6d2af70c92ab 1332 biozArgs.Ext_rbias,
darienf 20:6d2af70c92ab 1333 biozArgs.Gain,
darienf 20:6d2af70c92ab 1334 biozArgs.Dhpf,
darienf 20:6d2af70c92ab 1335 biozArgs.Dlpf,
darienf 20:6d2af70c92ab 1336 biozArgs.Fcgen,
darienf 20:6d2af70c92ab 1337 biozArgs.Cgmon,
darienf 20:6d2af70c92ab 1338 biozArgs.Cgmag,
darienf 20:6d2af70c92ab 1339 biozArgs.Phoff);
darienf 20:6d2af70c92ab 1340 }
darienf 20:6d2af70c92ab 1341 }
darienf 20:6d2af70c92ab 1342 if (enableRToR)
darienf 20:6d2af70c92ab 1343 {
darienf 20:6d2af70c92ab 1344 startedRtoR = true;
darienf 20:6d2af70c92ab 1345 if (GetRToRInitArgsPointer != null)
darienf 20:6d2af70c92ab 1346 {
darienf 20:6d2af70c92ab 1347 rtorArgs = GetRToRInitArgsPointer();
darienf 20:6d2af70c92ab 1348 rpcClient.MAX30001.RtoR_InitStart(
darienf 20:6d2af70c92ab 1349 rtorArgs.En_rtor,
darienf 20:6d2af70c92ab 1350 rtorArgs.Wndw,
darienf 20:6d2af70c92ab 1351 rtorArgs.Gain,
darienf 20:6d2af70c92ab 1352 rtorArgs.Pavg,
darienf 20:6d2af70c92ab 1353 rtorArgs.Ptsf,
darienf 20:6d2af70c92ab 1354 rtorArgs.Hoff,
darienf 20:6d2af70c92ab 1355 rtorArgs.Ravg,
darienf 20:6d2af70c92ab 1356 rtorArgs.Rhsf,
darienf 20:6d2af70c92ab 1357 rtorArgs.Clr_rrint);
darienf 20:6d2af70c92ab 1358 }
darienf 20:6d2af70c92ab 1359
darienf 20:6d2af70c92ab 1360 rToRCalculator = new RToRCalculator(frequencyMasterField, ecgArgs.Rate, ecgArgs.Dlpf, rtorArgs.Wndw);
darienf 20:6d2af70c92ab 1361 }
darienf 20:6d2af70c92ab 1362
darienf 20:6d2af70c92ab 1363 /*rpcClient.MAX30001.Rbias_FMSTR_Init(
darienf 20:6d2af70c92ab 1364 0,
darienf 20:6d2af70c92ab 1365 0,
darienf 20:6d2af70c92ab 1366 0,
darienf 20:6d2af70c92ab 1367 0,
darienf 20:6d2af70c92ab 1368 0);*/
darienf 20:6d2af70c92ab 1369
darienf 20:6d2af70c92ab 1370 rpcClient.MAX30001.INT_assignment(MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc,
darienf 20:6d2af70c92ab 1371 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc,
darienf 20:6d2af70c92ab 1372 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc,
darienf 20:6d2af70c92ab 1373 MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc,
darienf 20:6d2af70c92ab 1374 MAX30001.max30001_intrpt_Location.MAX30001_INT_2B, MAX30001.max30001_intrpt_Location.MAX30001_INT_B, MAX30001.max30001_intrpt_Location.MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc,
darienf 20:6d2af70c92ab 1375 MAX30001.max30001_intrpt_type.MAX30001_INT_ODNR, MAX30001.max30001_intrpt_type.MAX30001_INT_ODNR); // intb_Type, int2b_Type)
darienf 20:6d2af70c92ab 1376
darienf 20:6d2af70c92ab 1377 if (startedEcg | startedCal | startedPace | startedBioz | startedRtoR)
darienf 20:6d2af70c92ab 1378 {
darienf 20:6d2af70c92ab 1379 rpcClient.MAX30001.StartStreaming();
darienf 20:6d2af70c92ab 1380 }
darienf 20:6d2af70c92ab 1381
darienf 20:6d2af70c92ab 1382 // Clear Lead Off
darienf 20:6d2af70c92ab 1383 UpdateLeadOffState(lblLdoffPh, false);
darienf 20:6d2af70c92ab 1384 UpdateLeadOffState(lblLdoffPl, false);
darienf 20:6d2af70c92ab 1385 UpdateLeadOffState(lblLdoffNh, false);
darienf 20:6d2af70c92ab 1386 UpdateLeadOffState(lblLdoffNl, false);
darienf 20:6d2af70c92ab 1387 UpdateLeadOffState(lblBioZACOver, false);
darienf 20:6d2af70c92ab 1388 UpdateLeadOffState(lblBioZACUnder, false);
darienf 20:6d2af70c92ab 1389
darienf 20:6d2af70c92ab 1390 // Clear Charts
darienf 20:6d2af70c92ab 1391 chartECG.Series["Series"].Points.Clear();
darienf 20:6d2af70c92ab 1392 chartECG.Series["SeriesRToR"].Points.Clear();
darienf 20:6d2af70c92ab 1393 chartECG.Series["SeriesPace"].Points.Clear();
darienf 20:6d2af70c92ab 1394 chartECG.Series["SeriesPaceFalling"].Points.Clear();
darienf 20:6d2af70c92ab 1395 //chartRtoR.Series["Series"].Points.Clear();
darienf 20:6d2af70c92ab 1396 chartBioz.Series["Series"].Points.Clear();
darienf 20:6d2af70c92ab 1397 //chartPace.Series["Series"].Points.Clear();
darienf 20:6d2af70c92ab 1398 InitChart();
darienf 20:6d2af70c92ab 1399 fileLogData.Clear(); // Clear initiation points
darienf 20:6d2af70c92ab 1400
darienf 20:6d2af70c92ab 1401 // Reset R To R state
darienf 20:6d2af70c92ab 1402 rToRRemoveOffset = 0;
darienf 20:6d2af70c92ab 1403 lastRToRTime = -1;
darienf 20:6d2af70c92ab 1404
darienf 20:6d2af70c92ab 1405 // Clear Heart Rate
darienf 20:6d2af70c92ab 1406 heartRateList = new List<double>(10);
darienf 20:6d2af70c92ab 1407 lblHeartRateAverage10.Text = "--";
darienf 20:6d2af70c92ab 1408 lblHeartRateBeatToBeat.Text = "--";
darienf 20:6d2af70c92ab 1409
darienf 20:6d2af70c92ab 1410 #if CES_DEMO
darienf 20:6d2af70c92ab 1411 hpf.Reset();
darienf 20:6d2af70c92ab 1412 #endif
darienf 20:6d2af70c92ab 1413 btnMonitor.Text = "Stop Monitor";
darienf 20:6d2af70c92ab 1414 if (StreamingStartStop != null)
darienf 20:6d2af70c92ab 1415 {
darienf 20:6d2af70c92ab 1416 StreamingStartStop(this, new StreamingStartStopEventArgs() { state = true });
darienf 20:6d2af70c92ab 1417 }
darienf 20:6d2af70c92ab 1418 #if FILE_LOG
darienf 20:6d2af70c92ab 1419 // Debug
darienf 20:6d2af70c92ab 1420 DateTime localDate = DateTime.Now;
darienf 20:6d2af70c92ab 1421
darienf 20:6d2af70c92ab 1422 file = new StreamWriter("hsp_ecg_output_data.csv");
darienf 20:6d2af70c92ab 1423 file.WriteLine("# " + localDate.ToString() + ", Sample Rate Register Setting: " + ecgArgs.Rate);
darienf 20:6d2af70c92ab 1424 file.WriteLine(@"# ECG (μV) Raw Integer");
darienf 20:6d2af70c92ab 1425 #endif
darienf 20:6d2af70c92ab 1426
darienf 20:6d2af70c92ab 1427 // DEBUG - simulate the "first" R To R value as a > 10 second value to see what happens
darienf 20:6d2af70c92ab 1428 //DisplayRToR(0x600);
darienf 20:6d2af70c92ab 1429 }
darienf 20:6d2af70c92ab 1430 private void btnMonitor_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 1431 {
darienf 20:6d2af70c92ab 1432 if (btnMonitor.Text == "Start Monitor")
darienf 20:6d2af70c92ab 1433 {
darienf 20:6d2af70c92ab 1434 if (Connected)
darienf 20:6d2af70c92ab 1435 {
darienf 20:6d2af70c92ab 1436 //if (ckbxEcg.Checked | ckbxPace.Checked | ckbxBioz.Checked | ckbxRtoR.Checked)
darienf 20:6d2af70c92ab 1437 if (EnableECG | EnableBioZ)
darienf 20:6d2af70c92ab 1438 Start();
darienf 20:6d2af70c92ab 1439 else if (EnableRToR)
darienf 20:6d2af70c92ab 1440 MessageBox.Show("Also enable ECG for R-to-R streaming", "Streaming");
darienf 20:6d2af70c92ab 1441 else
darienf 20:6d2af70c92ab 1442 MessageBox.Show("Enable ECG or BioZ before starting streaming", "Streaming");
darienf 20:6d2af70c92ab 1443 }
darienf 20:6d2af70c92ab 1444 }
darienf 20:6d2af70c92ab 1445 else
darienf 20:6d2af70c92ab 1446 {
darienf 20:6d2af70c92ab 1447 Stop();
darienf 20:6d2af70c92ab 1448 }
darienf 20:6d2af70c92ab 1449 }
darienf 20:6d2af70c92ab 1450
darienf 20:6d2af70c92ab 1451 private void Stop()
darienf 20:6d2af70c92ab 1452 {
darienf 20:6d2af70c92ab 1453 if (startedEcg | startedCal | startedPace | startedBioz | startedRtoR)
darienf 20:6d2af70c92ab 1454 {
darienf 20:6d2af70c92ab 1455 rpcClient.MAX30001.StopStreaming(connected);
darienf 20:6d2af70c92ab 1456
darienf 20:6d2af70c92ab 1457 //rpcClient.MAX30001.WriteReg(0x02, 0);
darienf 20:6d2af70c92ab 1458 //rpcClient.MAX30001.WriteReg(0x03, 0);
darienf 20:6d2af70c92ab 1459 }
darienf 20:6d2af70c92ab 1460
darienf 20:6d2af70c92ab 1461 startedCal = false;
darienf 20:6d2af70c92ab 1462 startedEcg = false;
darienf 20:6d2af70c92ab 1463 startedPace = false;
darienf 20:6d2af70c92ab 1464 startedBioz = false;
darienf 20:6d2af70c92ab 1465 startedRtoR = false;
darienf 20:6d2af70c92ab 1466
darienf 20:6d2af70c92ab 1467 btnMonitor.Text = "Start Monitor";
darienf 20:6d2af70c92ab 1468 if (StreamingStartStop != null)
darienf 20:6d2af70c92ab 1469 StreamingStartStop(this, new StreamingStartStopEventArgs() { state = false });
darienf 20:6d2af70c92ab 1470
darienf 20:6d2af70c92ab 1471 #if FILE_LOG
darienf 20:6d2af70c92ab 1472 // Debug
darienf 20:6d2af70c92ab 1473 file.Close();
darienf 20:6d2af70c92ab 1474 #endif
darienf 20:6d2af70c92ab 1475 }
darienf 20:6d2af70c92ab 1476
darienf 20:6d2af70c92ab 1477 // Clean up streaming
darienf 20:6d2af70c92ab 1478 public void Close()
darienf 20:6d2af70c92ab 1479 {
darienf 20:6d2af70c92ab 1480 // Disable streaming if enabled
darienf 20:6d2af70c92ab 1481 if (StreamingStartStop != null && btnMonitor.Text == "Stop Monitor")
darienf 20:6d2af70c92ab 1482 {
darienf 20:6d2af70c92ab 1483 StreamingStartStop(this, new StreamingStartStopEventArgs() { state = false });
darienf 20:6d2af70c92ab 1484 Stop();
darienf 20:6d2af70c92ab 1485 }
darienf 20:6d2af70c92ab 1486 }
darienf 20:6d2af70c92ab 1487
darienf 20:6d2af70c92ab 1488
darienf 20:6d2af70c92ab 1489 private void chkbxCheckedChanged(object sender, EventArgs e)
darienf 20:6d2af70c92ab 1490 {
darienf 20:6d2af70c92ab 1491 /*
darienf 20:6d2af70c92ab 1492 EnableDisableControls(CAL_init, ckbxCal.Checked);
darienf 20:6d2af70c92ab 1493 EnableDisableControls(ECG_InitStart, ckbxEcg.Checked);
darienf 20:6d2af70c92ab 1494 EnableDisableControls(PACE_InitStart, ckbxPace.Checked);
darienf 20:6d2af70c92ab 1495 EnableDisableControls(BIOZ_InitStart, ckbxBioz.Checked);
darienf 20:6d2af70c92ab 1496 EnableDisableControls(ECGFast_Init, ckbxEcg.Checked);
darienf 20:6d2af70c92ab 1497 EnableDisableControls(RtoR_InitStart, ckbxRtoR.Checked);
darienf 20:6d2af70c92ab 1498 */
darienf 20:6d2af70c92ab 1499 }
darienf 20:6d2af70c92ab 1500
darienf 20:6d2af70c92ab 1501 private void btnStartTest_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 1502 {
darienf 20:6d2af70c92ab 1503 System.Windows.Forms.DataVisualization.Charting.Chart test = chartECG;
darienf 20:6d2af70c92ab 1504
darienf 20:6d2af70c92ab 1505 double ymin = test.ChartAreas[0].AxisY.Minimum;
darienf 20:6d2af70c92ab 1506 double ymax = test.ChartAreas[0].AxisY.Maximum;
darienf 20:6d2af70c92ab 1507 if (btnStartTest.Text == "Start Test")
darienf 20:6d2af70c92ab 1508 {
darienf 20:6d2af70c92ab 1509 rpcClient.MAX30001.StartTest();
darienf 20:6d2af70c92ab 1510 btnStartTest.Text = "Stop Test";
darienf 20:6d2af70c92ab 1511 }
darienf 20:6d2af70c92ab 1512 else
darienf 20:6d2af70c92ab 1513 {
darienf 20:6d2af70c92ab 1514 Stop();
darienf 20:6d2af70c92ab 1515 btnStartTest.Text = "Start Test";
darienf 20:6d2af70c92ab 1516 }
darienf 20:6d2af70c92ab 1517
darienf 20:6d2af70c92ab 1518 }
darienf 20:6d2af70c92ab 1519
darienf 20:6d2af70c92ab 1520 public void SetDCLeadOff(int leadOffState)
darienf 20:6d2af70c92ab 1521 {
darienf 20:6d2af70c92ab 1522 if (LeadOffBit(leadOffState, 8)) // check for ECG
darienf 20:6d2af70c92ab 1523 {
darienf 20:6d2af70c92ab 1524 UpdateLeadOffState(lblLdoffPh, LeadOffBit(leadOffState, 3));
darienf 20:6d2af70c92ab 1525 UpdateLeadOffState(lblLdoffPl, LeadOffBit(leadOffState, 2));
darienf 20:6d2af70c92ab 1526 UpdateLeadOffState(lblLdoffNh, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1527 UpdateLeadOffState(lblLdoffNl, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1528 }
darienf 20:6d2af70c92ab 1529 if (LeadOffBit(leadOffState, 9)) // check for BIOZ
darienf 20:6d2af70c92ab 1530 {
darienf 20:6d2af70c92ab 1531 UpdateLeadOffState(lblLdoffPh, LeadOffBit(leadOffState, 3));
darienf 20:6d2af70c92ab 1532 UpdateLeadOffState(lblLdoffPl, LeadOffBit(leadOffState, 2));
darienf 20:6d2af70c92ab 1533 UpdateLeadOffState(lblLdoffNh, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1534 UpdateLeadOffState(lblLdoffNl, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1535 }
darienf 20:6d2af70c92ab 1536 }
darienf 20:6d2af70c92ab 1537
darienf 20:6d2af70c92ab 1538 public void SetACLeadOff(int leadOffState)
darienf 20:6d2af70c92ab 1539 {
darienf 20:6d2af70c92ab 1540 UpdateLeadOffState(lblBioZACOver, LeadOffBit(leadOffState, 0));
darienf 20:6d2af70c92ab 1541 UpdateLeadOffState(lblBioZACUnder, LeadOffBit(leadOffState, 1));
darienf 20:6d2af70c92ab 1542 }
darienf 20:6d2af70c92ab 1543
darienf 20:6d2af70c92ab 1544 //
darienf 20:6d2af70c92ab 1545 // Update LeadOff GUI State
darienf 20:6d2af70c92ab 1546 //
darienf 20:6d2af70c92ab 1547 private void UpdateLeadOffState(TextBox tb, bool state)
darienf 20:6d2af70c92ab 1548 {
darienf 20:6d2af70c92ab 1549 tb.Text = (state == true) ? "1" : "0";
darienf 20:6d2af70c92ab 1550 if (state == true) tb.BackColor = Color.LightGreen;
darienf 20:6d2af70c92ab 1551 else tb.BackColor = Color.Yellow;
darienf 20:6d2af70c92ab 1552 }
darienf 20:6d2af70c92ab 1553
darienf 20:6d2af70c92ab 1554 private void UpdateLeadOffState(Label lbl, bool state)
darienf 20:6d2af70c92ab 1555 {
darienf 20:6d2af70c92ab 1556 lbl.ForeColor = (state == true) ? MaximStyle.MaximColor.Red : MaximStyle.MaximColor.Green;
darienf 20:6d2af70c92ab 1557 }
darienf 20:6d2af70c92ab 1558
darienf 20:6d2af70c92ab 1559 /* Inner Classes of EcgView */
darienf 20:6d2af70c92ab 1560
darienf 20:6d2af70c92ab 1561
darienf 20:6d2af70c92ab 1562
darienf 20:6d2af70c92ab 1563 /// <summary>
darienf 20:6d2af70c92ab 1564 /// Information used to generate the X-axis of a chart
darienf 20:6d2af70c92ab 1565 /// </summary>
darienf 20:6d2af70c92ab 1566 public class ChartInfo
darienf 20:6d2af70c92ab 1567 {
darienf 20:6d2af70c92ab 1568 /// <summary>
darienf 20:6d2af70c92ab 1569 /// Sample Rate
darienf 20:6d2af70c92ab 1570 /// </summary>
darienf 20:6d2af70c92ab 1571 private double sampleRate = 0;
darienf 20:6d2af70c92ab 1572 public double SampleRate
darienf 20:6d2af70c92ab 1573 {
darienf 20:6d2af70c92ab 1574 get
darienf 20:6d2af70c92ab 1575 {
darienf 20:6d2af70c92ab 1576 return sampleRate;
darienf 20:6d2af70c92ab 1577 }
darienf 20:6d2af70c92ab 1578 set
darienf 20:6d2af70c92ab 1579 {
darienf 20:6d2af70c92ab 1580 sampleRate = value;
darienf 20:6d2af70c92ab 1581 points = Convert.ToInt32(length * sampleRate / average);
darienf 20:6d2af70c92ab 1582 }
darienf 20:6d2af70c92ab 1583 }
darienf 20:6d2af70c92ab 1584
darienf 20:6d2af70c92ab 1585 /// <summary>
darienf 20:6d2af70c92ab 1586 /// Length of chart in seconds
darienf 20:6d2af70c92ab 1587 /// </summary>
darienf 20:6d2af70c92ab 1588 private int length = 1;
darienf 20:6d2af70c92ab 1589 public int Length
darienf 20:6d2af70c92ab 1590 {
darienf 20:6d2af70c92ab 1591 get
darienf 20:6d2af70c92ab 1592 {
darienf 20:6d2af70c92ab 1593 return length;
darienf 20:6d2af70c92ab 1594 }
darienf 20:6d2af70c92ab 1595 set
darienf 20:6d2af70c92ab 1596 {
darienf 20:6d2af70c92ab 1597 length = value;
darienf 20:6d2af70c92ab 1598 points = Convert.ToInt32(length * sampleRate / average);
darienf 20:6d2af70c92ab 1599 }
darienf 20:6d2af70c92ab 1600 }
darienf 20:6d2af70c92ab 1601
darienf 20:6d2af70c92ab 1602 /// <summary>
darienf 20:6d2af70c92ab 1603 /// Number of total points in chart
darienf 20:6d2af70c92ab 1604 /// </summary>
darienf 20:6d2af70c92ab 1605 private int points = 1;
darienf 20:6d2af70c92ab 1606 public int Points
darienf 20:6d2af70c92ab 1607 {
darienf 20:6d2af70c92ab 1608 get
darienf 20:6d2af70c92ab 1609 {
darienf 20:6d2af70c92ab 1610 return points;
darienf 20:6d2af70c92ab 1611 }
darienf 20:6d2af70c92ab 1612 }
darienf 20:6d2af70c92ab 1613
darienf 20:6d2af70c92ab 1614 public int Gain;
darienf 20:6d2af70c92ab 1615
darienf 20:6d2af70c92ab 1616 private int average = 1;
darienf 20:6d2af70c92ab 1617 public int Average
darienf 20:6d2af70c92ab 1618 {
darienf 20:6d2af70c92ab 1619 get
darienf 20:6d2af70c92ab 1620 {
darienf 20:6d2af70c92ab 1621 return average;
darienf 20:6d2af70c92ab 1622 }
darienf 20:6d2af70c92ab 1623 set
darienf 20:6d2af70c92ab 1624 {
darienf 20:6d2af70c92ab 1625 average = value;
darienf 20:6d2af70c92ab 1626 points = Convert.ToInt32(length * sampleRate / average);
darienf 20:6d2af70c92ab 1627 }
darienf 20:6d2af70c92ab 1628 }
darienf 20:6d2af70c92ab 1629
darienf 20:6d2af70c92ab 1630 /// <summary>
darienf 20:6d2af70c92ab 1631 /// Value passed the threshold is negative
darienf 20:6d2af70c92ab 1632 /// </summary>
darienf 20:6d2af70c92ab 1633 private int threshold = Int32.MaxValue;
darienf 20:6d2af70c92ab 1634 public int Threshold
darienf 20:6d2af70c92ab 1635 {
darienf 20:6d2af70c92ab 1636 get
darienf 20:6d2af70c92ab 1637 {
darienf 20:6d2af70c92ab 1638 return threshold;
darienf 20:6d2af70c92ab 1639 }
darienf 20:6d2af70c92ab 1640 set
darienf 20:6d2af70c92ab 1641 {
darienf 20:6d2af70c92ab 1642 threshold = value;
darienf 20:6d2af70c92ab 1643 }
darienf 20:6d2af70c92ab 1644 }
darienf 20:6d2af70c92ab 1645
darienf 20:6d2af70c92ab 1646 /// <summary>
darienf 20:6d2af70c92ab 1647 /// Amount to offset value by to convert to negative
darienf 20:6d2af70c92ab 1648 /// </summary>
darienf 20:6d2af70c92ab 1649 private int offset = 0;
darienf 20:6d2af70c92ab 1650 public int Offset
darienf 20:6d2af70c92ab 1651 {
darienf 20:6d2af70c92ab 1652 get
darienf 20:6d2af70c92ab 1653 {
darienf 20:6d2af70c92ab 1654 return offset;
darienf 20:6d2af70c92ab 1655 }
darienf 20:6d2af70c92ab 1656 set
darienf 20:6d2af70c92ab 1657 {
darienf 20:6d2af70c92ab 1658 offset = value;
darienf 20:6d2af70c92ab 1659 }
darienf 20:6d2af70c92ab 1660 }
darienf 20:6d2af70c92ab 1661
darienf 20:6d2af70c92ab 1662 /// <summary>
darienf 20:6d2af70c92ab 1663 /// Number of bits to shift raw data by
darienf 20:6d2af70c92ab 1664 /// </summary>
darienf 20:6d2af70c92ab 1665 public int Shift;
darienf 20:6d2af70c92ab 1666
darienf 20:6d2af70c92ab 1667
darienf 20:6d2af70c92ab 1668 /// <summary>
darienf 20:6d2af70c92ab 1669 /// Current generator for BioZ
darienf 20:6d2af70c92ab 1670 /// </summary>
darienf 20:6d2af70c92ab 1671 public int CurrentGenerator;
darienf 20:6d2af70c92ab 1672
darienf 20:6d2af70c92ab 1673 public Chart Chart;
darienf 20:6d2af70c92ab 1674
darienf 20:6d2af70c92ab 1675 public String SeriesName;
darienf 20:6d2af70c92ab 1676 }
darienf 20:6d2af70c92ab 1677
darienf 20:6d2af70c92ab 1678 public class PacePoint
darienf 20:6d2af70c92ab 1679 {
darienf 20:6d2af70c92ab 1680 public double Time;
darienf 20:6d2af70c92ab 1681 public bool Polarity;
darienf 20:6d2af70c92ab 1682
darienf 20:6d2af70c92ab 1683 public PacePoint(double time, bool polarity)
darienf 20:6d2af70c92ab 1684 {
darienf 20:6d2af70c92ab 1685 this.Time = time;
darienf 20:6d2af70c92ab 1686 this.Polarity = polarity;
darienf 20:6d2af70c92ab 1687 }
darienf 20:6d2af70c92ab 1688 }
darienf 20:6d2af70c92ab 1689
darienf 20:6d2af70c92ab 1690 // DEBUG
darienf 20:6d2af70c92ab 1691 int offsetTest = 0;
darienf 20:6d2af70c92ab 1692 private void button1_Click(object sender, EventArgs e)
darienf 20:6d2af70c92ab 1693 {
darienf 20:6d2af70c92ab 1694 //timer1.Enabled = !timer1.Enabled;
darienf 20:6d2af70c92ab 1695 chartECG.Series["SeriesPace"].Points.AddXY(1.99354553222656 + offsetTest, 0.05 * (1));
darienf 20:6d2af70c92ab 1696 chartECG.Series["SeriesPaceFalling"].Points.AddXY(1.99455261230469 + offsetTest, -0.08 * (1));
darienf 20:6d2af70c92ab 1697
darienf 20:6d2af70c92ab 1698 offsetTest += 100;
darienf 20:6d2af70c92ab 1699 }
darienf 20:6d2af70c92ab 1700
darienf 20:6d2af70c92ab 1701 // DEBUG
darienf 20:6d2af70c92ab 1702 private void timer1_Tick(object sender, EventArgs e)
darienf 20:6d2af70c92ab 1703 {
darienf 20:6d2af70c92ab 1704 /*
darienf 20:6d2af70c92ab 1705 PartialArrayIntAvailableEventArgs ecg1 = new PartialArrayIntAvailableEventArgs();
darienf 20:6d2af70c92ab 1706 PartialArrayIntAvailableEventArgs ecg2 = new PartialArrayIntAvailableEventArgs();
darienf 20:6d2af70c92ab 1707 PartialArrayIntAvailableEventArgs rr1 = new PartialArrayIntAvailableEventArgs();
darienf 20:6d2af70c92ab 1708
darienf 20:6d2af70c92ab 1709 ecg1.array1 = new int[] { 0x00, 0x00, 0x00, 0x00, 0xfffff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
darienf 20:6d2af70c92ab 1710 ecg2.array1 = new int[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
darienf 20:6d2af70c92ab 1711 rr1.array1 = new int[] { 0x88 };
darienf 20:6d2af70c92ab 1712
darienf 20:6d2af70c92ab 1713 ecg1.reportID = PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG;
darienf 20:6d2af70c92ab 1714 ecg2.reportID = PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG;
darienf 20:6d2af70c92ab 1715 rr1.reportID = PartialArrayIntAvailableEventArgs.PACKET_MAX30001_RTOR;
darienf 20:6d2af70c92ab 1716
darienf 20:6d2af70c92ab 1717 if (clicks % 15 == 0)
darienf 20:6d2af70c92ab 1718 {
darienf 20:6d2af70c92ab 1719 On_AppendChart(this, ecg2);
darienf 20:6d2af70c92ab 1720 }
darienf 20:6d2af70c92ab 1721 else if (clicks % 5 == 0)
darienf 20:6d2af70c92ab 1722 {
darienf 20:6d2af70c92ab 1723 On_AppendChart(this, ecg1);
darienf 20:6d2af70c92ab 1724 On_AppendChart(this, rr1);
darienf 20:6d2af70c92ab 1725 }
darienf 20:6d2af70c92ab 1726 else
darienf 20:6d2af70c92ab 1727 On_AppendChart(this, ecg2);
darienf 20:6d2af70c92ab 1728
darienf 20:6d2af70c92ab 1729 clicks++;
darienf 20:6d2af70c92ab 1730 */
darienf 20:6d2af70c92ab 1731 DisplayEcg(new double[] { 0, 0, 0, 0, 1, 2, 3, 4, 5 }, null, new double[] {-10, -10, -10, -10, -10, -10, 4, -10, -10});
darienf 20:6d2af70c92ab 1732 }
darienf 20:6d2af70c92ab 1733 }
darienf 20:6d2af70c92ab 1734 }