restructure logic to work on groups of valves and sensors instead of being 1:1:1
This commit is contained in:
parent
794c17052f
commit
7a25e4b46e
1 changed files with 337 additions and 223 deletions
292
config.hpp
292
config.hpp
|
|
@ -1,21 +1,30 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
typedef struct {
|
||||
struct Sensor {
|
||||
/// Which analog pin this is connected to (A0, A1, ...)
|
||||
uint8_t pin;
|
||||
/// The value sensors read when completely dry
|
||||
int calibration_dry;
|
||||
/// The value sensors read when completely wet
|
||||
int calibration_wet;
|
||||
} Sensor;
|
||||
/// Pot group index this sensor belongs to
|
||||
unsigned int pot_group;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t valve_pin;
|
||||
struct Group {
|
||||
/// Enable or disable the group
|
||||
bool enabled;
|
||||
/// Which pin the indicator light is connected to
|
||||
uint8_t led_pin;
|
||||
Sensor sensor;
|
||||
// define additional per-pot config here
|
||||
} PotConfig;
|
||||
};
|
||||
|
||||
struct Valve {
|
||||
/// The digital pin this valve is connected to
|
||||
uint8_t pin;
|
||||
/// Pot group index this valve belongs to
|
||||
unsigned int pot_group;
|
||||
};
|
||||
|
||||
constexpr unsigned int SECOND = 1000;
|
||||
constexpr unsigned int MINUTE = SECOND * 60;
|
||||
|
|
@ -33,7 +42,7 @@ constexpr int MAX_HUMIDITY_PERCENT = 70;
|
|||
/// the amount of time a valve needs to open/close
|
||||
constexpr int VALVE_DELAY_MS = 1 * SECOND / 4;
|
||||
|
||||
/// the amount of time the pump needs to start/stop
|
||||
/// the amount of time the pump needs to szcttart/stop
|
||||
constexpr int PUMP_DELAY_MS = 1 * SECOND / 4;
|
||||
|
||||
/// the amount of time to water the plot (valve open and pump running)
|
||||
|
|
@ -53,152 +62,137 @@ constexpr uint8_t PUMP_LED_PIN = 3;
|
|||
|
||||
constexpr uint8_t OK_LED_PIN = 2;
|
||||
|
||||
/// Per-pot configuration
|
||||
constexpr PotConfig POT_CONFIGS[] = {
|
||||
{
|
||||
.valve_pin = 23,
|
||||
constexpr struct Group GROUPS[] = {
|
||||
{ // 0
|
||||
.enabled = true,
|
||||
.led_pin = 22,
|
||||
.sensor = {
|
||||
.pin = A0,
|
||||
.calibration_dry = 540,
|
||||
.calibration_wet = 250,
|
||||
}
|
||||
},
|
||||
//{
|
||||
// .valve_pin = 25,
|
||||
// .led_pin = 24,
|
||||
// .sensor = {
|
||||
// .pin = A1,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 27,
|
||||
// .led_pin = 26,
|
||||
// .sensor = {
|
||||
// .pin = A2,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 29,
|
||||
// .led_pin = 28,
|
||||
// .sensor = {
|
||||
// .pin = A3,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
{
|
||||
.valve_pin = 31,
|
||||
}, { // 1
|
||||
.enabled = false,
|
||||
.led_pin = 24,
|
||||
}, { // 2
|
||||
.enabled = false,
|
||||
.led_pin = 26,
|
||||
}, { // 3
|
||||
.enabled = false,
|
||||
.led_pin = 28,
|
||||
}, { // 4
|
||||
.enabled = true,
|
||||
.led_pin = 30,
|
||||
.sensor = {
|
||||
.pin = A4,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
}
|
||||
},
|
||||
//{
|
||||
// .valve_pin = 33,
|
||||
// .led_pin = 32,
|
||||
// .sensor = {
|
||||
// .pin = A5,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 35,
|
||||
// .led_pin = 34,
|
||||
// .sensor = {
|
||||
// .pin = A6,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 37,
|
||||
// .led_pin = 36,
|
||||
// .sensor = {
|
||||
// .pin = A7,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 39,
|
||||
// .led_pin = 38,
|
||||
// .sensor = {
|
||||
// .pin = A8,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
{
|
||||
.valve_pin = 41,
|
||||
}, { // 5
|
||||
.enabled = false,
|
||||
.led_pin = 32,
|
||||
}, { // 6
|
||||
.enabled = false,
|
||||
.led_pin = 34,
|
||||
}, { // 7
|
||||
.enabled = false,
|
||||
.led_pin = 36,
|
||||
}, { // 8
|
||||
.enabled = false,
|
||||
.led_pin = 38,
|
||||
}, { // 9
|
||||
.enabled = true,
|
||||
.led_pin = 40,
|
||||
.sensor = {
|
||||
.pin = A9,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
}
|
||||
},
|
||||
//{
|
||||
// .valve_pin = 43,
|
||||
// .led_pin = 42,
|
||||
// .sensor = {
|
||||
// .pin = A10,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 45,
|
||||
// .led_pin = 44,
|
||||
// .sensor = {
|
||||
// .pin = A11,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
{
|
||||
.valve_pin = 47,
|
||||
}, { // 10
|
||||
.enabled = false,
|
||||
.led_pin = 42,
|
||||
}, { // 11
|
||||
.enabled = false,
|
||||
.led_pin = 44,
|
||||
}, { // 12
|
||||
.enabled = true,
|
||||
.led_pin = 46,
|
||||
.sensor = {
|
||||
.pin = A12,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
}
|
||||
},
|
||||
{
|
||||
.valve_pin = 49,
|
||||
}, { // 13
|
||||
.enabled = true,
|
||||
.led_pin = 48,
|
||||
.sensor = {
|
||||
.pin = A13,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
}
|
||||
}, { // 14
|
||||
.enabled = false,
|
||||
.led_pin = 50,
|
||||
}, { // 15
|
||||
.enabled = false,
|
||||
.led_pin = 52,
|
||||
},
|
||||
//{
|
||||
// .valve_pin = 51,
|
||||
// .led_pin = 50,
|
||||
// .sensor = {
|
||||
// .pin = A14,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
//{
|
||||
// .valve_pin = 53,
|
||||
// .led_pin = 52,
|
||||
// .sensor = {
|
||||
// .pin = A15,
|
||||
// .calibration_dry = 520,
|
||||
// .calibration_wet = 100,
|
||||
// }
|
||||
//},
|
||||
};
|
||||
|
||||
constexpr unsigned int POT_COUNT = sizeof(POT_CONFIGS) / sizeof(POT_CONFIGS[0]);
|
||||
constexpr struct Sensor SENSORS[] = {
|
||||
{
|
||||
.pin = A0,
|
||||
.calibration_dry = 540,
|
||||
.calibration_wet = 250,
|
||||
.pot_group = 0,
|
||||
}, {
|
||||
.pin = A4,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
.pot_group = 4,
|
||||
}, {
|
||||
.pin = A9,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
.pot_group = 9,
|
||||
}, {
|
||||
.pin = A12,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
.pot_group = 12,
|
||||
}, {
|
||||
.pin = A13,
|
||||
.calibration_dry = 520,
|
||||
.calibration_wet = 100,
|
||||
.pot_group = 13,
|
||||
},
|
||||
|
||||
// the rest of A0-A15 are not used
|
||||
};
|
||||
|
||||
constexpr struct Valve VALVES[] = {
|
||||
{
|
||||
.pin = 23,
|
||||
.pot_group = 0,
|
||||
}, {
|
||||
.pin = 25,
|
||||
.pot_group = 1,
|
||||
}, {
|
||||
.pin = 27,
|
||||
.pot_group = 2,
|
||||
}, {
|
||||
.pin = 29,
|
||||
.pot_group = 3,
|
||||
}, {
|
||||
.pin = 31,
|
||||
.pot_group = 4,
|
||||
}, {
|
||||
.pin = 33,
|
||||
.pot_group = 5,
|
||||
}, {
|
||||
.pin = 35,
|
||||
.pot_group = 6,
|
||||
}, {
|
||||
.pin = 37,
|
||||
.pot_group = 7,
|
||||
}, {
|
||||
.pin = 39,
|
||||
.pot_group = 8,
|
||||
}, {
|
||||
.pin = 41,
|
||||
.pot_group = 9,
|
||||
}, {
|
||||
.pin = 43,
|
||||
.pot_group = 10,
|
||||
}, {
|
||||
.pin = 45,
|
||||
.pot_group = 11,
|
||||
}, {
|
||||
.pin = 47,
|
||||
.pot_group = 12,
|
||||
}, {
|
||||
.pin = 49,
|
||||
.pot_group = 13,
|
||||
}, {
|
||||
.pin = 51,
|
||||
.pot_group = 14,
|
||||
}, {
|
||||
.pin = 53,
|
||||
.pot_group = 15,
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue