From e8a0b3e3a04f3d743ad6a378e22736674aaeb33b Mon Sep 17 00:00:00 2001 From: Bernd Giesecke Date: Mon, 17 Dec 2018 11:11:47 +0800 Subject: [PATCH 1/2] Sensor values mix up when using multiple sensors When using 2 (or more) sensors on the same device the sensor values read from the sensors can get mixed up. The struct sense is defined as a global and is reused from multiple instances of the MAX30105 class. Solution: Declare sense as class private: --- src/MAX30105.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/MAX30105.cpp b/src/MAX30105.cpp index 230a66f..d95a673 100644 --- a/src/MAX30105.cpp +++ b/src/MAX30105.cpp @@ -135,18 +135,6 @@ static const uint8_t SLOT_GREEN_PILOT = 0x07; static const uint8_t MAX_30105_EXPECTEDPARTID = 0x15; -//The MAX30105 stores up to 32 samples on the IC -//This is additional local storage to the microcontroller -const int STORAGE_SIZE = 4; //Each long is 4 bytes so limit this to fit on your micro -struct Record -{ - uint32_t red[STORAGE_SIZE]; - uint32_t IR[STORAGE_SIZE]; - uint32_t green[STORAGE_SIZE]; - byte head; - byte tail; -} sense; //This is our circular buffer of readings from the sensor - MAX30105::MAX30105() { // Constructor } From 92597b36bbabedbc91972bcdbf362d988710e022 Mon Sep 17 00:00:00 2001 From: Bernd Giesecke Date: Mon, 17 Dec 2018 11:14:23 +0800 Subject: [PATCH 2/2] Sensor values mix up when using multiple sensors When using 2 (or more) sensors on the same device the sensor values read from the sensors can get mixed up. The struct sense is defined as a global and is reused from multiple instances of the MAX30105 class. Solution: Declare sense as class private: --- src/MAX30105.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/MAX30105.h b/src/MAX30105.h index 73a99c5..0dcace7 100644 --- a/src/MAX30105.h +++ b/src/MAX30105.h @@ -140,4 +140,17 @@ class MAX30105 { void readRevisionID(); void bitMask(uint8_t reg, uint8_t mask, uint8_t thing); + + #define STORAGE_SIZE 4 //Each long is 4 bytes so limit this to fit on your micro + typedef struct Record + { + uint32_t red[STORAGE_SIZE]; + uint32_t IR[STORAGE_SIZE]; + uint32_t green[STORAGE_SIZE]; + byte head; + byte tail; + } sense_struct; //This is our circular buffer of readings from the sensor + + sense_struct sense; + };