Skip to content
Snippets Groups Projects
Commit 3bb85ae5 authored by Manon MALIQUE's avatar Manon MALIQUE
Browse files

Adding the switch calibration feature

parent 8a5ce3f4
No related branches found
No related tags found
No related merge requests found
#include <advertisedDeviceCallbacks.h>
//Manon //Manon
/*
#include <advertisedDeviceCallbacks.h>
void advertisedDeviceCallbacks::onResult(BLEAdvertisedDevice device) { void advertisedDeviceCallbacks::onResult(BLEAdvertisedDevice device) {
if (device.getName() == "TP358 (5551)") { if (device.getName() == "TP358 (5551)") {
log_debug(F("\nReference temperature : ")); log_debug(F("\nReference temperature : "));
...@@ -8,4 +10,5 @@ void advertisedDeviceCallbacks::onResult(BLEAdvertisedDevice device) { ...@@ -8,4 +10,5 @@ void advertisedDeviceCallbacks::onResult(BLEAdvertisedDevice device) {
log_debug(getHumidity(device)); log_debug(getHumidity(device));
log_flush(); log_flush();
} }
} }
\ No newline at end of file */
\ No newline at end of file
//Manon //Manon
/*
#include <Arduino.h> #include <Arduino.h>
#include <BLEDevice.h> #include <BLEDevice.h>
#include <BLEUtils.h> #include <BLEUtils.h>
...@@ -6,10 +7,11 @@ ...@@ -6,10 +7,11 @@
#include <BLEAdvertisedDevice.h> #include <BLEAdvertisedDevice.h>
#include "neocampus_debug.h" #include "neocampus_debug.h"
/* *
* Class * Class
*/ *
class advertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks{ class advertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks{
public: public:
void onResult(BLEAdvertisedDevice device); void onResult(BLEAdvertisedDevice device);
}; };
\ No newline at end of file */
\ No newline at end of file
...@@ -112,6 +112,63 @@ bool checkCLEARswitch( uint8_t sw_pin ) { ...@@ -112,6 +112,63 @@ bool checkCLEARswitch( uint8_t sw_pin ) {
return _res; return _res;
} }
//Manon
// --- CALIBRATION switch management ------------------------------------------------
/* check incr switch and decr switch for CALIBRATION procedure
* if decr_sw_pin == -1 OR incr_sw_pin-->== -1 check disabled
*/
bool checkCALIBRATIONswitch(uint8_t decr_sw_pin, uint8_t incr_sw_pin) {
if (decr_sw_pin == INVALID_GPIO) {
log_debug(F("\n[CALIBRATION] no DECR_SW defined !")); log_flush();
return false;
}
if (incr_sw_pin == INVALID_GPIO) {
log_debug(F("\n[CALIBRATION] no INCR_SW defined !")); log_flush();
return false;
}
// set pin as input
pinMode( decr_sw_pin, INPUT );
pinMode( incr_sw_pin, INPUT );
log_debug(F("\n[CALIBRATION] Press + AND - switch for 5s to activate TEST MANON :) ...")); log_flush();
delay(1000);
log_debug(F("\n[CALIBRATION] check for incr_switch and decr_switch activation ...")); log_flush();
delay(250);
bool _res = true;
// ... then read input for a specific time
for( uint8_t cpt=10; cpt > 0; cpt-- ) {
if ( digitalRead( decr_sw_pin ) != HIGH || digitalRead( incr_sw_pin ) != HIGH ) {
// at least read 'LOW' one time --> cancel calibration operation
_res = false;
_need2calibrate=false;
break;
}
delay(500); // sleep for 500ms (allowing ESP to manage internals)
}
/* okay, delay for + and - switch acquisition is now over.
* If we need to calibrate things, we want to wait for sw_pin
* LOW (i.e user stopped to press switch)
*/
if( _res==true ) {
log_info(F("\n[CALIBRATION] activate CALIBRATION procedure ..."));
log_debug(F("\n[CALIBRATION] release SWITCH for calibration to start ..."));
log_flush();
}
int i=1;
while( digitalRead( incr_sw_pin )==HIGH && digitalRead( decr_sw_pin )==HIGH ) {
delay(250);
}
if (_res==true){
log_debug(F("\n[neocampus_utils] Need to calibrate"));log_flush();
_need2calibrate=true;
}
log_debug(F("\n test "));log_debug(_res);
return _res;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
*/ */
// reboot flag // reboot flag
extern bool _need2reboot; extern bool _need2reboot;
//Manon
extern bool _need2calibrate;
...@@ -56,6 +58,9 @@ extern bool _need2reboot; ...@@ -56,6 +58,9 @@ extern bool _need2reboot;
// check clear switch for CLEAR procedure // check clear switch for CLEAR procedure
bool checkCLEARswitch( uint8_t ); bool checkCLEARswitch( uint8_t );
// check clear switch for CALIBRATION procedure
bool checkCALIBRATIONswitch( uint8_t , uint8_t );
// whole neocampus WiFi connexion setup // whole neocampus WiFi connexion setup
bool setupWiFi( wifiParametersMgt *wp=nullptr ); bool setupWiFi( wifiParametersMgt *wp=nullptr );
......
...@@ -285,7 +285,14 @@ boolean SHT3x::getTemp( float *pval ) ...@@ -285,7 +285,14 @@ boolean SHT3x::getTemp( float *pval )
// 100.0 x _tmp = (17500 x _tmp) / (16384 x 4) - 4500 // 100.0 x _tmp = (17500 x _tmp) / (16384 x 4) - 4500
_tmp = ((4375 * _tmp) >> 14) - 4500; _tmp = ((4375 * _tmp) >> 14) - 4500;
*pval = ((float)_tmp / 100.0f); *pval = ((float)_tmp / 100.0f);
calibrate(pval, _a, _b); //Manon //Manon
if ((not _need2reboot) && _need2calibrate){
auto result = calibrate(pval, _a, _b);
_a = std::get<0>(result);
_b = std::get<1>(result);
}
*pval = *pval * _a;
*pval = *pval + _b;
return true; return true;
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "neocampus.h" // _MAX_COOLDOWN_SENSOR #include "neocampus.h" // _MAX_COOLDOWN_SENSOR
#include "generic_driver.h" #include "generic_driver.h"
#include "neocampus_debug.h" //Manon #include "neocampus_debug.h" //Manon
#include "neocampus_utils.h" //Manon
/****************************************** /******************************************
...@@ -167,12 +167,12 @@ void generic_driver::setDataSent( void ) { ...@@ -167,12 +167,12 @@ void generic_driver::setDataSent( void ) {
} }
//Manon //Manon
void generic_driver::calibrate(float* pval, float a, float b){ std::tuple<float, float> generic_driver::calibrate(float* pval, float a, float b){
*pval = *pval * a; //TO-DO : Ajouter une variable globale externe -> valeur du capteur de référence : valBLE
*pval = *pval + b; float valBLE = 22.0; //<----- à enlever
log_debug(F("\n[generic_drivers][calibration] Calibration effectuée ! a=")); b= valBLE-*pval;
log_debug(a); //TO-DO traiter le cas de non-linéarité
log_debug(F(" ; b=")); //On vient de calibrer donc plus besoin de le faire
log_debug(b);log_flush(); _need2calibrate=false;
return std::make_tuple(a, b);
} }
\ No newline at end of file
...@@ -112,7 +112,7 @@ class generic_driver { ...@@ -112,7 +112,7 @@ class generic_driver {
float valueSent; // official value that has been sent float valueSent; // official value that has been sent
unsigned long _lastMsSent; // (ms) time the official value has been sent unsigned long _lastMsSent; // (ms) time the official value has been sent
void calibrate(float*, float a, float b); // Manon std::tuple<float, float> calibrate(float*, float a, float b); // Manon
}; };
#endif /* _GENERIC_DRIVER_H_ */ #endif /* _GENERIC_DRIVER_H_ */
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
//Manon //Manon
//BLE device //BLE device
#include <advertisedDeviceCallbacks.h> //#include <advertisedDeviceCallbacks.h>
/* /*
...@@ -186,7 +186,8 @@ typedef enum { ...@@ -186,7 +186,8 @@ typedef enum {
* Global variables * Global variables
*/ */
bool _need2reboot = false; // flag to tell a reboot is requested bool _need2reboot = false; // flag to tell a reboot is requested
//Manon
bool _need2calibrate = false; // flag to tell a calibration is requested
// WiFi parameters management statically allocated instance // WiFi parameters management statically allocated instance
wifiParametersMgt wifiParameters = wifiParametersMgt(); wifiParametersMgt wifiParameters = wifiParametersMgt();
...@@ -787,6 +788,7 @@ void lateSetup( void ) { ...@@ -787,6 +788,7 @@ void lateSetup( void ) {
//Manon //Manon
// ***** start BLE scan ***** // ***** start BLE scan *****
/*
void startScanBLE() { void startScanBLE() {
BLEScan* pBLEScan = BLEDevice::getScan(); // start scanning BLEScan* pBLEScan = BLEDevice::getScan(); // start scanning
pBLEScan->setAdvertisedDeviceCallbacks(new advertisedDeviceCallbacks(), true); pBLEScan->setAdvertisedDeviceCallbacks(new advertisedDeviceCallbacks(), true);
...@@ -819,7 +821,7 @@ uint8_t getHumidity(BLEAdvertisedDevice device) { ...@@ -819,7 +821,7 @@ uint8_t getHumidity(BLEAdvertisedDevice device) {
const uint8_t *pHum = (const uint8_t *)&device.getManufacturerData().c_str()[3]; const uint8_t *pHum = (const uint8_t *)&device.getManufacturerData().c_str()[3];
return *pHum; return *pHum;
} }
*/
// --- SETUP ------------------------------------------------------------------- // --- SETUP -------------------------------------------------------------------
void setup() { void setup() {
...@@ -1230,12 +1232,22 @@ if( res!=uint8_t(0x44) ) { ...@@ -1230,12 +1232,22 @@ if( res!=uint8_t(0x44) ) {
modulesList.startAll( &sensocampus, sharedRoot ); modulesList.startAll( &sensocampus, sharedRoot );
//Manon //Manon
/*
//Init BLE //Init BLE
BLEDevice::init(""); BLEDevice::init("");
manageBLEscan(); manageBLEscan();
log_debug(F("\nSetup of BLE device ..."));log_flush(); log_debug(F("\nSetup of BLE device ..."));log_flush();
delay(1000); delay(1000);
log_debug(F(" done !"));log_flush(); log_debug(F(" done !"));log_flush();
*/
//Manon
#ifdef INCR_SW
#ifdef DECR_SW
checkCALIBRATIONswitch(DECR_SW, INCR_SW);
#endif
#endif
/* /*
* Very end of setup() :) * Very end of setup() :)
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment