MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test_MAX30101.cpp Source File

Test_MAX30101.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #include "Test_MAX30101.h"
00034 #include "Test_Utilities.h"
00035 
00036 uint32_t testing_max30101 = 0;
00037 uint32_t testing_max30101_flags[4];
00038 
00039 //******************************************************************************
00040 void test_MAX30101(void (*outputString)(const char *)) {
00041   Timer timer;
00042   int totalPass = 1;
00043   uint32_t foundHR = 0;
00044   uint32_t foundSPO2 = 0;
00045   uint32_t foundMULTI = 0;
00046   MAX30101 *max30101;
00047 
00048   max30101 = Peripherals::max30101();
00049 
00050   // display header
00051   outputString("Testing MAX30101|");
00052 
00053   // clear testing flags
00054   testing_max30101_flags[TESTING_HR_FLAG] = 0;
00055   testing_max30101_flags[TESTING_SPO2_FLAG] = 0;
00056   testing_max30101_flags[TESTING_MULTI_FLAG] = 0;
00057   testing_max30101 = 1;
00058 
00059   //
00060   // start stream (HR)
00061   //
00062   outputString("Start HR Streaming...|");
00063   max30101->HRmode_init(0x0, 0x00, 0x01, 0x03,
00064                         0x33); // This is the HR mode only (IR LED only)
00065                                // look for (HR) streaming
00066   timer.start();
00067   while (1) {
00068     if ((foundHR == 0) && (testing_max30101_flags[TESTING_HR_FLAG] == 1)) {
00069       foundHR = 1;
00070       outputString("HR Stream: PASS|");
00071       break;
00072     }
00073     if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) {
00074       break;
00075     }
00076   }
00077   if (foundHR == 0) {
00078     outputString("HR Stream: FAIL|");
00079     totalPass = 0;
00080   }
00081   // stop stream
00082   max30101->HRmode_stop();
00083 
00084   //
00085   // start stream (SPO2)
00086   //
00087   outputString("Start SPO2 Streaming...|");
00088   max30101->SpO2mode_init(
00089       0xF, 0x00, 0x01, 0x03, 0x33,
00090       0x33); // This is the SpO2 mode only (Red and IR LED only)
00091   // look for (SPO2) stream
00092   timer.reset();
00093   while (1) {
00094     if ((foundSPO2 == 0) && (testing_max30101_flags[TESTING_SPO2_FLAG] == 1)) {
00095       foundSPO2 = 1;
00096       outputString("SPO2 Stream: PASS|");
00097       break;
00098     }
00099     if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) {
00100       break;
00101     }
00102   }
00103   if (foundSPO2 == 0) {
00104     outputString("SPO2 Stream: FAIL|");
00105     totalPass = 0;
00106   }
00107   // stop stream
00108   max30101->SpO2mode_stop();
00109 
00110   //
00111   // start stream (MULTI)
00112   //
00113   outputString("Start Multi Streaming...|");
00114   max30101->Multimode_init(0x00, 0x00, 0x01, 0x03, 0x33, 0x33, 0x33, 0x01, 0x02,
00115                            0x03, 0x00); // Up to 4 LED can be turned on over
00116   // look for (SPO2) stream
00117   timer.reset();
00118   while (1) {
00119     if ((foundMULTI == 0) &&
00120         (testing_max30101_flags[TESTING_MULTI_FLAG] == 1)) {
00121       foundMULTI = 1;
00122       outputString("Multi Stream: PASS|");
00123       break;
00124     }
00125     if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) {
00126       break;
00127     }
00128   }
00129   if (foundMULTI == 0) {
00130     outputString("Multi Stream: FAIL|");
00131     totalPass = 0;
00132   }
00133   // stop stream
00134   max30101->Multimode_stop();
00135 
00136   testing_max30101 = 0;
00137 
00138   timer.stop();
00139   // final results
00140   outputString("Result: ");
00141   _printPassFail(totalPass, 0, outputString);
00142 }