From 6ad43b3cf68cbbb7eafadd4342f5191617501aa5 Mon Sep 17 00:00:00 2001
From: Manon MALIQUE <manon.malique@irit.fr>
Date: Wed, 3 Apr 2024 11:58:14 +0200
Subject: [PATCH] Adding comments and updating

---
 .../libraries/neocampus/advertisedDeviceCallbacks.cpp  |  8 +++-----
 neosensor/libraries/neocampus/neocampus_utils.cpp      |  2 +-
 neosensor/libraries/neocampus/neocampus_utils.h        |  2 +-
 neosensor/libraries/neocampus_drivers/SHT3x.cpp        | 10 ++++------
 neosensor/libraries/neocampus_drivers/SHT3x.h          |  2 +-
 .../libraries/neocampus_drivers/generic_driver.cpp     |  4 ++--
 neosensor/neosensor.ino                                |  2 +-
 7 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/neosensor/libraries/neocampus/advertisedDeviceCallbacks.cpp b/neosensor/libraries/neocampus/advertisedDeviceCallbacks.cpp
index d7cf1e66..c35cdd78 100644
--- a/neosensor/libraries/neocampus/advertisedDeviceCallbacks.cpp
+++ b/neosensor/libraries/neocampus/advertisedDeviceCallbacks.cpp
@@ -7,11 +7,8 @@
 // ***** getTemperature *****
 float advertisedDeviceCallbacks::getTemperature(BLEAdvertisedDevice device) {
   uint8_t temp_lb = (uint8_t) device.getManufacturerData().c_str()[1]; // temperature lower byte 
-  log_debug(F("temp_lb :")); log_debug(temp_lb);
   uint8_t temp_hb = (uint8_t)(device.getManufacturerData().c_str()[2]); // temperature higher byte 
-  log_debug(F("\ntemp_hb :")); log_debug(temp_hb);
   int16_t temperature = (int16_t)((uint16_t)(temp_hb)<<8) + (uint16_t)temp_lb;
-  log_debug(F("\ntemperature :")); log_debug(temperature);log_flush();
   return ((float)(temperature)/10);
 }
 
@@ -20,13 +17,14 @@ float advertisedDeviceCallbacks::getTemperature(BLEAdvertisedDevice device) {
 //Display the BLE Device data
 void advertisedDeviceCallbacks::onResult(BLEAdvertisedDevice device) {
     if (device.getName() == "TP358 (5551)") {
-        log_debug(F("\nReference temperature : "));
+        log_debug(F("\n[CALIBRATION][advertisedDeviceCallbacks] Reference temperature : "));
         valBLE=getTemperature(device);
         log_debug(valBLE);
         log_flush();
         _gotcalibrationvalue = true;
     }else{
-        log_debug(device.getName());
+        log_debug(F("\n[CALIBRATION][advertisedDeviceCallbacks] This device is not a ThermoPro TP358 (5551) : "));
+        log_debug(device.getName());log_flush();
     }
     
 }
diff --git a/neosensor/libraries/neocampus/neocampus_utils.cpp b/neosensor/libraries/neocampus/neocampus_utils.cpp
index 900ee54e..d3135a2d 100644
--- a/neosensor/libraries/neocampus/neocampus_utils.cpp
+++ b/neosensor/libraries/neocampus/neocampus_utils.cpp
@@ -116,7 +116,7 @@ bool checkCLEARswitch( uint8_t sw_pin ) {
 // --- CALIBRATION switch management ------------------------------------------------
 
  /* check incr switch and decr switch for CALIBRATION procedure
- * if decr_sw_pin == -1 OR incr_sw_pin-->== -1 check disabled
+ * if decr_sw_pin == -1 OR incr_sw_pin == -1 --> check disabled
  */
 bool checkCALIBRATIONswitch(uint8_t decr_sw_pin, uint8_t incr_sw_pin) {
 
diff --git a/neosensor/libraries/neocampus/neocampus_utils.h b/neosensor/libraries/neocampus/neocampus_utils.h
index 264418a1..1e887b52 100644
--- a/neosensor/libraries/neocampus/neocampus_utils.h
+++ b/neosensor/libraries/neocampus/neocampus_utils.h
@@ -40,7 +40,7 @@ extern bool _need2reboot;
 extern bool _need2calibrate; 
 // value of the BLE device
 extern float valBLE;
-
+// got calibration flag
 extern bool _gotcalibrationvalue;
 
 
diff --git a/neosensor/libraries/neocampus_drivers/SHT3x.cpp b/neosensor/libraries/neocampus_drivers/SHT3x.cpp
index 49874e8a..56fbd05d 100644
--- a/neosensor/libraries/neocampus_drivers/SHT3x.cpp
+++ b/neosensor/libraries/neocampus_drivers/SHT3x.cpp
@@ -285,17 +285,15 @@ boolean SHT3x::getTemp( float *pval )
   // 100.0 x _tmp = (17500 x _tmp) / (16384 x 4) - 4500
   _tmp = ((4375 * _tmp) >> 14) - 4500;
   *pval = ((float)_tmp / 100.0f);
-  log_debug(F("[SHT3x] Need to calibrate ?\n"));log_debug(_need2calibrate);log_flush();
   if ((not _need2reboot) && _need2calibrate && _gotcalibrationvalue){
-    log_debug(_gotcalibrationvalue);
-    log_debug(F("[SHT3x] Let's calibrate !\n"));log_debug(_need2calibrate);log_flush();
     auto result = calibrate(pval, _a, _b); // updating of (a,b)
     _a = std::get<0>(result);
     _b = std::get<1>(result);
-  }else{
-    log_debug(F("[SHT3x] No need to calibrate :'(\n"));log_debug(_need2calibrate);log_flush();
   }
-  // calibration
+  if((not _need2reboot) && _need2calibrate && (not _gotcalibrationvalue)){
+    log_debug(F("\n[CALIBRATION][SHT3x] No reference value detected. Calibration canceled !"));log_flush();
+  }
+  // correction of the value
   *pval = *pval * _a;
   *pval = *pval + _b;
   return true;
diff --git a/neosensor/libraries/neocampus_drivers/SHT3x.h b/neosensor/libraries/neocampus_drivers/SHT3x.h
index 53110f75..ccb81443 100644
--- a/neosensor/libraries/neocampus_drivers/SHT3x.h
+++ b/neosensor/libraries/neocampus_drivers/SHT3x.h
@@ -155,7 +155,7 @@ class SHT3x : public generic_driver {
 #endif /* SHT3X_CRC_LOOKUP_TABLE */
 
     float _a = 1.0;       //coefficient for calibration
-    float _b = (-2.0);    //coefficient for calibration
+    float _b = 0;    //coefficient for calibration
 };
 
 #endif /* _SHT3X_H_ */
diff --git a/neosensor/libraries/neocampus_drivers/generic_driver.cpp b/neosensor/libraries/neocampus_drivers/generic_driver.cpp
index 08291832..e1eaa88e 100644
--- a/neosensor/libraries/neocampus_drivers/generic_driver.cpp
+++ b/neosensor/libraries/neocampus_drivers/generic_driver.cpp
@@ -172,9 +172,9 @@ void generic_driver::setDataSent( void ) {
  */
 std::tuple<float, float> generic_driver::calibrate(float* pval, float a, float b){
   //TO-DO : Add an extern global variable -> ThermoPro sensor value : valBLE to replace the one below
-  log_debug(F("[generic_drivers] BLE Value :"));log_debug(valBLE);log_debug(F("/n"));log_flush();
+  log_debug(F("\n[CALIBRATION][generic_drivers] BLE Value :"));log_debug(valBLE);log_flush();
   b= valBLE-*pval;
-  log_debug(F("[generic_drivers] b :"));log_debug(b);log_debug(F("/n"));log_flush();
+  log_debug(F("\n[CALIBRATION][generic_drivers] b :"));log_debug(b);log_debug(F("\n"));log_flush();
   // calibration is done so no need to do it again
   _need2calibrate=false;
   return std::make_tuple(a, b);
diff --git a/neosensor/neosensor.ino b/neosensor/neosensor.ino
index 0f37b800..88ff188c 100644
--- a/neosensor/neosensor.ino
+++ b/neosensor/neosensor.ino
@@ -795,7 +795,7 @@ void startScanBLE() {
 }
 // ***** scan Complete Call Back  *****
 static void scanCompleteCB(BLEScanResults scanResults) { // Callback invoked when scanning has completed
-  log_debug(F("scan completed"));log_flush();
+  log_debug(F("\nScan completed"));log_flush();
 }
 
 // --- SETUP -------------------------------------------------------------------
-- 
GitLab