Mise à jour de la bibliothèque MeasureUnit
This commit is contained in:
parent
31005dad7f
commit
af0a92f4b6
@ -56,6 +56,100 @@ MeasureUnit::~MeasureUnit()
|
|||||||
|
|
||||||
void MeasureUnit::run()
|
void MeasureUnit::run()
|
||||||
{
|
{
|
||||||
|
switch(_state)
|
||||||
|
{
|
||||||
|
case MEASURING:
|
||||||
|
_adc.startSample(_channel);
|
||||||
|
|
||||||
|
if(_channel == 0) //Calcule du courant
|
||||||
|
{
|
||||||
|
if(_adc.isSampleReady())
|
||||||
|
{
|
||||||
|
_tension = _adc.getSampleVoltage();
|
||||||
|
_courant = _tension / (double) _precResistor;
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print("Tension prec : ");Serial.println(_tension);
|
||||||
|
#endif
|
||||||
|
_channel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //Calcule des niveaux de tensions
|
||||||
|
{
|
||||||
|
if(_adc.isSampleReady())
|
||||||
|
{
|
||||||
|
_resistanceMap[_channel-1] = _adc.getSampleVoltage();
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print("Tension thermistances : ");Serial.println(_resistanceMap[_channel-1]);
|
||||||
|
#endif
|
||||||
|
_channel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fin de la partie d'acquisition
|
||||||
|
if(_channel == _thermistorCount)
|
||||||
|
{
|
||||||
|
_state = COMPUTING;
|
||||||
|
_resistanceMap[_channel-1] = _adc.getAdcSetting().getVref();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case COMPUTING :
|
||||||
|
//Ici nous calculons les temperatures
|
||||||
|
for(int i(_thermistorCount-1); i > 0; i--)
|
||||||
|
{
|
||||||
|
//Calcule de delta :
|
||||||
|
_resistanceMap[i] -= _resistanceMap[i-1];
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.printf("Debug voltage delta : %u -> ",i);Serial.println(_resistanceMap[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ne pas oublier de déduire la chute de tension de la resistance de precision pour la première thermistance
|
||||||
|
_resistanceMap[0] -= _tension;
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.printf("Debug voltage delta : 0 -> ");Serial.println(_resistanceMap[0]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
//3) Nous en déduisons la résistance
|
||||||
|
//Serial.print("Resistance ");Serial.print(i);Serial.print(" ");Serial.println(_resistanceMap[i]);
|
||||||
|
_resistanceMap[i] /= _courant;
|
||||||
|
//4) Nous en déduisons la temperature
|
||||||
|
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
||||||
|
|
||||||
|
//On effectue un étalonnage
|
||||||
|
if(_triggerLevelOff)
|
||||||
|
{
|
||||||
|
double averageTemp(0);
|
||||||
|
//We reset the offset
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetMap[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
averageTemp += _temperatures[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
averageTemp /= (double)_thermistorCount;
|
||||||
|
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetMap[i] = averageTemp - _temperatures[i];
|
||||||
|
}
|
||||||
|
_triggerLevelOff = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_temperatures[i] += _rOffsetMap[i] + _globalOffset;
|
||||||
|
#ifdef DEBUG_TEMP
|
||||||
|
Serial.print("Temperature ");Serial.print(i);Serial.print(" : ");Serial.println(_temperatures[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
_state = MEASUREMENT_READY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(_offsetCounter < _offsetComputeIte && isMeasurementReady())
|
if(_offsetCounter < _offsetComputeIte && isMeasurementReady())
|
||||||
{
|
{
|
||||||
//We reset the offset array
|
//We reset the offset array
|
||||||
@ -238,105 +332,17 @@ double *MeasureUnit::getROffsetMap()
|
|||||||
return _rOffsetMap;
|
return _rOffsetMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureUnit::startTemperatureMeasurement()
|
boolean MeasureUnit::startTemperatureMeasurement()
|
||||||
{
|
{
|
||||||
switch(_state)
|
|
||||||
|
if(_state == IDLING)
|
||||||
{
|
{
|
||||||
case IDLING:
|
_state = MEASURING;
|
||||||
_state = MEASURING;
|
_channel = 0;
|
||||||
_channel = 0;
|
return true;
|
||||||
break;
|
|
||||||
case MEASURING:
|
|
||||||
_adc.startSample(_channel);
|
|
||||||
|
|
||||||
if(_channel == 0) //Calcule du courant
|
|
||||||
{
|
|
||||||
if(_adc.isSampleReady())
|
|
||||||
{
|
|
||||||
_tension = _adc.getSampleVoltage();
|
|
||||||
_courant = _tension / (double) _precResistor;
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.print("Tension prec : ");Serial.println(_tension);
|
|
||||||
#endif
|
|
||||||
_channel++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //Calcule des niveaux de tensions
|
|
||||||
{
|
|
||||||
if(_adc.isSampleReady())
|
|
||||||
{
|
|
||||||
_resistanceMap[_channel-1] = _adc.getSampleVoltage();
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.print("Tension thermistances : ");Serial.println(_resistanceMap[_channel-1]);
|
|
||||||
#endif
|
|
||||||
_channel++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Fin de la partie d'acquisition
|
|
||||||
if(_channel == _thermistorCount)
|
|
||||||
{
|
|
||||||
_state = COMPUTING;
|
|
||||||
_resistanceMap[_channel-1] = _adc.getAdcSetting().getVref();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case COMPUTING :
|
|
||||||
//Ici nous calculons les temperatures
|
|
||||||
for(int i(_thermistorCount-1); i > 0; i--)
|
|
||||||
{
|
|
||||||
//Calcule de delta :
|
|
||||||
_resistanceMap[i] -= _resistanceMap[i-1];
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.printf("Debug voltage delta : %u -> ",i);Serial.println(_resistanceMap[i]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//Ne pas oublier de déduire la chute de tension de la resistance de precision pour la première thermistance
|
|
||||||
_resistanceMap[0] -= _tension;
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.printf("Debug voltage delta : 0 -> ");Serial.println(_resistanceMap[0]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(int i(0); i < _thermistorCount; i++)
|
|
||||||
{
|
|
||||||
//3) Nous en déduisons la résistance
|
|
||||||
//Serial.print("Resistance ");Serial.print(i);Serial.print(" ");Serial.println(_resistanceMap[i]);
|
|
||||||
_resistanceMap[i] /= _courant;
|
|
||||||
//4) Nous en déduisons la temperature
|
|
||||||
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
|
||||||
|
|
||||||
//On effectue un étalonnage
|
|
||||||
if(_triggerLevelOff)
|
|
||||||
{
|
|
||||||
double averageTemp(0);
|
|
||||||
//We reset the offset
|
|
||||||
for(int i(0); i < _thermistorCount; i++)
|
|
||||||
{
|
|
||||||
_rOffsetMap[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i(0); i < _thermistorCount; i++)
|
|
||||||
{
|
|
||||||
averageTemp += _temperatures[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
averageTemp /= (double)_thermistorCount;
|
|
||||||
|
|
||||||
for(int i(0); i < _thermistorCount; i++)
|
|
||||||
{
|
|
||||||
_rOffsetMap[i] = averageTemp - _temperatures[i];
|
|
||||||
}
|
|
||||||
_triggerLevelOff = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_temperatures[i] += _rOffsetMap[i] + _globalOffset;
|
|
||||||
#ifdef DEBUG_TEMP
|
|
||||||
Serial.print("Temperature ");Serial.print(i);Serial.print(" : ");Serial.println(_temperatures[i]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
_state = MEASUREMENT_READY;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureUnit::levelAsyncTemperaturesOff()
|
void MeasureUnit::levelAsyncTemperaturesOff()
|
||||||
|
@ -23,7 +23,7 @@ class MeasureUnit
|
|||||||
|
|
||||||
//Async methods
|
//Async methods
|
||||||
enum STATE {IDLING, MEASURING, COMPUTING, MEASUREMENT_READY};
|
enum STATE {IDLING, MEASURING, COMPUTING, MEASUREMENT_READY};
|
||||||
void startTemperatureMeasurement();
|
boolean startTemperatureMeasurement();
|
||||||
boolean isMeasurementReady();
|
boolean isMeasurementReady();
|
||||||
double *getAsyncTemperatures();
|
double *getAsyncTemperatures();
|
||||||
void levelAsyncTemperaturesOff();
|
void levelAsyncTemperaturesOff();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* 17/12/2019
|
* 17/12/2019
|
||||||
*/
|
*/
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
#include <WiFi.h>
|
||||||
#include <RTClib.h>
|
#include <RTClib.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
@ -20,11 +21,46 @@
|
|||||||
uint8_t analogInput[] = {0,1,2,3,4,5,6,7};
|
uint8_t analogInput[] = {0,1,2,3,4,5,6,7};
|
||||||
double *tempArray = NULL;
|
double *tempArray = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Liste des offsets trouvés
|
||||||
|
* | -0.49 | 0.36 | -0.29 | 0.38 | 0.44 | -0.35 | -0.21 | 0.14 |
|
||||||
|
* | -0.72 | 0.07 | -0.52 | -0.01 | 2.38 | -0.65 | -0.44 | -0.11 |
|
||||||
|
* | -0.99 | -0.06 | -0.74 | 2.24 | 0.73 | -0.86 | -0.68 | 0.35 |
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void downlinkHandler(u1_t length, u1_t dataBeg, u1_t *data)
|
||||||
|
{
|
||||||
|
Serial.println("Downlink received : ");
|
||||||
|
for(uint8_t i(0); i < length; i++)
|
||||||
|
{
|
||||||
|
Serial.print(data[dataBeg + i],HEX);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
//Action en fonction de l'octet de commande
|
||||||
|
switch(data[0])
|
||||||
|
{
|
||||||
|
case 0x01://Mise à jour de l'heure
|
||||||
|
//Octets suivants:
|
||||||
|
//2 jour 3 mois 4 année 5 heures 6 minutes
|
||||||
|
if(length == 6)
|
||||||
|
{
|
||||||
|
Serial.printf("dd: %u, m: %u, yyyy: %d, hh: %u, mm: %u\n", data[2], data[3], data[4]+2000, data[5], data[6]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Serial.println("Action réglage RTC : paramètres insuffisants");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.println("Action inconnnue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Objet de calcule de la temperature
|
//Objet de calcule de la temperature
|
||||||
//ThermistorSetting thermistorSetting(3380, 10000);
|
//ThermistorSetting thermistorSetting(3380, 10000);
|
||||||
ThermistorSetting thermistorSetting(3650, 470);
|
ThermistorSetting thermistorSetting(3650, 470);
|
||||||
//AdcSetting adcSetting(3300.0, 12, 310, 3);
|
//AdcSetting adcSetting(3300.0, 12, 310, 3);
|
||||||
AdcSetting adcSetting(3285, 15, 6, 10);
|
AdcSetting adcSetting(3320, 15, 6, 10);
|
||||||
Ads1115 adc;
|
Ads1115 adc;
|
||||||
MeasureUnit measureUnit(analogInput, 8, 990, thermistorSetting, adc);
|
MeasureUnit measureUnit(analogInput, 8, 990, thermistorSetting, adc);
|
||||||
//MeasureUnit measureUnit(analogInput, 8, 99, thermistorSetting, adc);
|
//MeasureUnit measureUnit(analogInput, 8, 99, thermistorSetting, adc);
|
||||||
@ -46,10 +82,6 @@ unsigned long _time(0);
|
|||||||
void os_getArtEui (u1_t* buf) { }
|
void os_getArtEui (u1_t* buf) { }
|
||||||
void os_getDevEui (u1_t* buf) { }
|
void os_getDevEui (u1_t* buf) { }
|
||||||
void os_getDevKey (u1_t* buf) { }
|
void os_getDevKey (u1_t* buf) { }
|
||||||
void onEvent(ev_t ev)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static u1_t NWKSKEY[16] = { 0x1F, 0x9E, 0xE2, 0x7A, 0xC8, 0xBA, 0xE8, 0xEA, 0xF5, 0xC2, 0x5E, 0x47, 0x5D, 0xE0, 0x77, 0x55 };
|
static u1_t NWKSKEY[16] = { 0x1F, 0x9E, 0xE2, 0x7A, 0xC8, 0xBA, 0xE8, 0xEA, 0xF5, 0xC2, 0x5E, 0x47, 0x5D, 0xE0, 0x77, 0x55 };
|
||||||
static u1_t APPSKEY[16] = { 0x3B, 0x89, 0x86, 0x96, 0xBB, 0xAA, 0x38, 0x1E, 0x1F, 0xC4, 0xAD, 0x03, 0xEF, 0x3F, 0x56, 0x12 };
|
static u1_t APPSKEY[16] = { 0x3B, 0x89, 0x86, 0x96, 0xBB, 0xAA, 0x38, 0x1E, 0x1F, 0xC4, 0xAD, 0x03, 0xEF, 0x3F, 0x56, 0x12 };
|
||||||
@ -63,12 +95,20 @@ void setup() {
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("Start setup");
|
Serial.println("Start setup");
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
pinMode(PUSH_BUTTON, INPUT);
|
pinMode(PUSH_BUTTON, INPUT);
|
||||||
//Radio init
|
//Partie concernant l'initialisation de la radio
|
||||||
#ifdef RADIO_ENABLED
|
#ifdef RADIO_ENABLED
|
||||||
radio.init();
|
radio.init();
|
||||||
radio.setTTNSession(0x1, DEVADDR, NWKSKEY, APPSKEY);
|
radio.setTTNSession(0x1, DEVADDR, NWKSKEY, APPSKEY);
|
||||||
radio.setRadioEUChannels();
|
radio.setRadioEUChannels();
|
||||||
|
/*
|
||||||
|
* La directive setMCUClockError() permet de laisser une fenêtre plus grande pour le slot de
|
||||||
|
* réception (Downlink). En effet ce slot doit durer 2 secondes et il peut durer moins en raison
|
||||||
|
* d'imprécisions d'horloge.
|
||||||
|
*/
|
||||||
|
radio.setMCUClockError();
|
||||||
|
radio.setDownlinkHandler(&(downlinkHandler));
|
||||||
#endif
|
#endif
|
||||||
//Adc init
|
//Adc init
|
||||||
adc.setAdcSetting(adcSetting);
|
adc.setAdcSetting(adcSetting);
|
||||||
@ -103,8 +143,7 @@ void loop() {
|
|||||||
|
|
||||||
//On peut tester si la conversion est terminée avec :
|
//On peut tester si la conversion est terminée avec :
|
||||||
//if(measureUnit.isMeasurementReady())
|
//if(measureUnit.isMeasurementReady())
|
||||||
|
|
||||||
measureUnit.run();
|
|
||||||
//measureUnit.getAsyncTemperatures() renvoie NULL si la recupération de la température n'est pas terminée
|
//measureUnit.getAsyncTemperatures() renvoie NULL si la recupération de la température n'est pas terminée
|
||||||
tempArray = measureUnit.getAsyncTemperatures();
|
tempArray = measureUnit.getAsyncTemperatures();
|
||||||
|
|
||||||
@ -162,4 +201,5 @@ void loop() {
|
|||||||
#ifdef RADIO_ENABLED
|
#ifdef RADIO_ENABLED
|
||||||
radio.run();
|
radio.run();
|
||||||
#endif
|
#endif
|
||||||
|
measureUnit.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user