From f8c87a10deafcecd073b18619293fa5c1e8eb7b9 Mon Sep 17 00:00:00 2001 From: Urmil Modi Date: Sat, 17 Jul 2021 15:40:39 -0400 Subject: [PATCH 1/3] fixed mpu9250 43 second bug and other sensor class bugs --- MPU9250/MPU9250.ino | 27 +++++++++++---------------- RTD/RTD.ino | 24 +++++++++++------------- SPT25-20-0200A/SPT25-20-0200A.ino | 24 +++++++++++------------- SPTD25-20-1000H/SPTD25-20-1000H.ino | 24 +++++++++++------------- Sensor.cpp | 2 +- Sensor.h | 6 +++--- TMP006/TMP006.ino | 24 +++++++++++------------- Template.ino | 6 +++--- VFS500/VFS500.ino | 24 +++++++++++------------- 9 files changed, 73 insertions(+), 88 deletions(-) diff --git a/MPU9250/MPU9250.ino b/MPU9250/MPU9250.ino index 25f2655..0d6a4c4 100644 --- a/MPU9250/MPU9250.ino +++ b/MPU9250/MPU9250.ino @@ -50,23 +50,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - - // vv Recommend commenting this bit out to see FFT printout vv - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } - // ^^ ----------------------------------------------------- ^^ + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/RTD/RTD.ino b/RTD/RTD.ino index 47448ec..822b948 100644 --- a/RTD/RTD.ino +++ b/RTD/RTD.ino @@ -49,20 +49,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/SPT25-20-0200A/SPT25-20-0200A.ino b/SPT25-20-0200A/SPT25-20-0200A.ino index cd16baf..b9698f6 100644 --- a/SPT25-20-0200A/SPT25-20-0200A.ino +++ b/SPT25-20-0200A/SPT25-20-0200A.ino @@ -49,20 +49,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/SPTD25-20-1000H/SPTD25-20-1000H.ino b/SPTD25-20-1000H/SPTD25-20-1000H.ino index 4b1aa8d..7d3d735 100644 --- a/SPTD25-20-1000H/SPTD25-20-1000H.ino +++ b/SPTD25-20-1000H/SPTD25-20-1000H.ino @@ -49,20 +49,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/Sensor.cpp b/Sensor.cpp index 452c41e..d72002d 100644 --- a/Sensor.cpp +++ b/Sensor.cpp @@ -9,7 +9,7 @@ * @param setup - t_datasetup - How many datasets are there? What are their units? * @param delta - uint16_t - The minimum time (in ms) between sensor read attempts. **/ -Sensor::Sensor(sensors_t sensor, arduino_t arduino, t_datasetup setup, uint16_t delta){ +Sensor::Sensor(sensors_t sensor, arduino_t arduino, t_datasetup setup, unsigned long delta){ // Set up cache this->sensor = sensor; this->arduino = arduino; diff --git a/Sensor.h b/Sensor.h index 0d7feeb..9d384e4 100644 --- a/Sensor.h +++ b/Sensor.h @@ -47,8 +47,8 @@ struct t_datasetup { // Sensor class - note the difference in exposure and implementation in read/init and getRead/begin class Sensor{ private: - uint16_t delta; //The minimum time (milliseconds) between sensor updates. - uint16_t lastread; //Timestamp of last read ATTEMPT + unsigned long delta; //The minimum time (milliseconds) between sensor updates. + unsigned long lastread; //Timestamp of last read ATTEMPT protected: // Sensor-specific functionality initialize and read functions - to be implemented by sensor classes virtual errorlevel_t init() = 0; //Connect to sensor, calibrate, set data count and units, and update state accordingly @@ -62,7 +62,7 @@ class Sensor{ // Wrappers return pointer to updated state SensorState* update(); //Calls read(), manages delta, and wraps all t_datum SensorState* begin(); //Sets state in accordance with init() - Sensor(sensors_t sensor, arduino_t arduino, t_datasetup setup, uint16_t delta); + Sensor(sensors_t sensor, arduino_t arduino, t_datasetup setup, unsigned long delta); }; #endif \ No newline at end of file diff --git a/TMP006/TMP006.ino b/TMP006/TMP006.ino index 3645560..c79fa65 100644 --- a/TMP006/TMP006.ino +++ b/TMP006/TMP006.ino @@ -51,20 +51,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/Template.ino b/Template.ino index 2f7cff8..cb17a61 100644 --- a/Template.ino +++ b/Template.ino @@ -92,13 +92,13 @@ void loop(){ Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); - for(int x = 0; x < state.numdata; x++){ + for(int x = 0; x < state->numdata; x++) { Serial.print(state->data[x].data); Serial.print(' '); Serial.print(state->data[x].units); - if(x < state.numdata-1){Serial.print(", ");} + if(x < state->numdata-1){Serial.print(", ");} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); diff --git a/VFS500/VFS500.ino b/VFS500/VFS500.ino index 87a4f47..56f7e8f 100644 --- a/VFS500/VFS500.ino +++ b/VFS500/VFS500.ino @@ -49,20 +49,18 @@ void loop(){ SensorState* state = sensors[i]->update(); // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); - bool _new = (state->debug == DS_NEWREAD); - if(_success){ - if(_new){ - Serial.print("Sensor "); - Serial.print(sensors[i]->sensor); - Serial.print(" read success: "); - for(int x = 0; x < state->numdata; x++){ - Serial.print(state->data[x].data); - Serial.print(' '); - Serial.print(state->data[x].units); - if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} - } + bool _new = (state->debug == DS_SUCCESS); + if(_success && _new){ + Serial.print("Sensor "); + Serial.print(sensors[i]->sensor); + Serial.print(" read success: "); + for(int x = 0; x < state->numdata; x++){ + Serial.print(state->data[x].data); + Serial.print(' '); + Serial.print(state->data[x].units); + if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } - } else { + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.println(" failed to update!"); From 2444873ba435e160f31f52ebf5bd67eae6b02ed6 Mon Sep 17 00:00:00 2001 From: Urmil Modi Date: Sat, 17 Jul 2021 15:45:58 -0400 Subject: [PATCH 2/3] formatting --- MPU9250/MPU9250.ino | 6 +++++- RTD/RTD.ino | 2 +- SPT25-20-0200A/SPT25-20-0200A.ino | 2 +- SPTD25-20-1000H/SPTD25-20-1000H.ino | 2 +- TMP006/TMP006.ino | 2 +- VFS500/VFS500.ino | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MPU9250/MPU9250.ino b/MPU9250/MPU9250.ino index 0d6a4c4..5226813 100644 --- a/MPU9250/MPU9250.ino +++ b/MPU9250/MPU9250.ino @@ -51,7 +51,9 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { + + // vv Recommend commenting this bit out to see FFT printout vv Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); @@ -61,6 +63,8 @@ void loop(){ Serial.print(state->data[x].units); if(x < state->numdata-1){Serial.print(", ");}else{Serial.println();} } + // ^^ ----------------------------------------------------- ^^ + } else if (!_success) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); diff --git a/RTD/RTD.ino b/RTD/RTD.ino index 822b948..8b84954 100644 --- a/RTD/RTD.ino +++ b/RTD/RTD.ino @@ -50,7 +50,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); diff --git a/SPT25-20-0200A/SPT25-20-0200A.ino b/SPT25-20-0200A/SPT25-20-0200A.ino index b9698f6..6630916 100644 --- a/SPT25-20-0200A/SPT25-20-0200A.ino +++ b/SPT25-20-0200A/SPT25-20-0200A.ino @@ -50,7 +50,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); diff --git a/SPTD25-20-1000H/SPTD25-20-1000H.ino b/SPTD25-20-1000H/SPTD25-20-1000H.ino index 7d3d735..10570a3 100644 --- a/SPTD25-20-1000H/SPTD25-20-1000H.ino +++ b/SPTD25-20-1000H/SPTD25-20-1000H.ino @@ -50,7 +50,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); diff --git a/TMP006/TMP006.ino b/TMP006/TMP006.ino index c79fa65..cfa88b9 100644 --- a/TMP006/TMP006.ino +++ b/TMP006/TMP006.ino @@ -52,7 +52,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); diff --git a/VFS500/VFS500.ino b/VFS500/VFS500.ino index 56f7e8f..bae2957 100644 --- a/VFS500/VFS500.ino +++ b/VFS500/VFS500.ino @@ -50,7 +50,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: "); From 9b193e665488fdf7fb10b0144fe8fe7651e0e099 Mon Sep 17 00:00:00 2001 From: Urmil Modi Date: Sat, 17 Jul 2021 15:46:18 -0400 Subject: [PATCH 3/3] formatting --- Template.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Template.ino b/Template.ino index cb17a61..dc59d22 100644 --- a/Template.ino +++ b/Template.ino @@ -88,7 +88,7 @@ void loop(){ // Print/send sensor post-setup state data here. For example: bool _success = (state->error == ERR_NONE); bool _new = (state->debug == DS_SUCCESS); - if(_success && _new){ + if(_success && _new) { Serial.print("Sensor "); Serial.print(sensors[i]->sensor); Serial.print(" read success: ");