From 46ab4f7dbb886c9bc3188081e6e4eb81405107e6 Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 1 Feb 2023 20:04:46 +0100 Subject: [PATCH] move most of cpp and header files --- include/sensor_anemometer.cpp | 4 +- include/sensor_ldr.h | 2 + include/sensor_mhz19b.cpp | 5 ++- include/sensor_mhz19b.h | 1 - include/sensor_raingauge.cpp | 4 +- {src => include}/tcs34725_agc.h | 3 -- platformio.ini | 10 ++++- src/main.cpp | 38 +++++++++++-------- {include => src}/sensor_bh1750.cpp | 3 ++ {include => src}/sensor_bmp180.cpp | 4 ++ {include => src}/sensor_dht22.cpp | 3 ++ {include => src}/sensor_hcsr501.cpp | 4 ++ {include => src}/sensor_hs1101.cpp | 6 ++- {include => src}/sensor_htu21d.cpp | 5 ++- {include => src}/sensor_ldr.cpp | 5 ++- {include => src}/sensor_ml8511.cpp | 4 +- .../sensor_multichannelgasgmxxx.cpp | 5 ++- {include => src}/sensor_radar.cpp | 3 ++ {include => src}/sensor_sds018.cpp | 4 +- {include => src}/sensor_sht31.cpp | 5 ++- {include => src}/sensor_tcs34725.cpp | 4 +- {include => src}/sensor_vl53l1x.cpp | 3 ++ src/tcs34725_agc.cpp | 2 +- 23 files changed, 93 insertions(+), 34 deletions(-) rename {src => include}/tcs34725_agc.h (97%) rename {include => src}/sensor_bh1750.cpp (98%) rename {include => src}/sensor_bmp180.cpp (98%) rename {include => src}/sensor_dht22.cpp (99%) rename {include => src}/sensor_hcsr501.cpp (98%) rename {include => src}/sensor_hs1101.cpp (99%) rename {include => src}/sensor_htu21d.cpp (98%) rename {include => src}/sensor_ldr.cpp (98%) rename {include => src}/sensor_ml8511.cpp (98%) rename {include => src}/sensor_multichannelgasgmxxx.cpp (99%) rename {include => src}/sensor_radar.cpp (98%) rename {include => src}/sensor_sds018.cpp (99%) rename {include => src}/sensor_sht31.cpp (99%) rename {include => src}/sensor_tcs34725.cpp (99%) rename {include => src}/sensor_vl53l1x.cpp (99%) diff --git a/include/sensor_anemometer.cpp b/include/sensor_anemometer.cpp index 3826108..917f835 100644 --- a/include/sensor_anemometer.cpp +++ b/include/sensor_anemometer.cpp @@ -1,4 +1,4 @@ - +#ifdef SENSOR_ANEMOMETER #include "sensor_anemometer.h" //uses ATS177 Latched hall sensor for rotation sensing @@ -66,3 +66,5 @@ void Sensor_Anemometer::sensorloop() } + +#endif \ No newline at end of file diff --git a/include/sensor_ldr.h b/include/sensor_ldr.h index 21149a5..3bc73f1 100644 --- a/include/sensor_ldr.h +++ b/include/sensor_ldr.h @@ -1,3 +1,4 @@ + #ifndef SENSOR_LDR_H #define SENSOR_LDR_H @@ -40,3 +41,4 @@ public: #endif + diff --git a/include/sensor_mhz19b.cpp b/include/sensor_mhz19b.cpp index a078b3c..d2ba3f6 100644 --- a/include/sensor_mhz19b.cpp +++ b/include/sensor_mhz19b.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_MHZ19B #include "sensor_mhz19b.h" @@ -153,4 +154,6 @@ int Sensor_MHZ19B::mhz19_readValue_reimplemented(Stream *_streamRef, MHZ19 *_mhz void Sensor_MHZ19B::calibrateZero() { mhz19->calibrateZero(); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/sensor_mhz19b.h b/include/sensor_mhz19b.h index fa04d17..57ca303 100644 --- a/include/sensor_mhz19b.h +++ b/include/sensor_mhz19b.h @@ -31,7 +31,6 @@ private: SoftwareSerial *mhz19_swSerial; #define BAUD_RATE_MHZ19 9600 - #define MHZ19CALIBRATIONTOPIC diff --git a/include/sensor_raingauge.cpp b/include/sensor_raingauge.cpp index 9243e36..03f2e84 100644 --- a/include/sensor_raingauge.cpp +++ b/include/sensor_raingauge.cpp @@ -1,4 +1,4 @@ - +#ifdef SENSOR_RAINGAUGE #include "sensor_raingauge.h" //uses ATS177 Latched hall sensor for rotation sensing @@ -79,3 +79,5 @@ void Sensor_Raingauge::sensorloop() } + +#endif \ No newline at end of file diff --git a/src/tcs34725_agc.h b/include/tcs34725_agc.h similarity index 97% rename from src/tcs34725_agc.h rename to include/tcs34725_agc.h index e5407fb..6812f37 100644 --- a/src/tcs34725_agc.h +++ b/include/tcs34725_agc.h @@ -1,5 +1,4 @@ //copied from example code: https://github.com/adafruit/Adafruit_TCS34725/blob/master/examples/tcs34725autorange/tcs34725autorange.ino -#ifdef SENSOR_TCS34725 #ifndef _TCS34725_AGC_H_ #define _TCS34725_AGC_H_ @@ -47,5 +46,3 @@ public: }; #endif - -#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index b09499a..cc5f933 100644 --- a/platformio.ini +++ b/platformio.ini @@ -376,7 +376,15 @@ build_flags = -D dataHTU21D_humidity_minchange=1.0 -D dataHTU21D_humidity_senddelaymax=1000*60*30 + + -D SENSOR_TCS34725 + -D SENSOR_TCS34725_LUX_minchange=500 + -D SENSOR_TCS34725_LUX_senddelaymax=1000*60*1 + -D SENSOR_TCS34725_COLORTEMP_minchange=100 + -D SENSOR_TCS34725_LUXFACTOR=0.3 #measured with luxmeter. with half tennis ball was 1.7ev less. 1/2^1.7=0,3078 + lib_deps = ArduinoJson@6.16.1 #dependency of homie. using older version because of "ambiguous overload for operator|" error Homie@3.0.0 - adafruit/Adafruit HTU21DF Library @ ^1.0.5 \ No newline at end of file + adafruit/Adafruit HTU21DF Library @ ^1.0.5 + https://github.com/adafruit/Adafruit_TCS34725#1.3.5 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f3d207d..b9c04bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_DHT22 - #include "sensor_dht22.cpp" + #include "sensor_dht22.h" Sensor_DHT22 sensor_dht22(SENSOR_DHT22_PIN); #ifndef SENSOR_DHT22_temperature_minchange @@ -58,7 +58,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_BMP180 - #include "sensor_bmp180.cpp" + #include "sensor_bmp180.h" Sensor_BMP180 sensor_bmp180; #ifndef SENSOR_BMP180_temperature_minchange @@ -83,7 +83,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_HTU21D - #include "sensor_htu21d.cpp" + #include "sensor_htu21d.h" Sensor_HTU21D sensor_htu21d; #ifndef SENSOR_HTU21D_temperature_minchange @@ -110,7 +110,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_SHT31 - #include "sensor_sht31.cpp" + #include "sensor_sht31.h" Sensor_SHT31 sensor_sht31; #ifndef SENSOR_SHT31_temperature_minchange @@ -136,7 +136,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_HS1101 - #include "sensor_hs1101.cpp" + #include "sensor_hs1101.h" Sensor_HS1101 sensor_hs1101(SENSOR_HS1101_PIN); #ifndef SENSOR_HS1101_humidity_minchange @@ -152,7 +152,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_BH1750 - #include "sensor_bh1750.cpp" + #include "sensor_bh1750.h" Sensor_BH1750 sensor_bh1750; #ifndef SENSOR_BH1750_light_minchange @@ -167,7 +167,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_ML8511 - #include "sensor_ml8511.cpp" + #include "sensor_ml8511.h" Sensor_ML8511 sensor_ml8511(SENSOR_ML8511_PIN); #ifndef SENSOR_ML8511_minchange @@ -183,7 +183,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_HCSR501 - #include "sensor_hcsr501.cpp" + #include "sensor_hcsr501.h" Sensor_HCSR501 sensor_hcsr501(SENSOR_HCSR501_PIN); #ifndef SENSOR_HCSR501_senddelaymax @@ -195,7 +195,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_RADAR - #include "sensor_radar.cpp" + #include "sensor_radar.h" Sensor_Radar sensor_radar(SENSOR_RADAR_PIN); #ifndef SENSOR_RADAR_senddelaymax @@ -207,7 +207,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_LDR - #include "sensor_ldr.cpp" + #include "sensor_ldr.h" Sensor_LDR sensor_ldr(SENSOR_LDR_PIN); #ifndef SENSOR_LDR_minchange @@ -259,7 +259,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_SDS018 - #include "sensor_sds018.cpp" + #include "sensor_sds018.h" Sensor_SDS018 sensor_sds018(SENSOR_SDS018_SERIAL_RX,SENSOR_SDS018_SERIAL_TX); #ifndef SENSOR_SDS018_PM10_minchange #define SENSOR_SDS018_PM10_minchange 10.0 @@ -282,7 +282,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_TCS34725 - #include "sensor_tcs34725.cpp" + #include "sensor_tcs34725.h" Sensor_TCS34725 sensor_tcs34725; #ifndef SENSOR_TCS34725_LUX_minchange #define SENSOR_TCS34725_LUX_minchange 500 @@ -305,7 +305,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_VL53L1X - #include "sensor_vl53l1x.cpp" + #include "sensor_vl53l1x.h" Sensor_VL53L1X sensor_vl53l1x; #ifndef SENSOR_VL53L1X_minchange #define SENSOR_VL53L1X_minchange 100 @@ -321,10 +321,11 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_ANEMOMETER void ICACHE_RAM_ATTR interrupt_anemometer(); #include "sensor_anemometer.cpp" + //Sensor_Anemometer_Instance = new Sensor_Anemometer(SENSOR_Anemometer_PIN); Sensor_Anemometer sensor_anemometer(SENSOR_Anemometer_PIN); - + void ICACHE_RAM_ATTR interrupt_anemometer() { if (millis() - sensor_anemometer.anemometer_lastpulse_fordebounce >= ANEMOMETER_DEBOUNCETIME) { //ignore if pulse came too fast @@ -333,6 +334,9 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type } } + + + #ifndef SENSOR_Anemometer_minchange #define SENSOR_Anemometer_minchange 0.25 #endif @@ -345,12 +349,14 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #endif #ifdef SENSOR_RAINGAUGE + //uses ATS177 Latched Hall Sensor for rauge flip sensing void ICACHE_RAM_ATTR interrupt_raingauge(); #include "sensor_raingauge.cpp" - + Sensor_Raingauge sensor_raingauge(SENSOR_Raingauge_PIN); + void ICACHE_RAM_ATTR interrupt_raingauge() { if (millis() - sensor_raingauge.raingauge_lastpulse_fordebounce >= RAINGAUGE_DEBOUNCETIME) { //ignore if pulse came too fast @@ -374,7 +380,7 @@ HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type #ifdef SENSOR_MULTICHANNELGASGMXXX - #include "sensor_multichannelgasgmxxx.cpp" + #include "sensor_multichannelgasgmxxx.h" Sensor_MULTICHANNELGASGMXXX sensor_multichannelgasgmxxx; #ifndef SENSOR_MULTICHANNELGASGMXXX_no2_minchange diff --git a/include/sensor_bh1750.cpp b/src/sensor_bh1750.cpp similarity index 98% rename from include/sensor_bh1750.cpp rename to src/sensor_bh1750.cpp index 372d5d7..34f044c 100644 --- a/include/sensor_bh1750.cpp +++ b/src/sensor_bh1750.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_BH1750 //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_bh1750.h" @@ -63,3 +64,5 @@ void Sensor_BH1750::sensorloop() } } } + +#endif \ No newline at end of file diff --git a/include/sensor_bmp180.cpp b/src/sensor_bmp180.cpp similarity index 98% rename from include/sensor_bmp180.cpp rename to src/sensor_bmp180.cpp index 7633cef..5d1cced 100644 --- a/include/sensor_bmp180.cpp +++ b/src/sensor_bmp180.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_BMP180 //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_bmp180.h" @@ -103,3 +104,6 @@ void Sensor_BMP180::loop_BMP180_pressure() d.lastsent=millis(); } } + + +#endif \ No newline at end of file diff --git a/include/sensor_dht22.cpp b/src/sensor_dht22.cpp similarity index 99% rename from include/sensor_dht22.cpp rename to src/sensor_dht22.cpp index bd9b46b..efece31 100644 --- a/include/sensor_dht22.cpp +++ b/src/sensor_dht22.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_DHT22 // Digital pin connected to the DHT sensor. // dht pins: 1=power, 2=data, 3=NC, 4=GND. 10k from data to power needed #include "sensor_dht22.h" @@ -108,3 +109,5 @@ void Sensor_DHT22::loop_DHT22_humidity() } } + +#endif \ No newline at end of file diff --git a/include/sensor_hcsr501.cpp b/src/sensor_hcsr501.cpp similarity index 98% rename from include/sensor_hcsr501.cpp rename to src/sensor_hcsr501.cpp index c2cd01c..61d9bd0 100644 --- a/include/sensor_hcsr501.cpp +++ b/src/sensor_hcsr501.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_HCSR501 // PIR Sensors HC-SR501 // pir sensor needs 5v through an inductor for filtering. output level is 3.3v // 100nF capacitor should be soldered between pins 12 and 13 of BISS0001 to stop interference from esp causing false triggers (in some setups). source: https://www.letscontrolit.com/forum/viewtopic.php?t=671 @@ -65,3 +66,6 @@ void Sensor_HCSR501::sensorloop() } + + +#endif \ No newline at end of file diff --git a/include/sensor_hs1101.cpp b/src/sensor_hs1101.cpp similarity index 99% rename from include/sensor_hs1101.cpp rename to src/sensor_hs1101.cpp index 9806a28..8a6ace1 100644 --- a/include/sensor_hs1101.cpp +++ b/src/sensor_hs1101.cpp @@ -1,4 +1,4 @@ - +#ifdef SENSOR_HS1101 #include "sensor_hs1101.h" @@ -101,4 +101,6 @@ int Sensor_HS1101::get_mapped(const unsigned int* _in, const unsigned int* _out, // interpolate in the right segment for the rest return map(val, _in[pos-1], _in[pos], _out[pos-1], _out[pos]); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/sensor_htu21d.cpp b/src/sensor_htu21d.cpp similarity index 98% rename from include/sensor_htu21d.cpp rename to src/sensor_htu21d.cpp index c24e42b..75a00ac 100644 --- a/include/sensor_htu21d.cpp +++ b/src/sensor_htu21d.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_HTU21D //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_htu21d.h" #include @@ -106,4 +107,6 @@ void Sensor_HTU21D::loop_HTU21D_humidity() d.lastsent=millis(); } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/sensor_ldr.cpp b/src/sensor_ldr.cpp similarity index 98% rename from include/sensor_ldr.cpp rename to src/sensor_ldr.cpp index 12b9fa0..105aa80 100644 --- a/include/sensor_ldr.cpp +++ b/src/sensor_ldr.cpp @@ -1,3 +1,5 @@ +#ifdef SENSOR_LDR + // High/Low Output LDR Sensor // For example: RCWL-0516 (needs 5v input (gnd, vin), 3.3v output level. high for 2seconds when movement detected) #include "sensor_ldr.h" @@ -86,4 +88,5 @@ int Sensor_LDR::get_lux(const unsigned int* _in, const unsigned int* _out, byte // interpolate in the right segment for the rest return map(val, _in[pos-1], _in[pos], _out[pos-1], _out[pos]); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/include/sensor_ml8511.cpp b/src/sensor_ml8511.cpp similarity index 98% rename from include/sensor_ml8511.cpp rename to src/sensor_ml8511.cpp index eb5f9c2..e472a03 100644 --- a/include/sensor_ml8511.cpp +++ b/src/sensor_ml8511.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_ML8511 //ML8511 UV Sensor outputs an analog voltage. ML8511PIN needs to be an ADC pin //value as uvIntensity (mW/cm^2) #include "sensor_ml8511.h" @@ -77,4 +78,5 @@ float Sensor_ML8511::getUV_ML8511(int pin) { float Sensor_ML8511::mapfloat(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/include/sensor_multichannelgasgmxxx.cpp b/src/sensor_multichannelgasgmxxx.cpp similarity index 99% rename from include/sensor_multichannelgasgmxxx.cpp rename to src/sensor_multichannelgasgmxxx.cpp index c38f2c6..2fe1699 100644 --- a/include/sensor_multichannelgasgmxxx.cpp +++ b/src/sensor_multichannelgasgmxxx.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_MULTICHANNELGASGMXXX //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_multichannelgasgmxxx.h" @@ -177,4 +178,6 @@ val = gas.measure_VOC(); Serial.print("VOC: "); Serial.print(val); Serial.print( Serial.print(gas.calcVol(val)); Serial.println("V"); val = gas.measure_CO(); Serial.print("CO: "); Serial.print(val); Serial.print(" eq "); Serial.print(gas.calcVol(val)); Serial.println("V"); -*/ \ No newline at end of file +*/ + +#endif \ No newline at end of file diff --git a/include/sensor_radar.cpp b/src/sensor_radar.cpp similarity index 98% rename from include/sensor_radar.cpp rename to src/sensor_radar.cpp index 759ce55..1b1397e 100644 --- a/include/sensor_radar.cpp +++ b/src/sensor_radar.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_RADAR // High/Low Output Radar Sensor // For example: RCWL-0516 (needs 5v input (gnd, vin), 3.3v output level. high for 2seconds when movement detected) #include "sensor_radar.h" @@ -59,3 +60,5 @@ void Sensor_Radar::sensorloop() } + +#endif \ No newline at end of file diff --git a/include/sensor_sds018.cpp b/src/sensor_sds018.cpp similarity index 99% rename from include/sensor_sds018.cpp rename to src/sensor_sds018.cpp index 740e390..a218cce 100644 --- a/include/sensor_sds018.cpp +++ b/src/sensor_sds018.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_SDS018 #include "sensor_sds018.h" // SDS018 example: https://github.com/crystaldust/sds018/blob/master/sds018.ino @@ -154,4 +155,5 @@ void Sensor_SDS018::readSDS018() sds018_swSerial->flush(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/include/sensor_sht31.cpp b/src/sensor_sht31.cpp similarity index 99% rename from include/sensor_sht31.cpp rename to src/sensor_sht31.cpp index f36a992..6025d88 100644 --- a/include/sensor_sht31.cpp +++ b/src/sensor_sht31.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_SHT31 //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_sht31.h" @@ -127,4 +128,6 @@ void Sensor_SHT31::checkHeater(float humidity) { last_sent_heaterstatus=heaterstatus; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/sensor_tcs34725.cpp b/src/sensor_tcs34725.cpp similarity index 99% rename from include/sensor_tcs34725.cpp rename to src/sensor_tcs34725.cpp index abe75a3..66ee1f3 100644 --- a/include/sensor_tcs34725.cpp +++ b/src/sensor_tcs34725.cpp @@ -1,4 +1,4 @@ - +#ifdef SENSOR_TCS34725 #include "sensor_tcs34725.h" //#include "Adafruit_TCS34725.h" //Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X); //initializer from standart class @@ -157,3 +157,5 @@ void Sensor_TCS34725::loop_colortemp() d.lastsent=millis(); } } + +#endif \ No newline at end of file diff --git a/include/sensor_vl53l1x.cpp b/src/sensor_vl53l1x.cpp similarity index 99% rename from include/sensor_vl53l1x.cpp rename to src/sensor_vl53l1x.cpp index 9160001..d8bc803 100644 --- a/include/sensor_vl53l1x.cpp +++ b/src/sensor_vl53l1x.cpp @@ -1,3 +1,4 @@ +#ifdef SENSOR_VL53L1X //Connect SCL to D1, SDA to D2, GND and 3v3 #include "sensor_vl53l1x.h" @@ -97,3 +98,5 @@ void Sensor_VL53L1X::sensorloop() } } } + +#endif \ No newline at end of file diff --git a/src/tcs34725_agc.cpp b/src/tcs34725_agc.cpp index abbdd9a..258c8e9 100644 --- a/src/tcs34725_agc.cpp +++ b/src/tcs34725_agc.cpp @@ -1,5 +1,5 @@ -#ifdef SENSOR_TCS34725 +#ifdef SENSOR_TCS34725 //#include //#include "Adafruit_TCS34725.h" #include "tcs34725_agc.h"