ME11C Sample Code in Maxim Integrated Team
Dependencies: BMI160 max32630hsp3 MemoryLCD USBDevice
Fork of Host_Software_MAX32664GWEC_SpO2_HR-_EXTE by
SHMAX8614X/SH_Max8614x_BareMetal.cpp@0:b259fd1a88f5, 2019-03-18 (annotated)
- Committer:
- seyhmus.cacina
- Date:
- Mon Mar 18 14:09:48 2019 +0300
- Revision:
- 0:b259fd1a88f5
ME11C Sample Code First Commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| seyhmus.cacina | 0:b259fd1a88f5 | 1 | /******************************************************************************* |
| seyhmus.cacina | 0:b259fd1a88f5 | 2 | * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. |
| seyhmus.cacina | 0:b259fd1a88f5 | 3 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| seyhmus.cacina | 0:b259fd1a88f5 | 5 | * copy of this software and associated documentation files (the "Software"), |
| seyhmus.cacina | 0:b259fd1a88f5 | 6 | * to deal in the Software without restriction, including without limitation |
| seyhmus.cacina | 0:b259fd1a88f5 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| seyhmus.cacina | 0:b259fd1a88f5 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| seyhmus.cacina | 0:b259fd1a88f5 | 9 | * Software is furnished to do so, subject to the following conditions: |
| seyhmus.cacina | 0:b259fd1a88f5 | 10 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 11 | * The above copyright notice and this permission notice shall be included |
| seyhmus.cacina | 0:b259fd1a88f5 | 12 | * in all copies or substantial portions of the Software. |
| seyhmus.cacina | 0:b259fd1a88f5 | 13 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| seyhmus.cacina | 0:b259fd1a88f5 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| seyhmus.cacina | 0:b259fd1a88f5 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| seyhmus.cacina | 0:b259fd1a88f5 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| seyhmus.cacina | 0:b259fd1a88f5 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| seyhmus.cacina | 0:b259fd1a88f5 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| seyhmus.cacina | 0:b259fd1a88f5 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| seyhmus.cacina | 0:b259fd1a88f5 | 21 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
| seyhmus.cacina | 0:b259fd1a88f5 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| seyhmus.cacina | 0:b259fd1a88f5 | 24 | * Products, Inc. Branding Policy. |
| seyhmus.cacina | 0:b259fd1a88f5 | 25 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 26 | * The mere transfer of this software does not imply any licenses |
| seyhmus.cacina | 0:b259fd1a88f5 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
| seyhmus.cacina | 0:b259fd1a88f5 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
| seyhmus.cacina | 0:b259fd1a88f5 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| seyhmus.cacina | 0:b259fd1a88f5 | 30 | * ownership rights. |
| seyhmus.cacina | 0:b259fd1a88f5 | 31 | ******************************************************************************* |
| seyhmus.cacina | 0:b259fd1a88f5 | 32 | */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 33 | #include "SH_Max8614x_BareMetal.h" |
| seyhmus.cacina | 0:b259fd1a88f5 | 34 | #include "SHComm.h" |
| seyhmus.cacina | 0:b259fd1a88f5 | 35 | #include "HostAccelHelper.h" |
| seyhmus.cacina | 0:b259fd1a88f5 | 36 | #include <string.h> //for memset |
| seyhmus.cacina | 0:b259fd1a88f5 | 37 | #include <stdint.h> |
| seyhmus.cacina | 0:b259fd1a88f5 | 38 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 39 | #include "demoDefinitions.h" |
| seyhmus.cacina | 0:b259fd1a88f5 | 40 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 41 | uint16_t HrmResult = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 42 | uint16_t SPO2Result = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 43 | uint8_t HrmConfidence = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 44 | uint8_t SPo2Confidence = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 45 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 46 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 47 | //#define SERIALOUT printf |
| seyhmus.cacina | 0:b259fd1a88f5 | 48 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 49 | #if defined(DEBUG_INFO) |
| seyhmus.cacina | 0:b259fd1a88f5 | 50 | #define __DBGMESSAGE( str , val ) {printf(str, val);} |
| seyhmus.cacina | 0:b259fd1a88f5 | 51 | #else |
| seyhmus.cacina | 0:b259fd1a88f5 | 52 | #define __DBGMESSAGE( str , val ) |
| seyhmus.cacina | 0:b259fd1a88f5 | 53 | #endif |
| seyhmus.cacina | 0:b259fd1a88f5 | 54 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 55 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 56 | // Defines |
| seyhmus.cacina | 0:b259fd1a88f5 | 57 | #define SSMAX8614X_REG_SIZE 1 |
| seyhmus.cacina | 0:b259fd1a88f5 | 58 | #define SSMAX8614X_MODE1_DATASIZE 18 //Taken from API doc |
| seyhmus.cacina | 0:b259fd1a88f5 | 59 | #define SSWHRM_MODE1_DATASIZE 6 //Taken from API doc |
| seyhmus.cacina | 0:b259fd1a88f5 | 60 | #define SSWSPO2_MODE1_DATASIZE 9 // added for wspo2 |
| seyhmus.cacina | 0:b259fd1a88f5 | 61 | #define SSACCEL_MODE1_DATASIZE 6 //Taken from API doc |
| seyhmus.cacina | 0:b259fd1a88f5 | 62 | #define SSAGC_MODE1_DATASIZE 0 //Taken from API doc |
| seyhmus.cacina | 0:b259fd1a88f5 | 63 | #define SSBPT_MODE1_2_DATASIZE 4 //Taken from API doc /* TODO */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 64 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 65 | #define MIN_MACRO(a,b) ((a)<(b)?(a):(b)) |
| seyhmus.cacina | 0:b259fd1a88f5 | 66 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 67 | // sensor configuration |
| seyhmus.cacina | 0:b259fd1a88f5 | 68 | //#define ENABLE_SENSOR_HUB_ACCEL |
| seyhmus.cacina | 0:b259fd1a88f5 | 69 | #define USE_HOST_ACCEL |
| seyhmus.cacina | 0:b259fd1a88f5 | 70 | // algorithm configuration |
| seyhmus.cacina | 0:b259fd1a88f5 | 71 | #define ENABLE_WHRM_AND_SP02 |
| seyhmus.cacina | 0:b259fd1a88f5 | 72 | #define ENABLE_WSP02 |
| seyhmus.cacina | 0:b259fd1a88f5 | 73 | // end of senor and algorithm configuration |
| seyhmus.cacina | 0:b259fd1a88f5 | 74 | #define MAX_NUM_WR_ACC_SAMPLES 5 |
| seyhmus.cacina | 0:b259fd1a88f5 | 75 | #define BMI160_SAMPLE_RATE 25 |
| seyhmus.cacina | 0:b259fd1a88f5 | 76 | // end of defines |
| seyhmus.cacina | 0:b259fd1a88f5 | 77 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 78 | //function pointer use to perform arithmetic operation |
| seyhmus.cacina | 0:b259fd1a88f5 | 79 | typedef void (*rx_data_callback)(uint8_t *); |
| seyhmus.cacina | 0:b259fd1a88f5 | 80 | typedef struct { |
| seyhmus.cacina | 0:b259fd1a88f5 | 81 | int data_size; |
| seyhmus.cacina | 0:b259fd1a88f5 | 82 | rx_data_callback rx_data_parser; |
| seyhmus.cacina | 0:b259fd1a88f5 | 83 | } ss_data_req; |
| seyhmus.cacina | 0:b259fd1a88f5 | 84 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 85 | typedef struct { |
| seyhmus.cacina | 0:b259fd1a88f5 | 86 | int16_t x; |
| seyhmus.cacina | 0:b259fd1a88f5 | 87 | int16_t y; |
| seyhmus.cacina | 0:b259fd1a88f5 | 88 | int16_t z; |
| seyhmus.cacina | 0:b259fd1a88f5 | 89 | } accel_mode1_data; |
| seyhmus.cacina | 0:b259fd1a88f5 | 90 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 91 | typedef struct { |
| seyhmus.cacina | 0:b259fd1a88f5 | 92 | uint32_t led1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 93 | uint32_t led2; |
| seyhmus.cacina | 0:b259fd1a88f5 | 94 | uint32_t led3; |
| seyhmus.cacina | 0:b259fd1a88f5 | 95 | uint32_t led4; |
| seyhmus.cacina | 0:b259fd1a88f5 | 96 | uint32_t led5; |
| seyhmus.cacina | 0:b259fd1a88f5 | 97 | uint32_t led6; |
| seyhmus.cacina | 0:b259fd1a88f5 | 98 | } max8614x_mode1_data; |
| seyhmus.cacina | 0:b259fd1a88f5 | 99 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 100 | typedef struct { |
| seyhmus.cacina | 0:b259fd1a88f5 | 101 | uint16_t hr; |
| seyhmus.cacina | 0:b259fd1a88f5 | 102 | uint8_t hr_conf; |
| seyhmus.cacina | 0:b259fd1a88f5 | 103 | uint16_t spo2; |
| seyhmus.cacina | 0:b259fd1a88f5 | 104 | uint8_t status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 105 | } whrm_mode1_data; |
| seyhmus.cacina | 0:b259fd1a88f5 | 106 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 107 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 108 | typedef struct { /// added for WSPO2 |
| seyhmus.cacina | 0:b259fd1a88f5 | 109 | uint16_t r; |
| seyhmus.cacina | 0:b259fd1a88f5 | 110 | uint8_t spo2_conf; |
| seyhmus.cacina | 0:b259fd1a88f5 | 111 | uint16_t spo2; |
| seyhmus.cacina | 0:b259fd1a88f5 | 112 | uint8_t percentComplete; |
| seyhmus.cacina | 0:b259fd1a88f5 | 113 | uint8_t lowSignalQualityFlag; |
| seyhmus.cacina | 0:b259fd1a88f5 | 114 | uint8_t motionFlag; |
| seyhmus.cacina | 0:b259fd1a88f5 | 115 | uint8_t status; //isSpo2Calculated; |
| seyhmus.cacina | 0:b259fd1a88f5 | 116 | } wspo2_mode1_data; |
| seyhmus.cacina | 0:b259fd1a88f5 | 117 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 118 | typedef struct Max86140_SH_Status_Tracker { |
| seyhmus.cacina | 0:b259fd1a88f5 | 119 | uint8_t sensor_data_from_host; |
| seyhmus.cacina | 0:b259fd1a88f5 | 120 | uint8_t data_type_enabled; // what type of data is enabled |
| seyhmus.cacina | 0:b259fd1a88f5 | 121 | uint8_t sample_count_enabled; // does me11 provide sample count |
| seyhmus.cacina | 0:b259fd1a88f5 | 122 | uint32_t sample_count; |
| seyhmus.cacina | 0:b259fd1a88f5 | 123 | uint8_t data_buf_storage[512]; // store data read from SH |
| seyhmus.cacina | 0:b259fd1a88f5 | 124 | ss_data_req algo_callbacks[SH_NUM_CURRENT_ALGOS]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 125 | ss_data_req sensor_callbacks[SH_NUM_CURRENT_SENSORS]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 126 | uint8_t sensor_enabled_mode[SH_NUM_CURRENT_SENSORS]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 127 | uint8_t algo_enabled_mode[SH_NUM_CURRENT_ALGOS]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 128 | int input_fifo_size; |
| seyhmus.cacina | 0:b259fd1a88f5 | 129 | } Max86140_SH_Status_Tracker_t; |
| seyhmus.cacina | 0:b259fd1a88f5 | 130 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 131 | // Max8614x Default Callbacks |
| seyhmus.cacina | 0:b259fd1a88f5 | 132 | void max8614x_data_rx(uint8_t* data_ptr) |
| seyhmus.cacina | 0:b259fd1a88f5 | 133 | { |
| seyhmus.cacina | 0:b259fd1a88f5 | 134 | max8614x_mode1_data sample; |
| seyhmus.cacina | 0:b259fd1a88f5 | 135 | sample.led1 = (data_ptr[0] << 16) | (data_ptr[1] << 8) | data_ptr[2]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 136 | sample.led2 = (data_ptr[3] << 16) | (data_ptr[4] << 8) | data_ptr[5]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 137 | sample.led3 = (data_ptr[6] << 16) | (data_ptr[7] << 8) | data_ptr[8]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 138 | sample.led4 = (data_ptr[9] << 16) | (data_ptr[10] << 8) | data_ptr[11]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 139 | sample.led5 = (data_ptr[12] << 16) | (data_ptr[13] << 8) | data_ptr[14]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 140 | sample.led6 = (data_ptr[15] << 16) | (data_ptr[16] << 8) | data_ptr[17]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 141 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 142 | //SERIALOUT("led1=%.6X led2=%.6X led3=%.6X led4=%.6X led5=%.6X led6=%.6X\r\n", |
| seyhmus.cacina | 0:b259fd1a88f5 | 143 | // sample.led1, sample.led2, sample.led3, sample.led4, sample.led5, sample.led6); |
| seyhmus.cacina | 0:b259fd1a88f5 | 144 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 145 | //enqueue(&max8614x_queue, &sample); |
| seyhmus.cacina | 0:b259fd1a88f5 | 146 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 147 | void whrm_data_rx(uint8_t* data_ptr) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 148 | //See API doc for data format |
| seyhmus.cacina | 0:b259fd1a88f5 | 149 | whrm_mode1_data sample; |
| seyhmus.cacina | 0:b259fd1a88f5 | 150 | sample.hr = (data_ptr[0] << 8) | data_ptr[1]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 151 | sample.hr_conf = data_ptr[2]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 152 | sample.spo2 = (data_ptr[3] << 8) | data_ptr[4]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 153 | sample.status = data_ptr[5]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 154 | HrmResult = sample.hr / 10; |
| seyhmus.cacina | 0:b259fd1a88f5 | 155 | HrmConfidence = sample.hr_conf; |
| seyhmus.cacina | 0:b259fd1a88f5 | 156 | SERIALOUT("hr_c=%d\r\n", HrmResult); |
| seyhmus.cacina | 0:b259fd1a88f5 | 157 | #if defined(DEBUG_INFO) |
| seyhmus.cacina | 0:b259fd1a88f5 | 158 | SERIALOUT("hr=%.1f conf=%d spo2=%d status=%d\r\n", (float)sample.hr / 10.0, sample.hr_conf, sample.spo2, sample.status); |
| seyhmus.cacina | 0:b259fd1a88f5 | 159 | #endif |
| seyhmus.cacina | 0:b259fd1a88f5 | 160 | //enqueue(&whrm_queue, &sample); |
| seyhmus.cacina | 0:b259fd1a88f5 | 161 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 162 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 163 | void wspo2_data_rx(uint8_t* data_ptr) |
| seyhmus.cacina | 0:b259fd1a88f5 | 164 | { |
| seyhmus.cacina | 0:b259fd1a88f5 | 165 | //See API doc for data format |
| seyhmus.cacina | 0:b259fd1a88f5 | 166 | wspo2_mode1_data sample; |
| seyhmus.cacina | 0:b259fd1a88f5 | 167 | sample.r = (data_ptr[0] << 8) | data_ptr[1]; // already x10 |
| seyhmus.cacina | 0:b259fd1a88f5 | 168 | sample.spo2_conf = data_ptr[2]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 169 | sample.spo2 = (data_ptr[3] << 8) | data_ptr[4]; // already x10 |
| seyhmus.cacina | 0:b259fd1a88f5 | 170 | sample.percentComplete = data_ptr[5]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 171 | sample.lowSignalQualityFlag = data_ptr[6]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 172 | sample.motionFlag = data_ptr[7]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 173 | sample.status = data_ptr[8]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 174 | SPO2Result = sample.spo2 / 10; |
| seyhmus.cacina | 0:b259fd1a88f5 | 175 | SPo2Confidence = sample.spo2_conf; |
| seyhmus.cacina | 0:b259fd1a88f5 | 176 | #if defined(DEBUG_INFO) |
| seyhmus.cacina | 0:b259fd1a88f5 | 177 | SERIALOUT("r=%.1f SpO2Conf=%d SpO2=%.1f prcntComp=%d lowSig=%d motion=%d isCalc=%d\r\n", (float)sample.r / 10.0, sample.spo2_conf, (float)sample.spo2/10.0, sample.percentComplete, sample.lowSignalQualityFlag , sample.motionFlag, sample.status); |
| seyhmus.cacina | 0:b259fd1a88f5 | 178 | #endif |
| seyhmus.cacina | 0:b259fd1a88f5 | 179 | //enqueue(&wspo2_queue, &sample); |
| seyhmus.cacina | 0:b259fd1a88f5 | 180 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 181 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 182 | void accel_data_rx(uint8_t* data_ptr) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 183 | //See API doc for data format |
| seyhmus.cacina | 0:b259fd1a88f5 | 184 | accel_mode1_data sample; |
| seyhmus.cacina | 0:b259fd1a88f5 | 185 | sample.x = (data_ptr[0] << 8) | data_ptr[1]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 186 | sample.y = (data_ptr[2] << 8) | data_ptr[3]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 187 | sample.z = (data_ptr[4] << 8) | data_ptr[5]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 188 | #if defined(DEBUG_INFO) |
| seyhmus.cacina | 0:b259fd1a88f5 | 189 | //SERIALOUT("x:%d, y:%d, z:%d\r\n", sample.x, sample.y, sample.z); |
| seyhmus.cacina | 0:b259fd1a88f5 | 190 | #endif |
| seyhmus.cacina | 0:b259fd1a88f5 | 191 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 192 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 193 | void agc_data_rx(uint8_t* data_ptr) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 194 | //NOP: AGC does not collect data |
| seyhmus.cacina | 0:b259fd1a88f5 | 195 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 196 | // end of Max8614x Default Callbacks |
| seyhmus.cacina | 0:b259fd1a88f5 | 197 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 198 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 199 | static Max86140_SH_Status_Tracker * get_config_struct() { |
| seyhmus.cacina | 0:b259fd1a88f5 | 200 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 201 | /* assigns a static adress to configuration struct*/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 202 | static Max86140_SH_Status_Tracker glbl_max8614x_status_track; |
| seyhmus.cacina | 0:b259fd1a88f5 | 203 | return &glbl_max8614x_status_track; |
| seyhmus.cacina | 0:b259fd1a88f5 | 204 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 205 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 206 | void initialize_config_struct() { |
| seyhmus.cacina | 0:b259fd1a88f5 | 207 | Max86140_SH_Status_Tracker *p_glbl_max8614x_status_track = get_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 208 | /* |
| seyhmus.cacina | 0:b259fd1a88f5 | 209 | * Desc: Configuration init flow, Perform this action at init stage of data acquisition. Raw sesnsor data buffer pointer is input to each |
| seyhmus.cacina | 0:b259fd1a88f5 | 210 | * enabled sensor/algorithm,s funtion that is responsible to extract numeric data from data byte stream from sensor hub. |
| seyhmus.cacina | 0:b259fd1a88f5 | 211 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 212 | * - Append Sensor Raw Data structure with raw sensor data sample size and pointer to function of sensor that is reposible to parse |
| seyhmus.cacina | 0:b259fd1a88f5 | 213 | * data byte stream from sesnor hub and extract sensor numeric data. |
| seyhmus.cacina | 0:b259fd1a88f5 | 214 | * - Append accompanying sensors to main state of sensor. ie Accelerometer from Host with sensor data sample size and pointer to function of |
| seyhmus.cacina | 0:b259fd1a88f5 | 215 | * sensor that is reposible to parse data byte stream from sesnor hub and extract sensor numeric data. |
| seyhmus.cacina | 0:b259fd1a88f5 | 216 | * - Append algorithms to be enabled with algorithm data sample size and pointer to function of |
| seyhmus.cacina | 0:b259fd1a88f5 | 217 | * algorithm that is reposible to parse data byte stream from sensor hub and extract sensor numeric data. |
| seyhmus.cacina | 0:b259fd1a88f5 | 218 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 219 | * */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 220 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 221 | //set all the values to 0 |
| seyhmus.cacina | 0:b259fd1a88f5 | 222 | memset(p_glbl_max8614x_status_track, 0, sizeof(*p_glbl_max8614x_status_track)); |
| seyhmus.cacina | 0:b259fd1a88f5 | 223 | // max8614x |
| seyhmus.cacina | 0:b259fd1a88f5 | 224 | p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_MAX8614X].data_size = SSMAX8614X_MODE1_DATASIZE; |
| seyhmus.cacina | 0:b259fd1a88f5 | 225 | p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_MAX8614X].rx_data_parser = &max8614x_data_rx; |
| seyhmus.cacina | 0:b259fd1a88f5 | 226 | // accelerometer |
| seyhmus.cacina | 0:b259fd1a88f5 | 227 | p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_ACCEL].data_size = SSACCEL_MODE1_DATASIZE; |
| seyhmus.cacina | 0:b259fd1a88f5 | 228 | p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_ACCEL].rx_data_parser = &accel_data_rx; |
| seyhmus.cacina | 0:b259fd1a88f5 | 229 | // agc |
| seyhmus.cacina | 0:b259fd1a88f5 | 230 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_AGC].data_size = SSAGC_MODE1_DATASIZE; |
| seyhmus.cacina | 0:b259fd1a88f5 | 231 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_AGC].rx_data_parser = &agc_data_rx; |
| seyhmus.cacina | 0:b259fd1a88f5 | 232 | // whrm |
| seyhmus.cacina | 0:b259fd1a88f5 | 233 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WHRM].data_size = SSWHRM_MODE1_DATASIZE; |
| seyhmus.cacina | 0:b259fd1a88f5 | 234 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WHRM].rx_data_parser = &whrm_data_rx; |
| seyhmus.cacina | 0:b259fd1a88f5 | 235 | // spo2 |
| seyhmus.cacina | 0:b259fd1a88f5 | 236 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WSPO2].data_size = SSWSPO2_MODE1_DATASIZE; |
| seyhmus.cacina | 0:b259fd1a88f5 | 237 | p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WSPO2].rx_data_parser = &wspo2_data_rx; |
| seyhmus.cacina | 0:b259fd1a88f5 | 238 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 239 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 240 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 241 | void SH_Max8614x_get_reg(uint8_t addr, uint32_t *val) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 242 | int status = sh_get_reg(SH_SENSORIDX_MAX8614X, addr, val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 243 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 244 | if (status == 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 245 | __DBGMESSAGE("\r\n reg_val=%02X err=0 \r\n", ((uint8_t)*val)) |
| seyhmus.cacina | 0:b259fd1a88f5 | 246 | } else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 247 | __DBGMESSAGE("\r\n err=%d\r\n", -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 248 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 249 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 250 | return; |
| seyhmus.cacina | 0:b259fd1a88f5 | 251 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 252 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 253 | int CSTMR_SH_FeedAccDataIntoSH(Max86140_SH_Status_Tracker_t *p_max8614x_status_track) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 254 | static accel_data_t peek_buf[MAX_NUM_WR_ACC_SAMPLES]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 255 | static uint8_t tx_buf[MAX_NUM_WR_ACC_SAMPLES * sizeof(accel_mode1_data) + 2]; // 2 bytes for the command |
| seyhmus.cacina | 0:b259fd1a88f5 | 256 | if(!p_max8614x_status_track->sensor_data_from_host) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 257 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 258 | } else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 259 | accel_data_t accel_data = {0}; |
| seyhmus.cacina | 0:b259fd1a88f5 | 260 | accel_mode1_data acc_sample; |
| seyhmus.cacina | 0:b259fd1a88f5 | 261 | int num_tx, num_samples, num_bytes = 0, num_wr_bytes = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 262 | int num_written_samples, nb_expected; |
| seyhmus.cacina | 0:b259fd1a88f5 | 263 | int ret = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 264 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 265 | // get accelerometer data |
| seyhmus.cacina | 0:b259fd1a88f5 | 266 | ret = CSTMR_SH_HostAccelerometerGet_sensor_xyz(&accel_data); |
| seyhmus.cacina | 0:b259fd1a88f5 | 267 | if (ret < 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 268 | return ret; |
| seyhmus.cacina | 0:b259fd1a88f5 | 269 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 270 | if(CSTMR_SH_HostAccelerometerEnqueueData(&accel_data) != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 271 | __DBGMESSAGE("Thrown an accel sample\n", NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 272 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 273 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 274 | if(CSTMR_SH_HostAccelerometerGetDataCount() < MAX_NUM_WR_ACC_SAMPLES) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 275 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 276 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 277 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 278 | ret = sh_get_num_bytes_in_input_fifo(&num_bytes); |
| seyhmus.cacina | 0:b259fd1a88f5 | 279 | if (ret != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 280 | __DBGMESSAGE("Unable to read num bytes in input fifo\r\n", NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 281 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 282 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 283 | num_tx = p_max8614x_status_track->input_fifo_size - num_bytes; |
| seyhmus.cacina | 0:b259fd1a88f5 | 284 | if (num_tx <= 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 285 | __DBGMESSAGE("num_tx can't be negative\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 286 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 287 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 288 | num_samples = num_tx / sizeof(accel_mode1_data); |
| seyhmus.cacina | 0:b259fd1a88f5 | 289 | num_samples = MIN_MACRO(num_samples, MAX_NUM_WR_ACC_SAMPLES); |
| seyhmus.cacina | 0:b259fd1a88f5 | 290 | num_tx = num_samples * sizeof(accel_mode1_data); |
| seyhmus.cacina | 0:b259fd1a88f5 | 291 | if (num_samples == 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 292 | __DBGMESSAGE("Input FIFO is Full\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 293 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 294 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 295 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 296 | for(int i = 0; i < num_samples; ++i) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 297 | ret |= CSTMR_SH_HostAccelerometerDequeuData(&peek_buf[i]); |
| seyhmus.cacina | 0:b259fd1a88f5 | 298 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 299 | if (ret != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 300 | __DBGMESSAGE("CSTMR_SH_HostAccelerometerDequeuData failed\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 301 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 302 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 303 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 304 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 305 | for (int i = 2, j = 0; j < num_samples; i+= sizeof(accel_mode1_data), j++) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 306 | accel_data = peek_buf[j]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 307 | acc_sample.x = (int16_t)(accel_data.x*1000); |
| seyhmus.cacina | 0:b259fd1a88f5 | 308 | acc_sample.y = (int16_t)(accel_data.y*1000); |
| seyhmus.cacina | 0:b259fd1a88f5 | 309 | acc_sample.z = (int16_t)(accel_data.z*1000); |
| seyhmus.cacina | 0:b259fd1a88f5 | 310 | tx_buf[i] = acc_sample.x; |
| seyhmus.cacina | 0:b259fd1a88f5 | 311 | tx_buf[i + 1] = acc_sample.x >> 8; |
| seyhmus.cacina | 0:b259fd1a88f5 | 312 | tx_buf[i + 2] = acc_sample.y; |
| seyhmus.cacina | 0:b259fd1a88f5 | 313 | tx_buf[i + 3] = acc_sample.y >> 8; |
| seyhmus.cacina | 0:b259fd1a88f5 | 314 | tx_buf[i + 4] = acc_sample.z; |
| seyhmus.cacina | 0:b259fd1a88f5 | 315 | tx_buf[i + 5] = acc_sample.z >> 8; |
| seyhmus.cacina | 0:b259fd1a88f5 | 316 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 317 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 318 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 319 | ret = sh_feed_to_input_fifo(tx_buf, num_tx + 2, &num_wr_bytes); |
| seyhmus.cacina | 0:b259fd1a88f5 | 320 | if(ret != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 321 | __DBGMESSAGE("sh_feed_to_input_fifo\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 322 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 323 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 324 | num_written_samples = num_wr_bytes / sizeof(accel_mode1_data); |
| seyhmus.cacina | 0:b259fd1a88f5 | 325 | if(num_written_samples != num_samples) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 326 | __DBGMESSAGE("num_written_samples failed\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 327 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 328 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 329 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 330 | return 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 331 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 332 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 333 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 334 | void SH_Max8614x_set_reg(uint8_t addr, uint32_t val) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 335 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 336 | status = sh_set_reg(SH_SENSORIDX_MAX8614X, addr, val, SSMAX8614X_REG_SIZE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 337 | __DBGMESSAGE("\r\n err=%d\r\n", status); |
| seyhmus.cacina | 0:b259fd1a88f5 | 338 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 339 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 340 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 341 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 342 | int SH_Max8614x_data_report_execute(void) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 343 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 344 | int num_samples, databufLen; |
| seyhmus.cacina | 0:b259fd1a88f5 | 345 | uint8_t *databuf; |
| seyhmus.cacina | 0:b259fd1a88f5 | 346 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 347 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 348 | Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 349 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 350 | // prepare the buffer to store the results |
| seyhmus.cacina | 0:b259fd1a88f5 | 351 | databuf = p_glbl_max8614x_status_track->data_buf_storage; |
| seyhmus.cacina | 0:b259fd1a88f5 | 352 | databufLen = sizeof(p_glbl_max8614x_status_track->data_buf_storage); |
| seyhmus.cacina | 0:b259fd1a88f5 | 353 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 354 | // poll SH |
| seyhmus.cacina | 0:b259fd1a88f5 | 355 | sh_ss_execute_once(databuf, databufLen, &num_samples); |
| seyhmus.cacina | 0:b259fd1a88f5 | 356 | //__DBGMESSAGE( "nsamplesFIFO: %d \r\n" , num_samples) |
| seyhmus.cacina | 0:b259fd1a88f5 | 357 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 358 | if(num_samples > 0 && num_samples <255) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 359 | //Skip status byte |
| seyhmus.cacina | 0:b259fd1a88f5 | 360 | uint8_t *data_ptr = &databuf[1]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 361 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 362 | int i = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 363 | for (i = 0; i < num_samples; i++) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 364 | int sh_data_type = p_glbl_max8614x_status_track->data_type_enabled; |
| seyhmus.cacina | 0:b259fd1a88f5 | 365 | if (p_glbl_max8614x_status_track->sample_count_enabled) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 366 | p_glbl_max8614x_status_track->sample_count = *data_ptr++; |
| seyhmus.cacina | 0:b259fd1a88f5 | 367 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 368 | //Chop up data and send to modules with enabled sensors |
| seyhmus.cacina | 0:b259fd1a88f5 | 369 | if (sh_data_type == SS_DATATYPE_RAW || sh_data_type == SS_DATATYPE_BOTH) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 370 | for (int i = 0; i < SH_NUM_CURRENT_SENSORS; i++) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 371 | if (p_glbl_max8614x_status_track->sensor_enabled_mode[i]) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 372 | p_glbl_max8614x_status_track->sensor_callbacks[i].rx_data_parser(data_ptr); |
| seyhmus.cacina | 0:b259fd1a88f5 | 373 | data_ptr += p_glbl_max8614x_status_track->sensor_callbacks[i].data_size; |
| seyhmus.cacina | 0:b259fd1a88f5 | 374 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 375 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 376 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 377 | if (sh_data_type == SS_DATATYPE_ALGO || sh_data_type == SS_DATATYPE_BOTH) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 378 | for (int i = 0; i < SH_NUM_CURRENT_ALGOS; i++) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 379 | if (p_glbl_max8614x_status_track->algo_enabled_mode[i]) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 380 | p_glbl_max8614x_status_track->algo_callbacks[i].rx_data_parser(data_ptr); |
| seyhmus.cacina | 0:b259fd1a88f5 | 381 | data_ptr += p_glbl_max8614x_status_track->algo_callbacks[i].data_size; |
| seyhmus.cacina | 0:b259fd1a88f5 | 382 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 383 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 384 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 385 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 386 | /* JUST*/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 387 | CSTMR_SH_FeedAccDataIntoSH(p_glbl_max8614x_status_track); |
| seyhmus.cacina | 0:b259fd1a88f5 | 388 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 389 | // feed accelerometer into me11 |
| seyhmus.cacina | 0:b259fd1a88f5 | 390 | //////////////////CSTMR_SH_FeedAccDataIntoSH(p_glbl_max8614x_status_track); |
| seyhmus.cacina | 0:b259fd1a88f5 | 391 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 392 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 393 | return num_samples; |
| seyhmus.cacina | 0:b259fd1a88f5 | 394 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 395 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 396 | /*MYG: added for Vimo Duan on 26.12.2018 */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 397 | static int SH_Max8614x_set_default_spo2cfg(void){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 398 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 399 | //const uint32_t val[3] = {0x00000000 , 0xfff33dc3, 0x009e943f}; |
| seyhmus.cacina | 0:b259fd1a88f5 | 400 | /*static uint8_t CalCoef[12] = { 0x00, 0x00, 0x00, 0x00, |
| seyhmus.cacina | 0:b259fd1a88f5 | 401 | 0xff, 0xf3, 0x3d, 0xc3, |
| seyhmus.cacina | 0:b259fd1a88f5 | 402 | 0x00, 0x9e, 0x94, 0x3f };*/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 403 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 404 | static uint8_t CalCoef[12] = { 0xff, 0xe6, 0x91, 0x96, |
| seyhmus.cacina | 0:b259fd1a88f5 | 405 | 0x00, 0x0c, 0xb7, 0x35, |
| seyhmus.cacina | 0:b259fd1a88f5 | 406 | 0x00, 0x98, 0x96, 0x80 }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 407 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 408 | int status = sh_set_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_CAL, &CalCoef[0], 12); |
| seyhmus.cacina | 0:b259fd1a88f5 | 409 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 410 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 411 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 412 | int SH_Max8614x_algo_init(enum enAlgoMode paramAlgoMode) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 413 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 414 | /* |
| seyhmus.cacina | 0:b259fd1a88f5 | 415 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 416 | * */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 417 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 418 | Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 419 | if(p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WHRM] || |
| seyhmus.cacina | 0:b259fd1a88f5 | 420 | p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WSPO2]) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 421 | __DBGMESSAGE("\r\n Algo already enabled\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 422 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 423 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 424 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 425 | if(paramAlgoMode == kAlgoModeHeartRate) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 426 | status = sh_enable_algo(SH_ALGOIDX_WHRM, SSWHRM_MODE1_DATASIZE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 427 | if (status != SS_SUCCESS) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 428 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 429 | __DBGMESSAGE("FAILED at line %d, enable whrm\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 430 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 431 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 432 | p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WHRM] = 0x01; |
| seyhmus.cacina | 0:b259fd1a88f5 | 433 | } else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 434 | status = SH_Max8614x_set_default_spo2cfg(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 435 | status = sh_enable_algo(SH_ALGOIDX_WSPO2, SSWSPO2_MODE1_DATASIZE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 436 | if (status != SS_SUCCESS) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 437 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 438 | __DBGMESSAGE("FAILED at line %d, enable whrm\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 439 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 440 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 441 | p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WSPO2] = 0x01; |
| seyhmus.cacina | 0:b259fd1a88f5 | 442 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 443 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 444 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 445 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 446 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 447 | int SH_Max8614x_default_init(enum enAlgoMode paramAlgoMode) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 448 | /* |
| seyhmus.cacina | 0:b259fd1a88f5 | 449 | * Desc: Initialization flow to get algorithm estimation results: |
| seyhmus.cacina | 0:b259fd1a88f5 | 450 | * 1. initialize algorithm config struct |
| seyhmus.cacina | 0:b259fd1a88f5 | 451 | * 2. enable data type to both raw sensor and algorithm data |
| seyhmus.cacina | 0:b259fd1a88f5 | 452 | * 3. get input fifo size to learn fifo capacity |
| seyhmus.cacina | 0:b259fd1a88f5 | 453 | * 4. set fifo threshold for mfio event frequency |
| seyhmus.cacina | 0:b259fd1a88f5 | 454 | * 5. enable sensor to acquire ppg data |
| seyhmus.cacina | 0:b259fd1a88f5 | 455 | * 6. enable accompanying accel sensor |
| seyhmus.cacina | 0:b259fd1a88f5 | 456 | * 7. enable algorithm |
| seyhmus.cacina | 0:b259fd1a88f5 | 457 | * 8. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which |
| seyhmus.cacina | 0:b259fd1a88f5 | 458 | * reports mfio event when data size determined by fifo threshold is written to report fifo |
| seyhmus.cacina | 0:b259fd1a88f5 | 459 | * data can be read by SH_Max8614x_data_report_execute function. |
| seyhmus.cacina | 0:b259fd1a88f5 | 460 | * |
| seyhmus.cacina | 0:b259fd1a88f5 | 461 | * */ |
| seyhmus.cacina | 0:b259fd1a88f5 | 462 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 463 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 464 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 465 | // first initialize the global config struct |
| seyhmus.cacina | 0:b259fd1a88f5 | 466 | initialize_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 467 | Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 468 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 469 | // get input fifo size |
| seyhmus.cacina | 0:b259fd1a88f5 | 470 | status = sh_get_input_fifo_size(&p_glbl_max8614x_status_track->input_fifo_size); |
| seyhmus.cacina | 0:b259fd1a88f5 | 471 | if (status != SS_SUCCESS) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 472 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 473 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 474 | return COMM_GENERAL_ERROR;; |
| seyhmus.cacina | 0:b259fd1a88f5 | 475 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 476 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 477 | // enable both data stype |
| seyhmus.cacina | 0:b259fd1a88f5 | 478 | p_glbl_max8614x_status_track->data_type_enabled = SS_DATATYPE_BOTH; |
| seyhmus.cacina | 0:b259fd1a88f5 | 479 | p_glbl_max8614x_status_track->sample_count_enabled = false; |
| seyhmus.cacina | 0:b259fd1a88f5 | 480 | status = sh_set_data_type(p_glbl_max8614x_status_track->data_type_enabled, |
| seyhmus.cacina | 0:b259fd1a88f5 | 481 | p_glbl_max8614x_status_track->sample_count_enabled); |
| seyhmus.cacina | 0:b259fd1a88f5 | 482 | if (status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 483 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 484 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 485 | return COMM_GENERAL_ERROR; |
| seyhmus.cacina | 0:b259fd1a88f5 | 486 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 487 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 488 | status = sh_set_fifo_thresh(5); |
| seyhmus.cacina | 0:b259fd1a88f5 | 489 | if (status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 490 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 491 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 492 | return COMM_GENERAL_ERROR; |
| seyhmus.cacina | 0:b259fd1a88f5 | 493 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 494 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 495 | status = sh_sensor_enable(SH_SENSORIDX_MAX8614X, SSMAX8614X_MODE1_DATASIZE, SH_INPUT_DATA_DIRECT_SENSOR); |
| seyhmus.cacina | 0:b259fd1a88f5 | 496 | if (status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 497 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 498 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 499 | return COMM_GENERAL_ERROR; |
| seyhmus.cacina | 0:b259fd1a88f5 | 500 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 501 | p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_MAX8614X] = 0x01; |
| seyhmus.cacina | 0:b259fd1a88f5 | 502 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 503 | #ifdef ENABLE_SENSOR_HUB_ACCEL |
| seyhmus.cacina | 0:b259fd1a88f5 | 504 | status = sh_sensor_enable(SH_SENSORIDX_ACCEL, SSACCEL_MODE1_DATASIZE, SH_INPUT_DATA_DIRECT_SENSOR); |
| seyhmus.cacina | 0:b259fd1a88f5 | 505 | if (status != SS_SUCCESS) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 506 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 507 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 508 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 509 | p_glbl_max8614x_status_track->sensor_data_from_host = false; |
| seyhmus.cacina | 0:b259fd1a88f5 | 510 | p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_ACCEL] = 0x01; |
| seyhmus.cacina | 0:b259fd1a88f5 | 511 | #elif defined(USE_HOST_ACCEL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 512 | CSTMR_SH_HostAccelerometerInitialize(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 513 | CSTMR_SH_HostAccelerometerSetDefaults(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 514 | status = CSTMR_SH_HostAccelerometerSetSampleRate(BMI160_SAMPLE_RATE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 515 | if (status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 516 | __DBGMESSAGE("Unable to set BMI160's sample rate\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 517 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 518 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 519 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 520 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 521 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 522 | status = CSTMR_SH_HostAccelerometerEnableDataReadyInterrupt(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 523 | if(status != 0){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 524 | __DBGMESSAGE("Unable to enable BMI160 Interrupt, ret: %d\n", status) |
| seyhmus.cacina | 0:b259fd1a88f5 | 525 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 526 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 527 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 528 | status = sh_sensor_enable(SH_SENSORIDX_ACCEL, SSACCEL_MODE1_DATASIZE, SH_INPUT_DATA_FROM_HOST); |
| seyhmus.cacina | 0:b259fd1a88f5 | 529 | if (status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 530 | __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) |
| seyhmus.cacina | 0:b259fd1a88f5 | 531 | __DBGMESSAGE("FAILED at line %d\n", __LINE__) |
| seyhmus.cacina | 0:b259fd1a88f5 | 532 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 533 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 534 | p_glbl_max8614x_status_track->sensor_data_from_host = true; |
| seyhmus.cacina | 0:b259fd1a88f5 | 535 | p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_ACCEL] = 0x01; |
| seyhmus.cacina | 0:b259fd1a88f5 | 536 | #endif |
| seyhmus.cacina | 0:b259fd1a88f5 | 537 | status = SH_Max8614x_algo_init(paramAlgoMode); |
| seyhmus.cacina | 0:b259fd1a88f5 | 538 | if(status != 0) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 539 | __DBGMESSAGE("AlgoInitFailed\r\n",NULL) |
| seyhmus.cacina | 0:b259fd1a88f5 | 540 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 541 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 542 | __DBGMESSAGE("\r\n err=%d\r\n", status) |
| seyhmus.cacina | 0:b259fd1a88f5 | 543 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 544 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 545 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 546 | void SH_Max8614x_stop() { |
| seyhmus.cacina | 0:b259fd1a88f5 | 547 | sh_disable_irq_mfioevent(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 548 | Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 549 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 550 | for(int i = 0; i < SH_NUM_CURRENT_SENSORS; ++i) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 551 | if(p_glbl_max8614x_status_track->sensor_enabled_mode[i]) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 552 | p_glbl_max8614x_status_track->sensor_enabled_mode[i] = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 553 | sh_sensor_disable(i); |
| seyhmus.cacina | 0:b259fd1a88f5 | 554 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 555 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 556 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 557 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 558 | for(int i = 0; i < SH_NUM_CURRENT_ALGOS; ++i) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 559 | if(p_glbl_max8614x_status_track->algo_enabled_mode[i]) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 560 | p_glbl_max8614x_status_track->algo_enabled_mode[i] = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 561 | sh_disable_algo(i); |
| seyhmus.cacina | 0:b259fd1a88f5 | 562 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 563 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 564 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 565 | if(p_glbl_max8614x_status_track->sensor_data_from_host) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 566 | CSTMR_SH_HostAccelerometerInitialize(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 567 | p_glbl_max8614x_status_track->sensor_data_from_host = 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 568 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 569 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 570 | sh_clear_mfio_event_flag(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 571 | sh_enable_irq_mfioevent(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 572 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 573 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 574 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 575 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 576 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 577 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 578 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 579 | /* ********************************************************************************************** |
| seyhmus.cacina | 0:b259fd1a88f5 | 580 | * * |
| seyhmus.cacina | 0:b259fd1a88f5 | 581 | * COMMAND INTERFACE RELATED METHODS * |
| seyhmus.cacina | 0:b259fd1a88f5 | 582 | * * |
| seyhmus.cacina | 0:b259fd1a88f5 | 583 | * **********************************************************************************************/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 584 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 585 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 586 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 587 | //MYG: CHECK FOR STDIN WITH SSCANF < WHY THEY NEEDED PARSE_CMD????? PAY ATTENTION: HEX AND/OR DECIMAL PARAMETER ENRTY!!! |
| seyhmus.cacina | 0:b259fd1a88f5 | 588 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 589 | static int SH_Max8614x_set_singleparamcfg(const char *cfg , int algo_idx, int cfg_idx ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 590 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 591 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 592 | if( sscanf(cfg, "%*s %*s %*s %10x", &val) == 1 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 593 | uint8_t Temp[1] = { (uint8_t)(val) }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 594 | status = sh_set_algo_cfg(algo_idx, cfg_idx , &Temp[0], 1); |
| seyhmus.cacina | 0:b259fd1a88f5 | 595 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 596 | return status; // if command error return -1 if operational error return >0 error |
| seyhmus.cacina | 0:b259fd1a88f5 | 597 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 598 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 599 | static int SH_Max8614x_get_singleparamcfg( int algo_idx, int cfg_idx , int *val){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 600 | // CMD: get_cfg spo2 samplerate |
| seyhmus.cacina | 0:b259fd1a88f5 | 601 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 602 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 603 | uint8_t rxBuff[1+1]; // first byte is status |
| seyhmus.cacina | 0:b259fd1a88f5 | 604 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 605 | status = sh_get_algo_cfg(algo_idx, cfg_idx, &rxBuff[0], 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 606 | if( status == 0){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 607 | *val = rxBuff[1]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 608 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 609 | *val = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 610 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 611 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 612 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 613 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 614 | static int SH_Max8614x_set_singleparamcfg_(const char *cfg , const int algo_idx, const int cfg_idx , const int paramsz){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 615 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 616 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 617 | if(paramsz == 1 || paramsz == 2) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 618 | if( sscanf(cfg, "%*s %*s %*s %10x", &val) == 1 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 619 | uint8_t Temp[2] = { (uint8_t)((val >> 8) & 0xFF), (uint8_t) (val & 0xFF) }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 620 | status = sh_set_algo_cfg(algo_idx, cfg_idx , &Temp[2-paramsz], paramsz); |
| seyhmus.cacina | 0:b259fd1a88f5 | 621 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 622 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 623 | return status; // if command error return -1 if operational error return >0 error |
| seyhmus.cacina | 0:b259fd1a88f5 | 624 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 625 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 626 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 627 | static int SH_Max8614x_get_singleparamcfg_( const int algo_idx, const int cfg_idx ,const int paramsz, int *val){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 628 | // CMD: get_cfg spo2 samplerate |
| seyhmus.cacina | 0:b259fd1a88f5 | 629 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 630 | int tmp; |
| seyhmus.cacina | 0:b259fd1a88f5 | 631 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 632 | uint8_t rxBuff[3]; // first byte is status 1/2 bytes cfgparam asked for. |
| seyhmus.cacina | 0:b259fd1a88f5 | 633 | if(paramsz == 1 || paramsz == 2) { |
| seyhmus.cacina | 0:b259fd1a88f5 | 634 | status = sh_get_algo_cfg(algo_idx, cfg_idx, &rxBuff[0], paramsz+1); |
| seyhmus.cacina | 0:b259fd1a88f5 | 635 | if( status == 0){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 636 | tmp = (int)((rxBuff[1]<<(8*(paramsz-1))) + rxBuff[2]*(paramsz-1)); // MYG: CHECK IF TRUE! |
| seyhmus.cacina | 0:b259fd1a88f5 | 637 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 638 | tmp = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 639 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 640 | tmp = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 641 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 642 | *val = tmp; |
| seyhmus.cacina | 0:b259fd1a88f5 | 643 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 644 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 645 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 646 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 647 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 648 | /************************************WSPO2 METHODS**********************************************/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 649 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 650 | int SH_Max8614x_get_wspo2_dataformat(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 651 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 652 | SERIALOUT("\r\n format={smpleCnt,8}," |
| seyhmus.cacina | 0:b259fd1a88f5 | 653 | "{irCnt,20},{redCnt,20},{accelX,14,3},{accelY,14,3}," |
| seyhmus.cacina | 0:b259fd1a88f5 | 654 | "{accelZ,14,3},{r,12},{wspo2conf,8},{spo2,11,1},{wspo2percentcomplete,8},{wspo2lowSNR,1},{wspo2motion,1},{status,8} err=0\r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 655 | return 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 656 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 657 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 658 | int SH_Max8614x_measure_wspo2(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 659 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 660 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 661 | SH_Max8614x_stop(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 662 | status = SH_Max8614x_default_init(kAlgoModeSPO2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 663 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 664 | SERIALOUT("whrm started \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 665 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 666 | SERIALOUT("ERR"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 667 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 668 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 669 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 670 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 671 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 672 | int SH_Max8614x_set_ppgreg(const char *addr_value_args){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 673 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 674 | //CMD: set_reg ppgsensor 0xAA 0xAA |
| seyhmus.cacina | 0:b259fd1a88f5 | 675 | int addr,val,status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 676 | if( sscanf(addr_value_args,"%*s %*s %4x %10x", &addr , &addr ) == 2 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 677 | status = sh_set_reg(SH_SENSORIDX_MAX8614X, (uint8_t) addr, (uint32_t) val, SSMAX8614X_REG_SIZE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 678 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 679 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 680 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 681 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 682 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 683 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 684 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 685 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 686 | int SH_Max8614x_get_ppgreg(const char *addr_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 687 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 688 | //CMD: get_reg ppgsensor 0xAA |
| seyhmus.cacina | 0:b259fd1a88f5 | 689 | int addr; |
| seyhmus.cacina | 0:b259fd1a88f5 | 690 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 691 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 692 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 693 | if( sscanf(addr_arg,"%*s %*s %4x", &addr) == 1 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 694 | int status = sh_get_reg(SH_SENSORIDX_MAX8614X, (uint8_t) addr, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 695 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 696 | SERIALOUT("reg_val=%02X \r\n",val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 697 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 698 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 699 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 700 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 701 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 702 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 703 | int SH_Max8614x_self_test_ppg(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 704 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 705 | // MYG: mfio interaction needed! |
| seyhmus.cacina | 0:b259fd1a88f5 | 706 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 707 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 708 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 709 | int SH_Max8614x_self_test_acc(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 710 | // MYG: mfio interaction needed! |
| seyhmus.cacina | 0:b259fd1a88f5 | 711 | return -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 712 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 713 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 714 | int SH_Max8614x_set_spo2_calibration(const char *calib_args){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 715 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 716 | //CMD: set_cfg spo2 cal 0xAAAAAAAA 0xBBBBBBBB 0xCCCCCCCC |
| seyhmus.cacina | 0:b259fd1a88f5 | 717 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 718 | uint32_t val[3]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 719 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 720 | if( sscanf(calib_args,"%*s %*s %*s %10x %10x %10x", &val[0], &val[1], &val[2] ) == 3 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 721 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 722 | uint8_t CalCoef[12] = { (uint8_t)((val[0] >> (3*8)) & 0xFF), (uint8_t)((val[0] >> (2*8)) & 0xFF), (uint8_t)((val[0] >> (1*8)) & 0xFF), (uint8_t)((val[0] >> (0*8)) & 0xFF), // A |
| seyhmus.cacina | 0:b259fd1a88f5 | 723 | (uint8_t)((val[1] >> (3*8)) & 0xFF), (uint8_t)((val[1] >> (2*8)) & 0xFF), (uint8_t)((val[1] >> (1*8)) & 0xFF), (uint8_t)((val[1] >> (0*8)) & 0xFF), // B |
| seyhmus.cacina | 0:b259fd1a88f5 | 724 | (uint8_t)((val[2] >> (3*8)) & 0xFF), (uint8_t)((val[2] >> (2*8)) & 0xFF), (uint8_t)((val[2] >> (1*8)) & 0xFF), (uint8_t)((val[2] >> (0*8)) & 0xFF) // C |
| seyhmus.cacina | 0:b259fd1a88f5 | 725 | }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 726 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 727 | status = sh_set_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_CAL, &CalCoef[0], 12); |
| seyhmus.cacina | 0:b259fd1a88f5 | 728 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 729 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 730 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 731 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 732 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 733 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 734 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 735 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 736 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 737 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 738 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 739 | int SH_Max8614x_get_spo2_calibration(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 740 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 741 | uint8_t rxBuff[12+1]; // first byte is status |
| seyhmus.cacina | 0:b259fd1a88f5 | 742 | uint32_t val[3]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 743 | int status = sh_get_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_CAL, &rxBuff[0], sizeof(rxBuff)); |
| seyhmus.cacina | 0:b259fd1a88f5 | 744 | val[0] = (rxBuff[1]<< 24) + (rxBuff[2]<< 16) + (rxBuff[3]<< 8) + (rxBuff[4]<< 0); |
| seyhmus.cacina | 0:b259fd1a88f5 | 745 | val[1] = (rxBuff[5]<< 24) + (rxBuff[6]<< 16) + (rxBuff[7]<< 8) + (rxBuff[8]<< 0); |
| seyhmus.cacina | 0:b259fd1a88f5 | 746 | val[2] = (rxBuff[9]<< 24) + (rxBuff[10]<< 16) + (rxBuff[11]<< 8) + (rxBuff[12]<< 0); |
| seyhmus.cacina | 0:b259fd1a88f5 | 747 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 748 | SERIALOUT("spo2_calib: A=0x%x B=0x%x C=0x%x" , val[0], val[1], val[2] ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 749 | return 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 750 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 751 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 752 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 753 | int SH_Max8614x_set_spo2_algomode(const char *mode_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 754 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 755 | int status = SH_Max8614x_set_singleparamcfg( mode_arg , SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_ALGO_MODE ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 756 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 757 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 758 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 759 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 760 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 761 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 762 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 763 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 764 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 765 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 766 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 767 | int SH_Max8614x_get_spo2_algomode(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 768 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 769 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 770 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 771 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_ALGO_MODE , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 772 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 773 | SERIALOUT("spo2_algo_mode= %d \r\n", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 774 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 775 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 776 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 777 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 778 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 779 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 780 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 781 | int SH_Max8614x_set_spo2_samplerate(const char *srate_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 782 | //CMD: set_cfg spo2 samplerate sampleRate |
| seyhmus.cacina | 0:b259fd1a88f5 | 783 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 784 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 785 | if( sscanf(srate_arg,"%*s %*s %*s %3u", &val) == 1 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 786 | uint8_t Temp[1] = { (uint8_t)(val) }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 787 | status = sh_set_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_SR, &Temp[0], 1); |
| seyhmus.cacina | 0:b259fd1a88f5 | 788 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 789 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 790 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 791 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 792 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 793 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 794 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 795 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 796 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 797 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 798 | int SH_Max8614x_get_spo2_samplerate(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 799 | // CMD: get_cfg spo2 samplerate |
| seyhmus.cacina | 0:b259fd1a88f5 | 800 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 801 | int status = -1; |
| seyhmus.cacina | 0:b259fd1a88f5 | 802 | uint8_t rxBuff[1+1]; // first byte is status |
| seyhmus.cacina | 0:b259fd1a88f5 | 803 | status = sh_get_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_SR, &rxBuff[0], sizeof(rxBuff)); |
| seyhmus.cacina | 0:b259fd1a88f5 | 804 | if( status == 0){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 805 | val = rxBuff[1]; |
| seyhmus.cacina | 0:b259fd1a88f5 | 806 | SERIALOUT("spo2_samprate= %d \r\n", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 807 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 808 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 809 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 810 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 811 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 812 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 813 | int SH_Max8614x_set_spo2_agcusage(const char *onoff_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 814 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 815 | int status = SH_Max8614x_set_singleparamcfg( onoff_arg , SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_AGC_MODE ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 816 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 817 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 818 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 819 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 820 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 821 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 822 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 823 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 824 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 825 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 826 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 827 | int SH_Max8614x_get_spo2_agcusage(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 828 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 829 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 830 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_AGC_MODE , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 831 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 832 | SERIALOUT("spo2_agc_usage= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 833 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 834 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 835 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 836 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 837 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 838 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 839 | int SH_Max8614x_set_spo2_agctimeout(const char *timeout_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 840 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 841 | int status = SH_Max8614x_set_singleparamcfg( timeout_arg , SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_AGC_TIMEOUT ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 842 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 843 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 844 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 845 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 846 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 847 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 848 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 849 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 850 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 851 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 852 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 853 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 854 | int SH_Max8614x_get_spo2_agctimeout(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 855 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 856 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 857 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_AGC_TIMEOUT , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 858 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 859 | SERIALOUT("spo2_agctimeout= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 860 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 861 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 862 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 863 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 864 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 865 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 866 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 867 | int SH_Max8614x_set_spo2_algotimeout(const char *timeout_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 868 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 869 | int status = SH_Max8614x_set_singleparamcfg( timeout_arg , SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_TIMEOUT ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 870 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 871 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 872 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 873 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 874 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 875 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 876 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 877 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 878 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 879 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 880 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 881 | int SH_Max8614x_get_spo2_algotimeout(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 882 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 883 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 884 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_TIMEOUT , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 885 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 886 | SERIALOUT("spo2_algotimeout= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 887 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 888 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 889 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 890 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 891 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 892 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 893 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 894 | int SH_Max8614x_set_spo2_motionusage(const char *onoff_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 895 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 896 | int status = SH_Max8614x_set_singleparamcfg( onoff_arg, SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_MOTION_DET ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 897 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 898 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 899 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 900 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 901 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 902 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 903 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 904 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 905 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 906 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 907 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 908 | int SH_Max8614x_get_spo2_motionusage(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 909 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 910 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 911 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_MOTION_DET , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 912 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 913 | SERIALOUT("spo2_motion_detection= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 914 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 915 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 916 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 917 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 918 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 919 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 920 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 921 | int SH_Max8614x_set_spo2_motionperiod(const char *period_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 922 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 923 | int status = SH_Max8614x_set_singleparamcfg_(period_arg , SH_ALGOIDX_WSPO2 , SS_CFGIDX_WSPO2_MOTION_PERIOD , 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 924 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 925 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 926 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 927 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 928 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 929 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 930 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 931 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 932 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 933 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 934 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 935 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 936 | int SH_Max8614x_get_spo2_motionperiod(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 937 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 938 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 939 | int status = SH_Max8614x_get_singleparamcfg_( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_MOTION_PERIOD, 2, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 940 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 941 | SERIALOUT("spo2_motionperiod= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 942 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 943 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 944 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 945 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 946 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 947 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 948 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 949 | int SH_Max8614x_set_spo2_motionthresh(const char *thresh_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 950 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 951 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 952 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 953 | if( sscanf(thresh_arg, "%*s %*s %*s %x", &val) == 1 ){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 954 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 955 | uint8_t CalCoef[4] = { (uint8_t)((val >> 24) & 0xFF),(uint8_t)((val >> 16) & 0xFF),(uint8_t)((val >> 8) & 0xFF), (uint8_t) (val & 0xFF) }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 956 | status = sh_set_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_MOTION_THRESHOLD , &CalCoef[0], 4); |
| seyhmus.cacina | 0:b259fd1a88f5 | 957 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 958 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 959 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 960 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 961 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 962 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 963 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 964 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 965 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 966 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 967 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 968 | int SH_Max8614x_get_spo2_motionthresh(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 969 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 970 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 971 | uint32_t val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 972 | uint8_t rxBuff[4+1]; // first byte is status |
| seyhmus.cacina | 0:b259fd1a88f5 | 973 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 974 | status = sh_get_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_MOTION_THRESHOLD, &rxBuff[0], sizeof(rxBuff)); |
| seyhmus.cacina | 0:b259fd1a88f5 | 975 | if( status == 0){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 976 | val = ((rxBuff[1] & 0xFF)<<24) + ((rxBuff[2] & 0xFF)<<16) + ((rxBuff[3] & 0xFF)<<8) + ((rxBuff[4] & 0xFF)<<0); |
| seyhmus.cacina | 0:b259fd1a88f5 | 977 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 978 | SERIALOUT("spo2_motion_thresh in hex= %x \r\n", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 979 | }else |
| seyhmus.cacina | 0:b259fd1a88f5 | 980 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 981 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 982 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 983 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 984 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 985 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 986 | int SH_Max8614x_set_spo2_pdiodeconfig(const char *pdcfg_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 987 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 988 | int status = SH_Max8614x_set_singleparamcfg( pdcfg_arg, SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_PD_CONFIG ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 989 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 990 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 991 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 992 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 993 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 994 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 995 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 996 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 997 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 998 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 999 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1000 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1001 | int SH_Max8614x_get_spo2_pdiodeconfig(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1002 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1003 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1004 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_PD_CONFIG , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1005 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1006 | SERIALOUT("spo2_pdiode_config= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1007 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1008 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1009 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1010 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1011 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1012 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1013 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1014 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1015 | //************************************WHRM METHODS***********************************************/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1016 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1017 | int SH_Max8614x_get_whrm_dataformat(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1018 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1019 | SERIALOUT("\r\n format={smpleCnt,16}," |
| seyhmus.cacina | 0:b259fd1a88f5 | 1020 | "{grnCnt,20},{grn2Cnt,20},{accelX,14,3},{accelY,14,3}," |
| seyhmus.cacina | 0:b259fd1a88f5 | 1021 | "{accelZ,14,3},{hr,12},{hrconf,8},{spo2,11,1},{activity,8} err=0\r\n" ); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1022 | return 0; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1023 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1024 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1025 | int SH_Max8614x_measure_whrm(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1026 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1027 | int status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1028 | SH_Max8614x_stop(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1029 | status = SH_Max8614x_default_init(kAlgoModeHeartRate); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1030 | if(status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1031 | SERIALOUT("whrm started \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1032 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1033 | SERIALOUT("ERR"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1034 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1035 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1036 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1037 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1038 | int SH_Max8614x_set_whrm_aecusage(const char *onoff_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1039 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1040 | int status = SH_Max8614x_set_singleparamcfg( onoff_arg , SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_AEC_ENABLE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1041 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1042 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1043 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1044 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1045 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1046 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1047 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1048 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1049 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1050 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1051 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1052 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1053 | int SH_Max8614x_get_whrm_aecusage(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1054 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1055 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1056 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_AEC_ENABLE , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1057 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1058 | SERIALOUT("whrm_aec_usage= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1059 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1060 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1061 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1062 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1063 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1064 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1065 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1066 | int SH_Max8614x_set_whrm_scdusage(const char *onoff_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1067 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1068 | int status = SH_Max8614x_set_singleparamcfg( onoff_arg , SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_SCD_ENABLE); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1069 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1070 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1071 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1072 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1073 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1074 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1075 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1076 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1077 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1078 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1079 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1080 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1081 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1082 | int SH_Max8614x_get_whrm_scdusage(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1083 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1084 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1085 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_SCD_ENABLE , &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1086 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1087 | SERIALOUT("whrm_scd_usage= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1088 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1089 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1090 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1091 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1092 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1093 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1094 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1095 | int SH_Max8614x_set_whrm_scdadjperiod(const char *period_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1096 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1097 | int status = SH_Max8614x_set_singleparamcfg_(period_arg , SH_ALGOIDX_WHRM , SS_CFGIDX_WHRM_ADJ_TARGET_PD_CURRENT_PERIOD , 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1098 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1099 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1100 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1101 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1102 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1103 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1104 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1105 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1106 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1107 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1108 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1109 | int SH_Max8614x_get_whrm_scdadjperiod(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1110 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1111 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1112 | int status = SH_Max8614x_get_singleparamcfg_( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_ADJ_TARGET_PD_CURRENT_PERIOD, 2, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1113 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1114 | SERIALOUT("whrm_scd_adjperiod= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1115 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1116 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1117 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1118 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1119 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1120 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1121 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1122 | int SH_Max8614x_set_whrm_scddebouncewin(const char *dwindow_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1123 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1124 | int status = SH_Max8614x_set_singleparamcfg_(dwindow_arg , SH_ALGOIDX_WHRM , SS_CFGIDX_WHRM_SCD_DEBOUNCE_WINDOW , 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1125 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1126 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1127 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1128 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1129 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1130 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1131 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1132 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1133 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1134 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1135 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1136 | int SH_Max8614x_get_whrm_scddebouncewin(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1137 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1138 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1139 | int status = SH_Max8614x_get_singleparamcfg_( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_SCD_DEBOUNCE_WINDOW , 2, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1140 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1141 | SERIALOUT("whrm_scd_debouncewin= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1142 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1143 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1144 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1145 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1146 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1147 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1148 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1149 | int SH_Max8614x_set_whrm_motionthresh(const char *motion_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1150 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1151 | int status = SH_Max8614x_set_singleparamcfg_(motion_arg , SH_ALGOIDX_WHRM , SS_CFGIDX_WHRM_MOTION_MAG_THRESHOLD , 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1152 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1153 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1154 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1155 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1156 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1157 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1158 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1159 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1160 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1161 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1162 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1163 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1164 | int SH_Max8614x_get_whrm_motionthresh(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1165 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1166 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1167 | int status = SH_Max8614x_get_singleparamcfg_( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_MOTION_MAG_THRESHOLD , 2, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1168 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1169 | SERIALOUT("whrm_motion_threshold= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1170 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1171 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1172 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1173 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1174 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1175 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1176 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1177 | int SH_Max8614x_set_whrm_minpdiodecurr(const char *curr_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1178 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1179 | int status = SH_Max8614x_set_singleparamcfg_(curr_arg, SH_ALGOIDX_WHRM , SS_CFGIDX_WHRM_MIN_PD_CURRENT , 2); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1180 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1181 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1182 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1183 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1184 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1185 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1186 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1187 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1188 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1189 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1190 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1191 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1192 | int SH_Max8614x_get_whrm_minpdiodecurr(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1193 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1194 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1195 | int status = SH_Max8614x_get_singleparamcfg_( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_MIN_PD_CURRENT , 2, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1196 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1197 | SERIALOUT("whrm_currentrange= %d", val); // MYG: CHECKIF EXPRESSION IS TRUE! |
| seyhmus.cacina | 0:b259fd1a88f5 | 1198 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1199 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1200 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1201 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1202 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1203 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1204 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1205 | int SH_Max8614x_set_whrm_pdiodeconfig(const char *cfg_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1206 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1207 | int status = SH_Max8614x_set_singleparamcfg( cfg_arg , SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_PD_CONFIG); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1208 | if( status == 0) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1209 | SERIALOUT("OK \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1210 | else { |
| seyhmus.cacina | 0:b259fd1a88f5 | 1211 | if( status == -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1212 | SERIALOUT("CMDERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1213 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1214 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1215 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1216 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1217 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1218 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1219 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1220 | int SH_Max8614x_get_whrm_pdiodeconfig(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1221 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1222 | int val; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1223 | int status = SH_Max8614x_get_singleparamcfg( SH_ALGOIDX_WHRM, SS_CFGIDX_WHRM_PD_CONFIG, &val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1224 | if(val != -1) |
| seyhmus.cacina | 0:b259fd1a88f5 | 1225 | SERIALOUT("whrm_pdiode_config= %d", val); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1226 | else |
| seyhmus.cacina | 0:b259fd1a88f5 | 1227 | SERIALOUT("ERR \r\n"); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1228 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1229 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1230 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1231 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1232 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1233 | int SH_Max8614x_stop_acquisition(const char *null_arg){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1234 | SH_Max8614x_stop(); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1235 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1236 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1237 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1238 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1239 | /*FOR THIS DEMO PURPOSE*/ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1240 | int Max8614x_Set_WSPO2Mode(int mode){ |
| seyhmus.cacina | 0:b259fd1a88f5 | 1241 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1242 | uint8_t Temp[1] = { (uint8_t)(mode) }; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1243 | int status = sh_set_algo_cfg(SH_ALGOIDX_WSPO2, SS_CFGIDX_WSPO2_ALGO_MODE , &Temp[0], 1); |
| seyhmus.cacina | 0:b259fd1a88f5 | 1244 | return status; |
| seyhmus.cacina | 0:b259fd1a88f5 | 1245 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1246 | } |
| seyhmus.cacina | 0:b259fd1a88f5 | 1247 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1248 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1249 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1250 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1251 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1252 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1253 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1254 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1255 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1256 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1257 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1258 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1259 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1260 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1261 | |
| seyhmus.cacina | 0:b259fd1a88f5 | 1262 |
