Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/Test/Test_MAX30101.cpp@0:e4a10ed6eb92, 2016-10-25 (annotated)
- Committer:
- jbradshaw
- Date:
- Tue Oct 25 15:22:11 2016 +0000
- Revision:
- 0:e4a10ed6eb92
- Child:
- 1:9490836294ea
tewt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | #include "Test_MAX30101.h" |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include "Test_Utilities.h" |
jbradshaw | 0:e4a10ed6eb92 | 35 | |
jbradshaw | 0:e4a10ed6eb92 | 36 | uint32_t testing_max30101 = 0; |
jbradshaw | 0:e4a10ed6eb92 | 37 | uint32_t testing_max30101_flags[4]; |
jbradshaw | 0:e4a10ed6eb92 | 38 | |
jbradshaw | 0:e4a10ed6eb92 | 39 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 40 | void test_MAX30101(void (*outputString)(const char *)) { |
jbradshaw | 0:e4a10ed6eb92 | 41 | Timer timer; |
jbradshaw | 0:e4a10ed6eb92 | 42 | int totalPass = 1; |
jbradshaw | 0:e4a10ed6eb92 | 43 | int pass; |
jbradshaw | 0:e4a10ed6eb92 | 44 | uint32_t foundHR = 0; |
jbradshaw | 0:e4a10ed6eb92 | 45 | uint32_t foundSPO2 = 0; |
jbradshaw | 0:e4a10ed6eb92 | 46 | uint32_t foundMULTI = 0; |
jbradshaw | 0:e4a10ed6eb92 | 47 | MAX30101 *max30101; |
jbradshaw | 0:e4a10ed6eb92 | 48 | |
jbradshaw | 0:e4a10ed6eb92 | 49 | max30101 = Peripherals::max30101(); |
jbradshaw | 0:e4a10ed6eb92 | 50 | |
jbradshaw | 0:e4a10ed6eb92 | 51 | // display header |
jbradshaw | 0:e4a10ed6eb92 | 52 | outputString("Testing MAX30101|"); |
jbradshaw | 0:e4a10ed6eb92 | 53 | |
jbradshaw | 0:e4a10ed6eb92 | 54 | // clear testing flags |
jbradshaw | 0:e4a10ed6eb92 | 55 | testing_max30101_flags[TESTING_HR_FLAG] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 56 | testing_max30101_flags[TESTING_SPO2_FLAG] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 57 | testing_max30101_flags[TESTING_MULTI_FLAG] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 58 | testing_max30101 = 1; |
jbradshaw | 0:e4a10ed6eb92 | 59 | |
jbradshaw | 0:e4a10ed6eb92 | 60 | // |
jbradshaw | 0:e4a10ed6eb92 | 61 | // start stream (HR) |
jbradshaw | 0:e4a10ed6eb92 | 62 | // |
jbradshaw | 0:e4a10ed6eb92 | 63 | outputString("Start HR Streaming...|"); |
jbradshaw | 0:e4a10ed6eb92 | 64 | max30101->HRmode_init(0x0, 0x00, 0x01, 0x03, |
jbradshaw | 0:e4a10ed6eb92 | 65 | 0x33); // This is the HR mode only (IR LED only) |
jbradshaw | 0:e4a10ed6eb92 | 66 | // look for (HR) streaming |
jbradshaw | 0:e4a10ed6eb92 | 67 | timer.start(); |
jbradshaw | 0:e4a10ed6eb92 | 68 | while (1) { |
jbradshaw | 0:e4a10ed6eb92 | 69 | if ((foundHR == 0) && (testing_max30101_flags[TESTING_HR_FLAG] == 1)) { |
jbradshaw | 0:e4a10ed6eb92 | 70 | foundHR = 1; |
jbradshaw | 0:e4a10ed6eb92 | 71 | outputString("HR Stream: PASS|"); |
jbradshaw | 0:e4a10ed6eb92 | 72 | break; |
jbradshaw | 0:e4a10ed6eb92 | 73 | } |
jbradshaw | 0:e4a10ed6eb92 | 74 | if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { |
jbradshaw | 0:e4a10ed6eb92 | 75 | break; |
jbradshaw | 0:e4a10ed6eb92 | 76 | } |
jbradshaw | 0:e4a10ed6eb92 | 77 | } |
jbradshaw | 0:e4a10ed6eb92 | 78 | if (foundHR == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 79 | outputString("HR Stream: FAIL|"); |
jbradshaw | 0:e4a10ed6eb92 | 80 | totalPass &= pass; |
jbradshaw | 0:e4a10ed6eb92 | 81 | } |
jbradshaw | 0:e4a10ed6eb92 | 82 | // stop stream |
jbradshaw | 0:e4a10ed6eb92 | 83 | max30101->HRmode_stop(); |
jbradshaw | 0:e4a10ed6eb92 | 84 | |
jbradshaw | 0:e4a10ed6eb92 | 85 | // |
jbradshaw | 0:e4a10ed6eb92 | 86 | // start stream (SPO2) |
jbradshaw | 0:e4a10ed6eb92 | 87 | // |
jbradshaw | 0:e4a10ed6eb92 | 88 | outputString("Start SPO2 Streaming...|"); |
jbradshaw | 0:e4a10ed6eb92 | 89 | max30101->SpO2mode_init( |
jbradshaw | 0:e4a10ed6eb92 | 90 | 0xF, 0x00, 0x01, 0x03, 0x33, |
jbradshaw | 0:e4a10ed6eb92 | 91 | 0x33); // This is the SpO2 mode only (Red and IR LED only) |
jbradshaw | 0:e4a10ed6eb92 | 92 | // look for (SPO2) stream |
jbradshaw | 0:e4a10ed6eb92 | 93 | timer.reset(); |
jbradshaw | 0:e4a10ed6eb92 | 94 | while (1) { |
jbradshaw | 0:e4a10ed6eb92 | 95 | if ((foundSPO2 == 0) && (testing_max30101_flags[TESTING_SPO2_FLAG] == 1)) { |
jbradshaw | 0:e4a10ed6eb92 | 96 | foundSPO2 = 1; |
jbradshaw | 0:e4a10ed6eb92 | 97 | outputString("SPO2 Stream: PASS|"); |
jbradshaw | 0:e4a10ed6eb92 | 98 | break; |
jbradshaw | 0:e4a10ed6eb92 | 99 | } |
jbradshaw | 0:e4a10ed6eb92 | 100 | if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { |
jbradshaw | 0:e4a10ed6eb92 | 101 | break; |
jbradshaw | 0:e4a10ed6eb92 | 102 | } |
jbradshaw | 0:e4a10ed6eb92 | 103 | } |
jbradshaw | 0:e4a10ed6eb92 | 104 | if (foundSPO2 == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 105 | outputString("SPO2 Stream: FAIL|"); |
jbradshaw | 0:e4a10ed6eb92 | 106 | totalPass &= pass; |
jbradshaw | 0:e4a10ed6eb92 | 107 | } |
jbradshaw | 0:e4a10ed6eb92 | 108 | // stop stream |
jbradshaw | 0:e4a10ed6eb92 | 109 | max30101->SpO2mode_stop(); |
jbradshaw | 0:e4a10ed6eb92 | 110 | |
jbradshaw | 0:e4a10ed6eb92 | 111 | // |
jbradshaw | 0:e4a10ed6eb92 | 112 | // start stream (MULTI) |
jbradshaw | 0:e4a10ed6eb92 | 113 | // |
jbradshaw | 0:e4a10ed6eb92 | 114 | outputString("Start Multi Streaming...|"); |
jbradshaw | 0:e4a10ed6eb92 | 115 | max30101->Multimode_init(0x00, 0x00, 0x01, 0x03, 0x33, 0x33, 0x33, 0x01, 0x02, |
jbradshaw | 0:e4a10ed6eb92 | 116 | 0x03, 0x00); // Up to 4 LED can be turned on over |
jbradshaw | 0:e4a10ed6eb92 | 117 | // look for (SPO2) stream |
jbradshaw | 0:e4a10ed6eb92 | 118 | timer.reset(); |
jbradshaw | 0:e4a10ed6eb92 | 119 | while (1) { |
jbradshaw | 0:e4a10ed6eb92 | 120 | if ((foundMULTI == 0) && |
jbradshaw | 0:e4a10ed6eb92 | 121 | (testing_max30101_flags[TESTING_MULTI_FLAG] == 1)) { |
jbradshaw | 0:e4a10ed6eb92 | 122 | foundMULTI = 1; |
jbradshaw | 0:e4a10ed6eb92 | 123 | outputString("Multi Stream: PASS|"); |
jbradshaw | 0:e4a10ed6eb92 | 124 | break; |
jbradshaw | 0:e4a10ed6eb92 | 125 | } |
jbradshaw | 0:e4a10ed6eb92 | 126 | if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { |
jbradshaw | 0:e4a10ed6eb92 | 127 | break; |
jbradshaw | 0:e4a10ed6eb92 | 128 | } |
jbradshaw | 0:e4a10ed6eb92 | 129 | } |
jbradshaw | 0:e4a10ed6eb92 | 130 | if (foundMULTI == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 131 | outputString("Multi Stream: FAIL|"); |
jbradshaw | 0:e4a10ed6eb92 | 132 | totalPass &= pass; |
jbradshaw | 0:e4a10ed6eb92 | 133 | } |
jbradshaw | 0:e4a10ed6eb92 | 134 | // stop stream |
jbradshaw | 0:e4a10ed6eb92 | 135 | max30101->Multimode_stop(); |
jbradshaw | 0:e4a10ed6eb92 | 136 | |
jbradshaw | 0:e4a10ed6eb92 | 137 | testing_max30101 = 0; |
jbradshaw | 0:e4a10ed6eb92 | 138 | |
jbradshaw | 0:e4a10ed6eb92 | 139 | timer.stop(); |
jbradshaw | 0:e4a10ed6eb92 | 140 | // final results |
jbradshaw | 0:e4a10ed6eb92 | 141 | outputString("Result: "); |
jbradshaw | 0:e4a10ed6eb92 | 142 | _printPassFail(totalPass, 0, outputString); |
jbradshaw | 0:e4a10ed6eb92 | 143 | } |