Changement apportés à l'objet measure unit
This commit is contained in:
parent
6f1e8734c4
commit
62019634c6
@ -14,6 +14,8 @@ _globalOffset(0),
|
|||||||
_error(OK),
|
_error(OK),
|
||||||
_state(IDLING),
|
_state(IDLING),
|
||||||
_channel(0),
|
_channel(0),
|
||||||
|
_offsetComputeIte(7),
|
||||||
|
_offsetCounter(7),
|
||||||
_courant(0.0),
|
_courant(0.0),
|
||||||
_tension(0.0),
|
_tension(0.0),
|
||||||
_triggerLevelOff(false)
|
_triggerLevelOff(false)
|
||||||
@ -22,17 +24,20 @@ _triggerLevelOff(false)
|
|||||||
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
_rOffsetMap = (double*) calloc(_thermistorCount, sizeof(double));
|
_rOffsetMap = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
_resistanceMap = (double*) malloc(_thermistorCount * sizeof(double));
|
_resistanceMap = (double*) malloc(_thermistorCount * sizeof(double));
|
||||||
|
_rOffsetBuffer = (double*) malloc(_thermistorCount * sizeof(double));
|
||||||
|
|
||||||
if(_temperatures == NULL || _rOffsetMap == NULL || _resistanceMap == NULL)
|
if(_temperatures == NULL || _rOffsetMap == NULL || _resistanceMap == NULL || _rOffsetBuffer == NULL)
|
||||||
{
|
{
|
||||||
_error = MALLOC_ERR;
|
_error = MALLOC_ERR;
|
||||||
_temperatures != NULL ? free(_temperatures):(void)_temperatures;
|
_temperatures != NULL ? free(_temperatures):(void)_temperatures;
|
||||||
_rOffsetMap != NULL ? free(_rOffsetMap):(void)_rOffsetMap;
|
_rOffsetMap != NULL ? free(_rOffsetMap):(void)_rOffsetMap;
|
||||||
_resistanceMap != NULL ? free(_resistanceMap):(void)_resistanceMap;
|
_resistanceMap != NULL ? free(_resistanceMap):(void)_resistanceMap;
|
||||||
|
_rOffsetBuffer != NULL ? free(_rOffsetBuffer):(void)_rOffsetBuffer;
|
||||||
|
|
||||||
_temperatures = NULL;
|
_temperatures = NULL;
|
||||||
_rOffsetMap = NULL;
|
_rOffsetMap = NULL;
|
||||||
_resistanceMap = NULL;
|
_resistanceMap = NULL;
|
||||||
|
_rOffsetBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_adc.begin();
|
_adc.begin();
|
||||||
@ -45,9 +50,83 @@ MeasureUnit::~MeasureUnit()
|
|||||||
free(_temperatures);
|
free(_temperatures);
|
||||||
free(_rOffsetMap);
|
free(_rOffsetMap);
|
||||||
free(_resistanceMap);
|
free(_resistanceMap);
|
||||||
|
free(_rOffsetBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeasureUnit::run()
|
||||||
|
{
|
||||||
|
if(_offsetCounter < _offsetComputeIte && isMeasurementReady())
|
||||||
|
{
|
||||||
|
//We reset the offset array
|
||||||
|
if(_offsetCounter == 0)
|
||||||
|
{
|
||||||
|
Serial.printf("Initiating average \n");
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetBuffer[i] = 0;
|
||||||
|
_rOffsetMap[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(_offsetCounter == _offsetComputeIte-1)
|
||||||
|
{
|
||||||
|
double averageTemp(0);
|
||||||
|
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetBuffer[i] += _temperatures[i];
|
||||||
|
}
|
||||||
|
//We compute the average for each thermistor:
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetBuffer[i] /= _offsetCounter;
|
||||||
|
averageTemp += _rOffsetBuffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
averageTemp /= _thermistorCount;
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetMap[i] = averageTemp - _rOffsetBuffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Offset done");
|
||||||
|
Serial.print("|");
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
if(i != 7)
|
||||||
|
{
|
||||||
|
Serial.print(" ");Serial.print(_rOffsetMap[i],2);Serial.print(" |");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.print(" ");Serial.print(_rOffsetMap[i],2);Serial.print(" |");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetBuffer[i] += _temperatures[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_offsetCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureUnit::setOffsetIteration(uint8_t iteration)
|
||||||
|
{
|
||||||
|
_offsetComputeIte = iteration;
|
||||||
|
_offsetCounter = iteration;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureUnit::startOffsetComputing()
|
||||||
|
{
|
||||||
|
_offsetCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode permettant d'effectuer les mesures de température et de les récupérer
|
* Methode permettant d'effectuer les mesures de température et de les récupérer
|
||||||
*/
|
*/
|
||||||
@ -282,3 +361,9 @@ double *MeasureUnit::getAsyncTemperatures()
|
|||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeasureUnit::init()
|
||||||
|
{
|
||||||
|
Serial.println(computeTemperature(3380, 18000, 10000));
|
||||||
|
Serial.println(computeTemperature(3380, 11700, 10000));
|
||||||
|
}
|
||||||
|
@ -12,6 +12,9 @@ class MeasureUnit
|
|||||||
MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, Adc &adc);
|
MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, Adc &adc);
|
||||||
~MeasureUnit();
|
~MeasureUnit();
|
||||||
void init();
|
void init();
|
||||||
|
void run();
|
||||||
|
void startOffsetComputing();
|
||||||
|
void setOffsetIteration(uint8_t iteration);
|
||||||
void setGlobalTempOffset(double offset);
|
void setGlobalTempOffset(double offset);
|
||||||
void levelTemperaturesOff();
|
void levelTemperaturesOff();
|
||||||
double getGlobalTempOffset();
|
double getGlobalTempOffset();
|
||||||
@ -34,7 +37,7 @@ class MeasureUnit
|
|||||||
|
|
||||||
double _globalOffset; //Correspond à l'offset global nécessaire afin d'avoir une température qui corresponde à la réalité
|
double _globalOffset; //Correspond à l'offset global nécessaire afin d'avoir une température qui corresponde à la réalité
|
||||||
double *_temperatures; //Tableau contenant toutes les températures
|
double *_temperatures; //Tableau contenant toutes les températures
|
||||||
double *_rOffsetMap; //Tableau qui contient les offsets individuels pour chaque thermistance
|
double *_rOffsetMap,*_rOffsetBuffer; //Tableau qui contient les offsets individuels pour chaque thermistance
|
||||||
double *_resistanceMap; //Tableau qui contient les resistances associées aux thermistances (pour debug seulement)
|
double *_resistanceMap; //Tableau qui contient les resistances associées aux thermistances (pour debug seulement)
|
||||||
uint8_t *_analogInput; //Pointeur qui garde l'adresse du tableau contenant le nom des entrées analogiques
|
uint8_t *_analogInput; //Pointeur qui garde l'adresse du tableau contenant le nom des entrées analogiques
|
||||||
uint16_t _thermistorCount;
|
uint16_t _thermistorCount;
|
||||||
@ -46,7 +49,7 @@ class MeasureUnit
|
|||||||
|
|
||||||
//Async part
|
//Async part
|
||||||
STATE _state;
|
STATE _state;
|
||||||
uint8_t _channel;
|
uint8_t _channel, _offsetComputeIte,_offsetCounter;
|
||||||
double _courant, _tension;
|
double _courant, _tension;
|
||||||
boolean _triggerLevelOff; //Attribut permettant de savoir si un étalonnage a été demandé
|
boolean _triggerLevelOff; //Attribut permettant de savoir si un étalonnage a été demandé
|
||||||
};
|
};
|
||||||
|
@ -5,13 +5,17 @@
|
|||||||
* Anatole SCHRAMM-HENRY
|
* Anatole SCHRAMM-HENRY
|
||||||
* 17/12/2019
|
* 17/12/2019
|
||||||
*/
|
*/
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <RTClib.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
#include "MeasureUnit.h"
|
#include "MeasureUnit.h"
|
||||||
#include "PayloadFormatter.h"
|
#include "PayloadFormatter.h"
|
||||||
#include "Ads1115.h"
|
#include "Ads1115.h"
|
||||||
#include "LoRaRadio.h"
|
#include "LoRaRadio.h"
|
||||||
|
|
||||||
//#define RADIO_ENABLED
|
#define RADIO_ENABLED
|
||||||
|
#define PUSH_BUTTON 0
|
||||||
|
|
||||||
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;
|
||||||
@ -20,13 +24,17 @@ double *tempArray = NULL;
|
|||||||
//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(3298.13, 15, 6, 10);//6, 10);
|
AdcSetting adcSetting(3285, 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);
|
||||||
//Objet de création des trames LoRa
|
//Objet de création des trames LoRa
|
||||||
PayloadFormatter payloadFormatter(2,4);
|
PayloadFormatter payloadFormatter(2,4);
|
||||||
DateTime payloadDate(2020,12,26,8,42);
|
|
||||||
|
RTC_DS3231 rtc;
|
||||||
|
DateTime payloadDate;
|
||||||
|
TwoWire sc(1);
|
||||||
|
Adafruit_SSD1306 display(128,64,&sc, 16);
|
||||||
|
|
||||||
boolean data(false);
|
boolean data(false);
|
||||||
uint8_t *payload(NULL), _timeCounter(0), size(0), _channel(0);
|
uint8_t *payload(NULL), _timeCounter(0), size(0), _channel(0);
|
||||||
@ -55,6 +63,7 @@ void setup() {
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("Start setup");
|
Serial.println("Start setup");
|
||||||
|
pinMode(PUSH_BUTTON, INPUT);
|
||||||
//Radio init
|
//Radio init
|
||||||
#ifdef RADIO_ENABLED
|
#ifdef RADIO_ENABLED
|
||||||
radio.init();
|
radio.init();
|
||||||
@ -65,22 +74,37 @@ void setup() {
|
|||||||
adc.setAdcSetting(adcSetting);
|
adc.setAdcSetting(adcSetting);
|
||||||
//measureUnit.setGlobalTempOffset(-17);
|
//measureUnit.setGlobalTempOffset(-17);
|
||||||
_time = millis();
|
_time = millis();
|
||||||
Serial.println("End setup");
|
|
||||||
|
|
||||||
|
if(rtc.begin())Serial.println("RTC Ok!");
|
||||||
|
else Serial.println("RTC Fail!");
|
||||||
|
sc.begin(4, 15);
|
||||||
|
if(display.begin(SSD1306_SWITCHCAPVCC,0x3C))
|
||||||
|
{
|
||||||
|
Serial.println("SCREEN Ok!");
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setCursor(0,15);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.print("LES ALEAS DU DIRECT");
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
else Serial.println("SCREEN Fail!");
|
||||||
|
|
||||||
|
display.startscrollleft(0,16);
|
||||||
|
Serial.println("End setup");
|
||||||
|
measureUnit.init();
|
||||||
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//Version synchrone (bloquante)
|
|
||||||
//tempArray = measureUnit.getTemperatures();
|
|
||||||
|
|
||||||
//Version asynchrone :
|
//Version asynchrone :
|
||||||
measureUnit.startTemperatureMeasurement();
|
measureUnit.startTemperatureMeasurement();
|
||||||
|
|
||||||
//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();
|
||||||
|
|
||||||
@ -101,6 +125,7 @@ void loop() {
|
|||||||
|
|
||||||
//On affiche la trame associée:
|
//On affiche la trame associée:
|
||||||
payloadFormatter.startSession(1);
|
payloadFormatter.startSession(1);
|
||||||
|
payloadDate = rtc.now();
|
||||||
size = payloadFormatter.buildPayload(&payload, &payloadDate,tempArray);
|
size = payloadFormatter.buildPayload(&payload, &payloadDate,tempArray);
|
||||||
if(size != 0)
|
if(size != 0)
|
||||||
{
|
{
|
||||||
@ -109,13 +134,13 @@ void loop() {
|
|||||||
{
|
{
|
||||||
payload[i] <= 0x0F ? Serial.print("0") : Serial.print(""); Serial.print(payload[i], HEX); Serial.print(" ");
|
payload[i] <= 0x0F ? Serial.print("0") : Serial.print(""); Serial.print(payload[i], HEX); Serial.print(" ");
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.printf("|%u-%u-%u %u:%u \n", payloadDate.day(),payloadDate.month(),payloadDate.year(),payloadDate.hour(),payloadDate.minute());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Serial.print("Failed to build LoRa packet");
|
Serial.print("Failed to build LoRa packet");
|
||||||
//if(payloadFormatter.endSession())
|
|
||||||
//Serial.println("Session ended successfully");
|
payloadFormatter.endSession();
|
||||||
|
|
||||||
#ifdef RADIO_ENABLED
|
#ifdef RADIO_ENABLED
|
||||||
if(_timeCounter == 30 && size != 0)
|
if(_timeCounter == 30 && size != 0)
|
||||||
{
|
{
|
||||||
@ -129,13 +154,11 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//On effectue la calibration
|
//On effectue la calibration
|
||||||
/*if(millis() - _time > 5000 && !calibrer)
|
if(digitalRead(PUSH_BUTTON) == 0)
|
||||||
{
|
{
|
||||||
Serial.println("********************Starting calibration********************");
|
delay(500);
|
||||||
measureUnit.levelAsyncTemperaturesOff();
|
measureUnit.startOffsetComputing();
|
||||||
Serial.println("********************Ending calibration********************");
|
}
|
||||||
calibrer = true;
|
|
||||||
}*/
|
|
||||||
#ifdef RADIO_ENABLED
|
#ifdef RADIO_ENABLED
|
||||||
radio.run();
|
radio.run();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user