Merge branch 'ollo-dev' of github.com:0110/PlantCtrl into ollo-dev

This commit is contained in:
Ollo 2023-03-22 20:02:33 +01:00
commit 1e79588e98
2 changed files with 13 additions and 10 deletions

View File

@ -75,8 +75,6 @@
#define CUSTOM1_PIN5 GPIO_NUM_2 /** mosfet controlled */
#define CUSTOM1_PIN7 GPIO_NUM_12 /** mosfet controlled */
#define I2C1_SDA GPIO_NUM_34 /**< GPIO 34 - I2C */
#define I2C1_SCL GPIO_NUM_35 /**< GPIO 35 - I2C */
/* @} */
/** \addtogroup Configuration
@ -116,7 +114,9 @@
#define MAX_CONFIG_SETTING_ITEMS 100 /**< Parameter, that can be configured in Homie */
#define MAX_JSON_CONFIG_FILE_SIZE_CUSTOM 2500
#define TEMPERATUR_TIMEOUT 3000 /**< 3 Seconds timeout for the temperatur sensors */
#define TEMPERATUR_TIMEOUT 3000 /**< 3 Seconds timeout for the temperatures sensors */
#define WATERSENSOR_TIMEOUT 3000 /**< 3 Seconds timeout for the water distance sensor */
#define WATERSENSOR_CYCLE 5 /**< 5 sensor measurement are performed */
#define DS18B20_RESOLUTION 9 /**< 9bit temperature resolution -> 0.5°C steps */
#define UTC_OFFSET_DE 3600 /* UTC offset in seconds for Germany */

View File

@ -329,11 +329,14 @@ void readPowerSwitchedSensors()
}
}
waterRawSensor.clear();
tankSensor.setTimeout(500);
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL);
// Source: https://www.st.com/resource/en/datasheet/vl53l0x.pdf
tankSensor.setAddress(0x52);
tankSensor.setBus(&Wire);
delay(50);
long start = millis();
bool distanceReady = false;
while (start + 500 > millis())
while ((start + WATERSENSOR_TIMEOUT) > millis())
{
if (tankSensor.init())
{
@ -342,17 +345,18 @@ void readPowerSwitchedSensors()
}
else
{
delay(20);
delay(200);
}
}
if (distanceReady)
{
waterRawSensor.clear();
tankSensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
tankSensor.setMeasurementTimingBudget(200000);
for (int readCnt = 0; readCnt < 5; readCnt++)
for (int readCnt = 0; readCnt < WATERSENSOR_CYCLE; readCnt++)
{
if (!tankSensor.timeoutOccurred())
{
@ -362,7 +366,7 @@ void readPowerSwitchedSensors()
waterRawSensor.add(distance);
}
}
delay(10);
delay(50);
}
Serial << "Distance sensor " << waterRawSensor.getMedian() << " mm" << endl;
}
@ -802,7 +806,6 @@ void safeSetup()
{
mPlants[i].initSensors();
}
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL);
readPowerSwitchedSensors();
Homie.setup();