fix for capacitive sensors not working, enum introduction for sensormode

This commit is contained in:
c3ma
2022-02-19 02:24:19 +01:00
parent d0320beaa7
commit a0f8df7016
6 changed files with 192 additions and 177 deletions

View File

@@ -1,51 +1,6 @@
/**
* @file ControllerConfiguration.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2020-05-30
*
* @copyright Copyright (c) 2020
*
* \mainpage Configuration of the controller
* @{
* Describe the used PINs of the controller
*
* @subpage Controller
*
* @subpage Homie
*
* @subpage Configuration
*
* There are several modes in the controller
* \dot
* digraph Operationmode {
* ranksep=.75;
* poweroff [ label="off" ];
* mode1 [ label="Mode 1 - Sensor only", shape=box, width=2 ];
* mode2 [ label="Mode 2 - Wifi enabled", shape=box ];
* mode3 [ label="Mode 3 - Stay alive", shape=box ];
* mode1 -> mode2 [ label="wakeup reason", fontsize=10 ];
* mode1 -> mode2 [ label="Time duration", fontsize=10 ];
* mode2 -> mode3 [ label="Over the Air Update", fontsize=10 ];
* mode3 -> mode2 [ label="Over the Air Finished", fontsize=10 ];
* mode3 -> mode2 [ label="Mqtt Command", fontsize=10 ];
* mode2 -> mode3 [ label="Mqtt Command", fontsize=10 ];
* poweroff -> mode1 [ label="deep sleep wakeup", fontsize=10 ];
* mode1 -> poweroff [ label="enter deep sleep", fontsize=10 ];
* mode2 -> poweroff [ label="Mqtt queue empty", fontsize=10 ];
* }
* \enddot
*
* Before entering Deep sleep the controller is configured with an wakeup time.
*
* @}
*/
#ifndef CONTROLLER_CONFIG_H
#define CONTROLLER_CONFIG_H
/** \addtogroup GPIO Settings
* @{
*/
#define SENSOR_PLANT0 GPIO_NUM_32 /**< GPIO 32 (ADC1) */
#define SENSOR_PLANT1 GPIO_NUM_33 /**< GPIO 33 (ADC1) */
#define SENSOR_PLANT2 GPIO_NUM_25 /**< GPIO 25 (ADC2) */
@@ -77,12 +32,8 @@
#define I2C1_SDA GPIO_NUM_34 /**< GPIO 34 - I2C */
#define I2C1_SCL GPIO_NUM_35 /**< GPIO 35 - I2C */
/* @} */
/** \addtogroup Configuration
* @{
*/
#define FIRMWARE_VERSION "sw 2.1 hw 0.10b"
#define FIRMWARE_VERSION "sw 2.2 hw 0.10b"
#define TIMED_LIGHT_PIN CUSTOM1_PIN5
#define FLOWMETER_PIN CUSTOM1_PIN1

View File

@@ -13,9 +13,21 @@
#include <Homie.h>
#define SENSOR_NONE 0
#define SENSOR_CAPACITIVE_FREQUENCY_MOD 1
#define SENSOR_ANALOG_RESISTANCE_PROBE 2
#define FOREACH_SENSOR(SENSOR) \
SENSOR(NONE) \
SENSOR(CAPACITIVE_FREQUENCY) \
SENSOR(ANALOG_RESISTANCE_PROBE) \
#define GENERATE_ENUM(ENUM) ENUM,
#define GENERATE_STRING(STRING) #STRING,
enum SENSOR_MODE {
FOREACH_SENSOR(GENERATE_ENUM)
};
static const char *SENSOR_STRING[] = {
FOREACH_SENSOR(GENERATE_STRING)
};
//plant pump is deactivated, but sensor values are still recorded and published
#define DEACTIVATED_PLANT -1

View File

@@ -64,15 +64,22 @@ public:
void activatePump(void);
String getSensorModeString(){
SENSOR_MODE mode = getSensorMode();
return SENSOR_STRING[mode];
}
bool isHydroponic()
{
long current = this->mSetting->pSensorDry->get();
return equalish(current, HYDROPONIC_MODE);
}
long isSensorMode(int sensorMode)
SENSOR_MODE getSensorMode()
{
return this->mSetting->pSensorMode->get() == sensorMode;
int raw_mode = this->mSetting->pSensorMode->get();
SENSOR_MODE sensorType = static_cast<SENSOR_MODE>(raw_mode);
return sensorType;
}
/**
@@ -113,18 +120,14 @@ public:
float getCurrentMoisturePCT()
{
if (isSensorMode(SENSOR_NONE))
{
switch (getSensorMode()){
case NONE:
return DEACTIVATED_PLANT;
}
if (isSensorMode(SENSOR_CAPACITIVE_FREQUENCY_MOD))
{
return mapf(mMoisture_raw.getMedian(), MOIST_SENSOR_MAX_FRQ, MOIST_SENSOR_MIN_FRQ, 0, 100);
}
else if (isSensorMode(SENSOR_ANALOG_RESISTANCE_PROBE))
{
case CAPACITIVE_FREQUENCY:
return mapf(mMoisture_raw.getMedian(), MOIST_SENSOR_MAX_FRQ, MOIST_SENSOR_MIN_FRQ, 0, 100);
case ANALOG_RESISTANCE_PROBE:
return mapf(mMoisture_raw.getMedian(), ANALOG_SENSOR_MAX_MV, ANALOG_SENSOR_MIN_MV, 0, 100);
} else {
default:
log(LOG_LEVEL_ERROR, LOG_SENSORMODE_UNKNOWN, LOG_SENSORMODE_UNKNOWN_CODE);
return DEACTIVATED_PLANT;
}
@@ -132,14 +135,13 @@ public:
float getCurrentMoistureRaw()
{
if (isSensorMode(SENSOR_CAPACITIVE_FREQUENCY_MOD))
{
if (mMoisture_raw.getMedian() < MOIST_SENSOR_MIN_FRQ)
if(getSensorMode() == CAPACITIVE_FREQUENCY){
if (mMoisture_raw.getMedian() < MOIST_SENSOR_MIN_FRQ)
{
return MISSING_SENSOR;
}
}
return mMoisture_raw.getMedian();
}
@@ -149,6 +151,7 @@ public:
}
void init(void);
void initSensors(void);
long getCooldownInSeconds()
{