Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OpticalAlgorithmPresenter.cs Source File

OpticalAlgorithmPresenter.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 Maxim.MAX30101GUI;
00042 using HealthSensorPlatform.View;
00043 using HealthSensorPlatform.CustomControls;
00044 using RPCSupport;
00045 using RPCSupport.Streaming;
00046 
00047 namespace HealthSensorPlatform.Presenter
00048 {
00049     class OpticalAlgorithmPresenter
00050     {
00051         private MaximAlgorithmClass algorithm;
00052         private IOpticalAlgorithmView view;
00053 
00054         private bool streaming;
00055         private int count;
00056 
00057         private bool validRed = false;
00058         private bool validGreen = false;
00059         private bool validIR = false;
00060 
00061         public OpticalAlgorithmPresenter(RPCClient rpcClient, MaximAlgorithmClass algorithm, IOpticalAlgorithmView view)
00062         {
00063             this.algorithm = algorithm;
00064             this.view = view;
00065 
00066             //((OpticalView)view).StreamingStartStop += new OpticalView.StreamingStartStopEventHandler(OnStreamingStartStop);
00067             ((OpticalView)view).StreamingStartStop += new EventHandler<StreamingStartStopEventArgs>(OnStreamingStartStop);
00068             rpcClient.streaming.PartialArrayIntAvailable += new EventHandler<PartialArrayIntAvailableEventArgs>(OnPartialArrayIntAvaible);
00069             algorithm.OnHeartRateSpO2dataAvailable += OnHeartRateSpO2DataAvailable; // view.DisplayAlgorithmResult;
00070         }
00071 
00072         public void OnHeartRateSpO2DataAvailable(double heartRateBPM, bool heartRateBPMValid, double heartRateBPMSignalStrength,
00073                 double spO2Percent, bool spO2PercentValid, double spO2PercentSignalStrength)
00074         {
00075             view.DisplayAlgorithmResult(heartRateBPM, heartRateBPMValid, heartRateBPMSignalStrength,
00076                 spO2Percent, spO2PercentValid, spO2PercentSignalStrength);
00077         }
00078 
00079         public void OnStreamingStartStop(object sender, StreamingStartStopEventArgs e)
00080         {
00081             streaming = e.state;
00082             count = 0;
00083             if (streaming)
00084             {
00085                 algorithm.Clear();
00086                 view.DisplayAlgorithmReset();
00087                 switch (((OpticalView)view).ModeConfiguration)
00088                 {
00089                     case OpticalView.eStreamMode.eHR:
00090                         validRed = true;
00091                         validIR = false;
00092                         validGreen = false;
00093                         break;
00094                     case OpticalView.eStreamMode.eSPO2:
00095                         validRed = true;
00096                         validIR = true;
00097                         validGreen = false;
00098                         break;
00099                     case OpticalView.eStreamMode.eMulti:
00100                         validRed = true;
00101                         validIR = true;
00102                         validGreen = true;
00103                         break;
00104                 }
00105             }
00106         }
00107 
00108         public void OnPartialArrayIntAvaible(object sender, PartialArrayIntAvailableEventArgs e)
00109         {
00110             int numSamples;
00111 
00112             if (streaming)
00113             {
00114                 if ((e.reportID & 0xF0) == PartialArrayIntAvailableEventArgs.PACKET_MAX30101)
00115                 {
00116                     numSamples = e.array1.Length;
00117 
00118                     for (int i = 0; i < numSamples; i++)
00119                     {
00120                         int red = 0, ir = 0, green = 0;
00121 
00122                         if (e.array1.Length != 0)
00123                         {
00124                             red = e.array1[i];
00125                         }
00126                         if (e.array2.Length != 0)
00127                         {
00128                             ir = e.array2[i];
00129                         }
00130                         if (e.array3.Length != 0)
00131                         {
00132                             green = e.array3[i];
00133                         }
00134 
00135                         algorithm.ConsumeRedIRGreenLEDdata(count, ir, red, green, validIR, validRed, validGreen);
00136                         count++;
00137                     }
00138                 }
00139             }
00140         }
00141     }
00142 }