From c5bad1cc44692a3faf587533f5d09d40dc731b81 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 7 Nov 2021 22:05:57 +0100 Subject: [PATCH] initialize sensor objects in constructor --- include/sensor_bh1750.cpp | 2 +- include/sensor_bmp180.cpp | 2 +- include/sensor_htu21d.cpp | 2 +- include/sensor_mhz19b.cpp | 3 +++ include/sensor_mhz19b.h | 1 - include/sensor_sds018.cpp | 2 ++ 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/sensor_bh1750.cpp b/include/sensor_bh1750.cpp index 0dcf04b..372d5d7 100644 --- a/include/sensor_bh1750.cpp +++ b/include/sensor_bh1750.cpp @@ -5,7 +5,7 @@ Sensor_BH1750::Sensor_BH1750() { - BH1750 bh1750(0x23); //0x23 if addr connected to ground (=pin open), 0x5c if addr pulled high + bh1750 = new BH1750(0x23); //0x23 if addr connected to ground (=pin open), 0x5c if addr pulled high } void Sensor_BH1750::init() //Things to be done during setup() diff --git a/include/sensor_bmp180.cpp b/include/sensor_bmp180.cpp index 678362e..7633cef 100644 --- a/include/sensor_bmp180.cpp +++ b/include/sensor_bmp180.cpp @@ -5,7 +5,7 @@ Sensor_BMP180::Sensor_BMP180() { - Adafruit_BMP085 bmp180; + bmp180 = new Adafruit_BMP085(); } void Sensor_BMP180::init() //Things to be done during setup() diff --git a/include/sensor_htu21d.cpp b/include/sensor_htu21d.cpp index 8d03d73..253a5f8 100644 --- a/include/sensor_htu21d.cpp +++ b/include/sensor_htu21d.cpp @@ -6,7 +6,7 @@ Sensor_HTU21D::Sensor_HTU21D() { - Adafruit_HTU21DF htu; + htu = new Adafruit_HTU21DF(); } void Sensor_HTU21D::init() //Things to be done during setup() diff --git a/include/sensor_mhz19b.cpp b/include/sensor_mhz19b.cpp index 73abccc..ecc3812 100644 --- a/include/sensor_mhz19b.cpp +++ b/include/sensor_mhz19b.cpp @@ -7,6 +7,9 @@ Sensor_MHZ19B::Sensor_MHZ19B(int prx,int ptx) pin_rx=prx; pin_tx=ptx; + mhz19 = new MHZ19(); + mhz19_swSerial = new SoftwareSerial(); + /* * MHZ19 Library: https://platformio.org/lib/show/1620/SevSegSPI * Software Serial Library: https://platformio.org/lib/show/168/EspSoftwareSerial diff --git a/include/sensor_mhz19b.h b/include/sensor_mhz19b.h index ea89a2a..cd40fff 100644 --- a/include/sensor_mhz19b.h +++ b/include/sensor_mhz19b.h @@ -25,7 +25,6 @@ private: int mhz19_readValue_reimplemented(Stream *_streamRef, MHZ19 *_mhz19Ref); byte mhz19_getCheckSum(byte* packet); - bool mhz19_ready; MHZ19 *mhz19; diff --git a/include/sensor_sds018.cpp b/include/sensor_sds018.cpp index a21fe60..740e390 100644 --- a/include/sensor_sds018.cpp +++ b/include/sensor_sds018.cpp @@ -10,6 +10,8 @@ Sensor_SDS018::Sensor_SDS018(int prx,int ptx) { pin_rx=prx; pin_tx=ptx; + + sds018_swSerial = new SoftwareSerial(); } void Sensor_SDS018::init() //Things to be done during setup()