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 * Permission is hereby granted, free of charge, to any person obtaining a
darienf 20:6d2af70c92ab 5 * copy of this software and associated documentation files (the "Software"),
darienf 20:6d2af70c92ab 6 * to deal in the Software without restriction, including without limitation
darienf 20:6d2af70c92ab 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
darienf 20:6d2af70c92ab 8 * and/or sell copies of the Software, and to permit persons to whom the
darienf 20:6d2af70c92ab 9 * Software is furnished to do so, subject to the following conditions:
darienf 20:6d2af70c92ab 10 *
darienf 20:6d2af70c92ab 11 * The above copyright notice and this permission notice shall be included
darienf 20:6d2af70c92ab 12 * in all copies or substantial portions of the Software.
darienf 20:6d2af70c92ab 13 *
darienf 20:6d2af70c92ab 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 20:6d2af70c92ab 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 20:6d2af70c92ab 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 20:6d2af70c92ab 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 20:6d2af70c92ab 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 20:6d2af70c92ab 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 20:6d2af70c92ab 20 * OTHER DEALINGS IN THE SOFTWARE.
darienf 20:6d2af70c92ab 21 *
darienf 20:6d2af70c92ab 22 * Except as contained in this notice, the name of Maxim Integrated
darienf 20:6d2af70c92ab 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 20:6d2af70c92ab 24 * Products, Inc. Branding Policy.
darienf 20:6d2af70c92ab 25 *
darienf 20:6d2af70c92ab 26 * The mere transfer of this software does not imply any licenses
darienf 20:6d2af70c92ab 27 * of trade secrets, proprietary technology, copyrights, patents,
darienf 20:6d2af70c92ab 28 * trademarks, maskwork rights, or any other form of intellectual
darienf 20:6d2af70c92ab 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 20:6d2af70c92ab 30 * ownership rights.
darienf 20:6d2af70c92ab 31 *******************************************************************************
darienf 20:6d2af70c92ab 32 */
darienf 20:6d2af70c92ab 33 #include "MAX30101_RPC.h"
darienf 20:6d2af70c92ab 34 #include "StringHelper.h"
darienf 20:6d2af70c92ab 35 #include "MAX30101.h"
darienf 20:6d2af70c92ab 36 #include "Streaming.h"
darienf 20:6d2af70c92ab 37 #include "RpcFifo.h"
darienf 20:6d2af70c92ab 38 #include "RpcServer.h"
darienf 20:6d2af70c92ab 39 #include "StringInOut.h"
darienf 20:6d2af70c92ab 40 #include "MAX30101_helper.h"
darienf 20:6d2af70c92ab 41 #include "LIS2DH.h"
darienf 20:6d2af70c92ab 42 #include "Peripherals.h"
darienf 20:6d2af70c92ab 43 #include "DataLoggingService.h"
darienf 20:6d2af70c92ab 44
darienf 20:6d2af70c92ab 45 //******************************************************************************
darienf 20:6d2af70c92ab 46 int MAX30101_WriteReg(char argStrs[32][32], char replyStrs[32][32]) {
darienf 20:6d2af70c92ab 47 uint8_t args[2];
darienf 20:6d2af70c92ab 48 uint8_t reply[1];
darienf 20:6d2af70c92ab 49 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 50 // Peripherals::max30101()->writeReg(args[0] , args[1]); // pass in the register address and the data
darienf 20:6d2af70c92ab 51 reply[0] = 0x80;
darienf 20:6d2af70c92ab 52 FormatReply(reply, sizeof(reply), replyStrs);
darienf 20:6d2af70c92ab 53 return 0;
darienf 20:6d2af70c92ab 54 }
darienf 20:6d2af70c92ab 55
darienf 20:6d2af70c92ab 56 //******************************************************************************
darienf 20:6d2af70c92ab 57 int MAX30101_ReadReg(char argStrs[32][32], char replyStrs[32][32]) {
darienf 20:6d2af70c92ab 58 uint8_t args[1];
darienf 20:6d2af70c92ab 59 uint8_t reply[1];
darienf 20:6d2af70c92ab 60 char value;
darienf 20:6d2af70c92ab 61 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 62 // Peripherals::max30101()->readReg(args[0] , &value, 1);
darienf 20:6d2af70c92ab 63 reply[0] = (uint8_t)value;
darienf 20:6d2af70c92ab 64 FormatReply(reply, sizeof(reply), replyStrs);
darienf 20:6d2af70c92ab 65 return 0;
darienf 20:6d2af70c92ab 66 }
darienf 20:6d2af70c92ab 67
darienf 20:6d2af70c92ab 68 //******************************************************************************
darienf 20:6d2af70c92ab 69 int MAX30101_COMMinit(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 70 {
darienf 20:6d2af70c92ab 71 uint8_t args[4];
darienf 20:6d2af70c92ab 72 uint8_t return_value;
darienf 20:6d2af70c92ab 73 ProcessArgs(argStrs,args,sizeof(args));
darienf 20:6d2af70c92ab 74
darienf 20:6d2af70c92ab 75 //return_value = max30101_COMMinit(args[0], args[1], args[2], args[3]);
darienf 20:6d2af70c92ab 76
darienf 20:6d2af70c92ab 77 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 78 return return_value;
darienf 20:6d2af70c92ab 79 }
darienf 20:6d2af70c92ab 80
darienf 20:6d2af70c92ab 81 //******************************************************************************
darienf 20:6d2af70c92ab 82 int MAX30101_SpO2mode_stop(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 83 {
darienf 20:6d2af70c92ab 84 uint8_t args[4];
darienf 20:6d2af70c92ab 85 uint8_t return_value;
darienf 20:6d2af70c92ab 86 ProcessArgs(argStrs,args,sizeof(args));
darienf 20:6d2af70c92ab 87
darienf 20:6d2af70c92ab 88 //lis2dh_Stop();
darienf 20:6d2af70c92ab 89 //max30101_SpO2mode_stop();
darienf 20:6d2af70c92ab 90 Peripherals::max30101()->SpO2mode_stop();
darienf 20:6d2af70c92ab 91
darienf 20:6d2af70c92ab 92 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 93 return return_value;
darienf 20:6d2af70c92ab 94 }
darienf 20:6d2af70c92ab 95
darienf 20:6d2af70c92ab 96 //******************************************************************************
darienf 20:6d2af70c92ab 97 int MAX30101_HRmode_stop(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 98 {
darienf 20:6d2af70c92ab 99 uint8_t args[4];
darienf 20:6d2af70c92ab 100 ProcessArgs(argStrs,args,sizeof(args));
darienf 20:6d2af70c92ab 101
darienf 20:6d2af70c92ab 102 //lis2dh_Stop();
darienf 20:6d2af70c92ab 103 Peripherals::max30101()->HRmode_stop();
darienf 20:6d2af70c92ab 104
darienf 20:6d2af70c92ab 105 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 106 return 0;
darienf 20:6d2af70c92ab 107 }
darienf 20:6d2af70c92ab 108
darienf 20:6d2af70c92ab 109 //******************************************************************************
darienf 20:6d2af70c92ab 110 int MAX30101_Multimode_stop(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 111 {
darienf 20:6d2af70c92ab 112 uint8_t args[4];
darienf 20:6d2af70c92ab 113 ProcessArgs(argStrs,args,sizeof(args));
darienf 20:6d2af70c92ab 114
darienf 20:6d2af70c92ab 115 //lis2dh_Stop();
darienf 20:6d2af70c92ab 116 Peripherals::max30101()->Multimode_stop();
darienf 20:6d2af70c92ab 117
darienf 20:6d2af70c92ab 118 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 119 return 0;
darienf 20:6d2af70c92ab 120 }
darienf 20:6d2af70c92ab 121
darienf 20:6d2af70c92ab 122 //******************************************************************************
darienf 20:6d2af70c92ab 123 void ClearInOutFifos() {
darienf 20:6d2af70c92ab 124 fifo_clear(GetStreamOutFifo()); // clear stream out fifo
darienf 20:6d2af70c92ab 125 fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo
darienf 20:6d2af70c92ab 126 }
darienf 20:6d2af70c92ab 127
darienf 20:6d2af70c92ab 128 int highDataRate = 0;
darienf 20:6d2af70c92ab 129 #define MAX30101_200HZ 2
darienf 20:6d2af70c92ab 130 #define MAX30101_400HZ 3
darienf 20:6d2af70c92ab 131
darienf 20:6d2af70c92ab 132 /**
darienf 20:6d2af70c92ab 133 * Adjust the threshold of the Accel based on the data rate
darienf 20:6d2af70c92ab 134 * @lis2dhDataRate Data rate of the accel to determine what would be a good threshold value
darienf 20:6d2af70c92ab 135 */
darienf 20:6d2af70c92ab 136 static int adjustAccelThreshold(int lis2dhDataRate) {
darienf 20:6d2af70c92ab 137 int lis2dhFifoThreshold;
darienf 20:6d2af70c92ab 138 lis2dhFifoThreshold = 31;
darienf 20:6d2af70c92ab 139 if (lis2dhDataRate <= LIS2DH_DATARATE_50HZ) lis2dhFifoThreshold = 4;
darienf 20:6d2af70c92ab 140 if (lis2dhDataRate == LIS2DH_DATARATE_100HZ) lis2dhFifoThreshold = 8;
darienf 20:6d2af70c92ab 141 return lis2dhFifoThreshold;
darienf 20:6d2af70c92ab 142 }
darienf 20:6d2af70c92ab 143
darienf 20:6d2af70c92ab 144 /**
darienf 20:6d2af70c92ab 145 * Evaluate the data rate of the Accel to see if we should stream using a high data rate mode
darienf 20:6d2af70c92ab 146 * @lis2dhDataRate Data rate of the accel to determine if this is a high data rate
darienf 20:6d2af70c92ab 147 */
darienf 20:6d2af70c92ab 148 static void adjustHighDataRate(int lis2dhDataRate) {
darienf 20:6d2af70c92ab 149 highDataRate = 0;
darienf 20:6d2af70c92ab 150 if (lis2dhDataRate >= LIS2DH_DATARATE_200HZ) highDataRate = 1;
darienf 20:6d2af70c92ab 151 }
darienf 20:6d2af70c92ab 152
darienf 20:6d2af70c92ab 153 //******************************************************************************
darienf 20:6d2af70c92ab 154 int MAX30101_SpO2mode_init(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 155 {
darienf 20:6d2af70c92ab 156 uint8_t args[7];
darienf 20:6d2af70c92ab 157 uint8_t lis2dhDataRate;
darienf 20:6d2af70c92ab 158 uint8_t lis2dhFifoThreshold;
darienf 20:6d2af70c92ab 159 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 160
darienf 20:6d2af70c92ab 161 ClearInOutFifos();
darienf 20:6d2af70c92ab 162 MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1);
darienf 20:6d2af70c92ab 163 Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]);
darienf 20:6d2af70c92ab 164
darienf 20:6d2af70c92ab 165 lis2dhDataRate = args[6];
darienf 20:6d2af70c92ab 166 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate);
darienf 20:6d2af70c92ab 167 adjustHighDataRate(lis2dhDataRate);
darienf 20:6d2af70c92ab 168
darienf 20:6d2af70c92ab 169 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold);
darienf 20:6d2af70c92ab 170 LoggingService_StartLoggingUsb();
darienf 20:6d2af70c92ab 171
darienf 20:6d2af70c92ab 172 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 173 return 0;
darienf 20:6d2af70c92ab 174 }
darienf 20:6d2af70c92ab 175
darienf 20:6d2af70c92ab 176 //******************************************************************************
darienf 20:6d2af70c92ab 177 int MAX30101_SpO2mode_InitStart(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 178 {
darienf 20:6d2af70c92ab 179 uint8_t args[6]; // Size
darienf 20:6d2af70c92ab 180 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 181
darienf 20:6d2af70c92ab 182 ClearInOutFifos();
darienf 20:6d2af70c92ab 183 MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1);
darienf 20:6d2af70c92ab 184 if (args[2] >= MAX30101_200HZ) highDataRate = 1;
darienf 20:6d2af70c92ab 185 Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]);
darienf 20:6d2af70c92ab 186
darienf 20:6d2af70c92ab 187 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 188 return 0;
darienf 20:6d2af70c92ab 189 }
darienf 20:6d2af70c92ab 190
darienf 20:6d2af70c92ab 191 //******************************************************************************
darienf 20:6d2af70c92ab 192 int MAX30101_HRmode_init(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 193 {
darienf 20:6d2af70c92ab 194 uint8_t args[6];
darienf 20:6d2af70c92ab 195 uint8_t lis2dhDataRate;
darienf 20:6d2af70c92ab 196 uint8_t lis2dhFifoThreshold;
darienf 20:6d2af70c92ab 197 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 198
darienf 20:6d2af70c92ab 199 ClearInOutFifos();
darienf 20:6d2af70c92ab 200 MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1);
darienf 20:6d2af70c92ab 201 Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]);
darienf 20:6d2af70c92ab 202
darienf 20:6d2af70c92ab 203 lis2dhDataRate = args[5];
darienf 20:6d2af70c92ab 204 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate);
darienf 20:6d2af70c92ab 205 adjustHighDataRate(lis2dhDataRate);
darienf 20:6d2af70c92ab 206
darienf 20:6d2af70c92ab 207 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold);
darienf 20:6d2af70c92ab 208 LoggingService_StartLoggingUsb();
darienf 20:6d2af70c92ab 209 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 210 return 0;
darienf 20:6d2af70c92ab 211 }
darienf 20:6d2af70c92ab 212
darienf 20:6d2af70c92ab 213 //******************************************************************************
darienf 20:6d2af70c92ab 214 int MAX30101_HRmode_InitStart(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 215 {
darienf 20:6d2af70c92ab 216 uint8_t args[5];
darienf 20:6d2af70c92ab 217 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 218
darienf 20:6d2af70c92ab 219 ClearInOutFifos();
darienf 20:6d2af70c92ab 220 MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1);
darienf 20:6d2af70c92ab 221 if (args[2] >= MAX30101_200HZ) highDataRate = 1;
darienf 20:6d2af70c92ab 222 Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]);
darienf 20:6d2af70c92ab 223 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 224 return 0;
darienf 20:6d2af70c92ab 225 }
darienf 20:6d2af70c92ab 226
darienf 20:6d2af70c92ab 227 //******************************************************************************
darienf 20:6d2af70c92ab 228 int MAX30101_Multimode_init(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 229 {
darienf 20:6d2af70c92ab 230 uint8_t args[12];
darienf 20:6d2af70c92ab 231 uint8_t lis2dhDataRate;
darienf 20:6d2af70c92ab 232 uint8_t lis2dhFifoThreshold;
darienf 20:6d2af70c92ab 233 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 234
darienf 20:6d2af70c92ab 235 ClearInOutFifos();
darienf 20:6d2af70c92ab 236
darienf 20:6d2af70c92ab 237 lis2dhDataRate = args[11];
darienf 20:6d2af70c92ab 238 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate);
darienf 20:6d2af70c92ab 239 adjustHighDataRate(lis2dhDataRate);
darienf 20:6d2af70c92ab 240
darienf 20:6d2af70c92ab 241 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold);
darienf 20:6d2af70c92ab 242
darienf 20:6d2af70c92ab 243 wait(0.1f);
darienf 20:6d2af70c92ab 244 MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1);
darienf 20:6d2af70c92ab 245 Peripherals::max30101()->Multimode_init(args[0], args[1], args[2],
darienf 20:6d2af70c92ab 246 args[3], args[4], args[5], args[6],
darienf 20:6d2af70c92ab 247 args[7], args[8], args[9], args[10]);
darienf 20:6d2af70c92ab 248 LoggingService_StartLoggingUsb();
darienf 20:6d2af70c92ab 249
darienf 20:6d2af70c92ab 250 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 251 return 0;
darienf 20:6d2af70c92ab 252 }
darienf 20:6d2af70c92ab 253
darienf 20:6d2af70c92ab 254 //******************************************************************************
darienf 20:6d2af70c92ab 255 int MAX30101_Multimode_InitStart(char argStrs[32][32], char replyStrs[32][32])
darienf 20:6d2af70c92ab 256 {
darienf 20:6d2af70c92ab 257 uint8_t args[11];
darienf 20:6d2af70c92ab 258 ProcessArgs(argStrs, args, sizeof(args));
darienf 20:6d2af70c92ab 259
darienf 20:6d2af70c92ab 260 ClearInOutFifos();
darienf 20:6d2af70c92ab 261 MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1);
darienf 20:6d2af70c92ab 262 if (args[2] >= MAX30101_200HZ) highDataRate = 1;
darienf 20:6d2af70c92ab 263 Peripherals::max30101()->Multimode_init(args[0], args[1], args[2],
darienf 20:6d2af70c92ab 264 args[3], args[4], args[5], args[6],
darienf 20:6d2af70c92ab 265 args[7], args[8], args[9], args[10]);
darienf 20:6d2af70c92ab 266
darienf 20:6d2af70c92ab 267 strcpy(replyStrs[0],"80");
darienf 20:6d2af70c92ab 268 return 0;
darienf 20:6d2af70c92ab 269 }
darienf 20:6d2af70c92ab 270
darienf 20:6d2af70c92ab 271
darienf 20:6d2af70c92ab 272