mirror of https://github.com/arendst/Tasmota.git
Refactor ADC MQ_SAMPLES saving code and RAM
This commit is contained in:
parent
55cb473e13
commit
9af25c73d6
|
@ -163,6 +163,8 @@ struct {
|
||||||
} Adcs;
|
} Adcs;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
// float mq_samples[ANALOG_MQ_SAMPLES];
|
||||||
|
float *mq_samples;
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
float current = 0;
|
float current = 0;
|
||||||
float energy = 0;
|
float energy = 0;
|
||||||
|
@ -170,12 +172,11 @@ struct {
|
||||||
uint32_t param2 = 0;
|
uint32_t param2 = 0;
|
||||||
int param3 = 0;
|
int param3 = 0;
|
||||||
int param4 = 0;
|
int param4 = 0;
|
||||||
|
int indexOfPointer = -1;
|
||||||
uint32_t previous_millis = 0;
|
uint32_t previous_millis = 0;
|
||||||
uint16_t last_value = 0;
|
uint16_t last_value = 0;
|
||||||
uint8_t type = 0;
|
uint8_t type = 0;
|
||||||
uint8_t pin = 0;
|
uint8_t pin = 0;
|
||||||
float mq_samples[ANALOG_MQ_SAMPLES];
|
|
||||||
int indexOfPointer = -1;
|
|
||||||
} Adc[MAX_ADCS];
|
} Adc[MAX_ADCS];
|
||||||
|
|
||||||
bool adcAttachPin(uint8_t pin) {
|
bool adcAttachPin(uint8_t pin) {
|
||||||
|
@ -261,6 +262,10 @@ void AdcAttach(uint32_t pin, uint8_t type) {
|
||||||
if (Adcs.present == MAX_ADCS) { return; }
|
if (Adcs.present == MAX_ADCS) { return; }
|
||||||
Adc[Adcs.present].pin = pin;
|
Adc[Adcs.present].pin = pin;
|
||||||
if (adcAttachPin(Adc[Adcs.present].pin)) {
|
if (adcAttachPin(Adc[Adcs.present].pin)) {
|
||||||
|
if (ADC_MQ == type) {
|
||||||
|
Adc[Adcs.present].mq_samples = (float*)calloc(sizeof(float), ANALOG_MQ_SAMPLES); // Need calloc to reset registers to 0/false
|
||||||
|
if (nullptr == Adc[Adcs.present].mq_samples) { return; }
|
||||||
|
}
|
||||||
Adc[Adcs.present].type = type;
|
Adc[Adcs.present].type = type;
|
||||||
// analogSetPinAttenuation(Adc[Adcs.present].pin, ADC_11db); // Default
|
// analogSetPinAttenuation(Adc[Adcs.present].pin, ADC_11db); // Default
|
||||||
Adcs.present++;
|
Adcs.present++;
|
||||||
|
|
Loading…
Reference in New Issue