MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface
Dependencies: USBDevice
Fork of HSP_Release by
MAX30101_RPC.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 "MAX30101_RPC.h" 00034 #include "StringHelper.h" 00035 #include "MAX30101.h" 00036 #include "Streaming.h" 00037 #include "RpcFifo.h" 00038 #include "RpcServer.h" 00039 #include "StringInOut.h" 00040 #include "MAX30101_helper.h" 00041 #include "LIS2DH.h" 00042 #include "Peripherals.h" 00043 #include "DataLoggingService.h" 00044 00045 //****************************************************************************** 00046 int MAX30101_WriteReg(char argStrs[32][32], char replyStrs[32][32]) { 00047 uint8_t args[2]; 00048 uint8_t reply[1]; 00049 ProcessArgs(argStrs, args, sizeof(args)); 00050 reply[0] = 0x80; 00051 FormatReply(reply, sizeof(reply), replyStrs); 00052 return 0; 00053 } 00054 00055 //****************************************************************************** 00056 int MAX30101_ReadReg(char argStrs[32][32], char replyStrs[32][32]) { 00057 uint8_t args[1]; 00058 uint8_t reply[1]; 00059 char value = 0; 00060 ProcessArgs(argStrs, args, sizeof(args)); 00061 reply[0] = (uint8_t)value; 00062 FormatReply(reply, sizeof(reply), replyStrs); 00063 return 0; 00064 } 00065 00066 //****************************************************************************** 00067 int MAX30101_COMMinit(char argStrs[32][32], char replyStrs[32][32]) 00068 { 00069 uint8_t args[4]; 00070 uint8_t return_value = 0; 00071 ProcessArgs(argStrs,args,sizeof(args)); 00072 00073 strcpy(replyStrs[0],"80"); 00074 return return_value; 00075 } 00076 00077 //****************************************************************************** 00078 int MAX30101_SpO2mode_stop(char argStrs[32][32], char replyStrs[32][32]) 00079 { 00080 uint8_t args[4]; 00081 uint8_t return_value = 0; 00082 ProcessArgs(argStrs,args,sizeof(args)); 00083 00084 Peripherals::max30101()->SpO2mode_stop(); 00085 00086 strcpy(replyStrs[0],"80"); 00087 return return_value; 00088 } 00089 00090 //****************************************************************************** 00091 int MAX30101_HRmode_stop(char argStrs[32][32], char replyStrs[32][32]) 00092 { 00093 uint8_t args[4]; 00094 ProcessArgs(argStrs,args,sizeof(args)); 00095 00096 Peripherals::max30101()->HRmode_stop(); 00097 00098 strcpy(replyStrs[0],"80"); 00099 return 0; 00100 } 00101 00102 //****************************************************************************** 00103 int MAX30101_Multimode_stop(char argStrs[32][32], char replyStrs[32][32]) 00104 { 00105 uint8_t args[4]; 00106 ProcessArgs(argStrs,args,sizeof(args)); 00107 00108 Peripherals::max30101()->Multimode_stop(); 00109 00110 strcpy(replyStrs[0],"80"); 00111 return 0; 00112 } 00113 00114 //****************************************************************************** 00115 void ClearInOutFifos() { 00116 fifo_clear(GetStreamOutFifo()); ///< clear stream out fifo 00117 fifo_clear(GetUSBIncomingFifo()); ///< clear USB serial incoming fifo 00118 } 00119 00120 int highDataRate = 0; 00121 #define MAX30101_200HZ 2 00122 #define MAX30101_400HZ 3 00123 00124 /** 00125 * Adjust the threshold of the Accel based on the data rate 00126 * @lis2dhDataRate Data rate of the accel to determine what would be a good threshold value 00127 */ 00128 static int adjustAccelThreshold(int lis2dhDataRate) { 00129 int lis2dhFifoThreshold; 00130 lis2dhFifoThreshold = 31; 00131 if (lis2dhDataRate <= LIS2DH_DATARATE_50HZ) lis2dhFifoThreshold = 4; 00132 if (lis2dhDataRate == LIS2DH_DATARATE_100HZ) lis2dhFifoThreshold = 8; 00133 return lis2dhFifoThreshold; 00134 } 00135 00136 /** 00137 * Evaluate the data rate of the Accel to see if we should stream using a high data rate mode 00138 * @lis2dhDataRate Data rate of the accel to determine if this is a high data rate 00139 */ 00140 static void adjustHighDataRate(int lis2dhDataRate) { 00141 highDataRate = 0; 00142 if (lis2dhDataRate >= LIS2DH_DATARATE_200HZ) highDataRate = 1; 00143 } 00144 00145 //****************************************************************************** 00146 int MAX30101_SpO2mode_init(char argStrs[32][32], char replyStrs[32][32]) 00147 { 00148 uint8_t args[7]; 00149 uint8_t lis2dhDataRate; 00150 uint8_t lis2dhFifoThreshold; 00151 ProcessArgs(argStrs, args, sizeof(args)); 00152 00153 ClearInOutFifos(); 00154 MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1); 00155 Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]); 00156 00157 lis2dhDataRate = args[6]; 00158 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); 00159 adjustHighDataRate(lis2dhDataRate); 00160 00161 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); 00162 LoggingService_StartLoggingUsb(); 00163 00164 strcpy(replyStrs[0],"80"); 00165 return 0; 00166 } 00167 00168 //****************************************************************************** 00169 int MAX30101_SpO2mode_InitStart(char argStrs[32][32], char replyStrs[32][32]) 00170 { 00171 uint8_t args[6]; // Size 00172 ProcessArgs(argStrs, args, sizeof(args)); 00173 00174 ClearInOutFifos(); 00175 MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1); 00176 if (args[2] >= MAX30101_200HZ) { 00177 highDataRate = 1; 00178 } 00179 Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]); 00180 00181 strcpy(replyStrs[0],"80"); 00182 return 0; 00183 } 00184 00185 //****************************************************************************** 00186 int MAX30101_HRmode_init(char argStrs[32][32], char replyStrs[32][32]) 00187 { 00188 uint8_t args[6]; 00189 uint8_t lis2dhDataRate; 00190 uint8_t lis2dhFifoThreshold; 00191 ProcessArgs(argStrs, args, sizeof(args)); 00192 00193 ClearInOutFifos(); 00194 MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1); 00195 Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]); 00196 00197 lis2dhDataRate = args[5]; 00198 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); 00199 adjustHighDataRate(lis2dhDataRate); 00200 00201 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); 00202 LoggingService_StartLoggingUsb(); 00203 strcpy(replyStrs[0],"80"); 00204 return 0; 00205 } 00206 00207 //****************************************************************************** 00208 int MAX30101_HRmode_InitStart(char argStrs[32][32], char replyStrs[32][32]) 00209 { 00210 uint8_t args[5]; 00211 ProcessArgs(argStrs, args, sizeof(args)); 00212 00213 ClearInOutFifos(); 00214 MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1); 00215 if (args[2] >= MAX30101_200HZ) { 00216 highDataRate = 1; 00217 } 00218 Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]); 00219 strcpy(replyStrs[0],"80"); 00220 return 0; 00221 } 00222 00223 //****************************************************************************** 00224 int MAX30101_Multimode_init(char argStrs[32][32], char replyStrs[32][32]) 00225 { 00226 uint8_t args[12]; 00227 uint8_t lis2dhDataRate; 00228 uint8_t lis2dhFifoThreshold; 00229 ProcessArgs(argStrs, args, sizeof(args)); 00230 00231 ClearInOutFifos(); 00232 00233 lis2dhDataRate = args[11]; 00234 lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); 00235 adjustHighDataRate(lis2dhDataRate); 00236 00237 Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); 00238 00239 wait(0.1f); 00240 MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1); 00241 Peripherals::max30101()->Multimode_init(args[0], args[1], args[2], 00242 args[3], args[4], args[5], args[6], 00243 args[7], args[8], args[9], args[10]); 00244 LoggingService_StartLoggingUsb(); 00245 00246 strcpy(replyStrs[0],"80"); 00247 return 0; 00248 } 00249 00250 //****************************************************************************** 00251 int MAX30101_Multimode_InitStart(char argStrs[32][32], char replyStrs[32][32]) 00252 { 00253 uint8_t args[11]; 00254 ProcessArgs(argStrs, args, sizeof(args)); 00255 00256 ClearInOutFifos(); 00257 MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1); 00258 if (args[2] >= MAX30101_200HZ) { 00259 highDataRate = 1; 00260 } 00261 Peripherals::max30101()->Multimode_init(args[0], args[1], args[2], 00262 args[3], args[4], args[5], args[6], 00263 args[7], args[8], args[9], args[10]); 00264 00265 strcpy(replyStrs[0],"80"); 00266 return 0; 00267 } 00268 00269 00270
Generated on Tue Jul 12 2022 17:59:19 by 1.7.2