Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EcgDelay.cs Source File

EcgDelay.cs

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
00003 * 
00004 * This software is protected by copyright laws of the United States and
00005 * of foreign countries. This material may also be protected by patent laws
00006 * and technology transfer regulations of the United States and of foreign
00007 * countries. This software is furnished under a license agreement and/or a
00008 * nondisclosure agreement and may only be used or reproduced in accordance
00009 * with the terms of those agreements. Dissemination of this information to
00010 * any party or parties not specified in the license agreement and/or
00011 * nondisclosure agreement is expressly prohibited.
00012 *
00013 * The above copyright notice and this permission notice shall be included
00014 * in all copies or substantial portions of the Software.
00015 *
00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00022 * OTHER DEALINGS IN THE SOFTWARE.
00023 *
00024 * Except as contained in this notice, the name of Maxim Integrated
00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00026 * Products, Inc. Branding Policy.
00027 *
00028 * The mere transfer of this software does not imply any licenses
00029 * of trade secrets, proprietary technology, copyrights, patents,
00030 * trademarks, maskwork rights, or any other form of intellectual
00031 * property whatsoever. Maxim Integrated Products, Inc. retains all
00032 * ownership rights.
00033 *******************************************************************************
00034 */
00035 
00036 using System;
00037 using System.Collections.Generic;
00038 using System.Linq;
00039 using System.Text;
00040 
00041 using HealthSensorPlatform.CustomControls;
00042 
00043 namespace HealthSensorPlatform.Presenter
00044 {
00045     class EcgDelay
00046     {
00047         public const int RToRMaxValue = 0x3FFF;
00048 
00049         List<double> ecg;
00050         List<string> pace;
00051         List<double> rToR;
00052 
00053         //bool enableEcg;
00054         //bool enablePace;
00055         bool enableRToR;
00056 
00057         int offset;
00058 
00059         RToRCalculator rToRCalculator;
00060 
00061         bool firstRToR = true;
00062 
00063         public EcgDelay(bool enableRToR, int fmstr, int ecgSampleRate, int dlpf, int rWndw)
00064         {
00065             ecg = new List<double>();
00066             pace = new List<string>();
00067             rToR = new List<double>();
00068 
00069             this.enableRToR = enableRToR;
00070 
00071             rToRCalculator = new RToRCalculator(fmstr, ecgSampleRate, dlpf, rWndw);
00072 
00073             offset = rToRCalculator.EcgPoints(0, true) * -1;
00074         }
00075 
00076         public void AddEcg(double[] ecgVoltage)
00077         {
00078             ecg.AddRange(ecgVoltage);
00079         }
00080 
00081         public void AddPace(string[] paceLog)
00082         {
00083             pace.AddRange(paceLog);
00084         }
00085 
00086         public void AddRToR(int rToRRaw)
00087         {
00088             int rToREcg;
00089 
00090             if (firstRToR)
00091             {
00092                 rToREcg = rToRCalculator.EcgPoints(rToRRaw, true);
00093                 firstRToR = false;
00094             }
00095             else
00096             {
00097                 rToREcg = rToRCalculator.EcgPoints(rToRRaw, false);
00098             }
00099 
00100             for (int i = 1; i < rToREcg; i++)
00101             {
00102                 rToR.Add(0);
00103             }
00104 
00105             if (rToRRaw != RToRMaxValue)
00106                 rToR.Add(rToRCalculator.Millisecond(rToRRaw));
00107             else
00108                 rToR.Add(0);
00109         }
00110 
00111         public bool HasData()
00112         {
00113             if (enableRToR)
00114                 return offset + 10 < rToR.Count;
00115             else
00116                 return offset + 10 < ecg.Count;
00117         }
00118 
00119         public bool HasFinalData()
00120         {
00121             return ecg.Count > 0;
00122         }
00123 
00124         public Tuple<double[], string[], double[]> GetEcg()
00125         {
00126             double[] ecgVoltage;
00127             string[] paceGroup;
00128             double[] rToRInterval;
00129 
00130             int size;
00131 
00132             if (enableRToR)
00133                 size = rToR.Count - offset - 10;
00134             else
00135                 size = ecg.Count; // No delay needed if R To R is disabled, dump all points
00136 
00137 
00138             ecgVoltage = new double[size];
00139             paceGroup = new string[size];
00140             rToRInterval = new double[size];
00141 
00142             for (int i = 0; i < size; i++ )
00143             {
00144                 ecgVoltage[i] = ecg[i];
00145                 paceGroup[i] = pace[i];
00146                 if (enableRToR)
00147                     rToRInterval[i] = rToR[i];
00148             }
00149 
00150             ecg.RemoveRange(0, size);
00151             pace.RemoveRange(0, size);
00152             if (enableRToR)
00153                 rToR.RemoveRange(0, size);
00154 
00155             return new Tuple<double[],string[],double[]>(ecgVoltage, paceGroup, rToRInterval);
00156         }
00157 
00158         public Tuple<double[], string[], double[]> GetAllEcg()
00159         {
00160             double[] rToRZeroData = new double[ecg.Count];
00161 
00162             for (int i = 0; i < rToR.Count; i++)
00163                 rToRZeroData[i] = rToR[i];
00164 
00165             return new Tuple<double[], string[], double[]>(ecg.ToArray(), pace.ToArray(), rToRZeroData);
00166         }
00167     }
00168 }