Skip to content

Commit

Permalink
Make seconds between pump does configurable. (#16)
Browse files Browse the repository at this point in the history
Also:

- version -> 0.7.2
- move example .ini files into place before platformio test build in CI
  • Loading branch information
chl33 authored Oct 19, 2024
1 parent 0a628ca commit f415eee
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/platformio-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ jobs:
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Setup secrets for build
run: cp secrets.ini.example secrets.ini && cp secrets-usb.ini.example secrets-usb.ini

- name: Build PlatformIO Project
run: pio run
8 changes: 5 additions & 3 deletions lib/watering/watering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Watering::Watering(unsigned index, const char* name, uint8_t moisture_pin, uint8
kCfgSet, 0, m_cfg_vg),
m_pump_dose_msec("pump_on_msec", 3 * kMsecInSec, units::kMilliseconds, "Pump on time",
kCfgSet, 0, m_cfg_vg),
m_between_doses_sec("between_doses_sec", kPumpOffSec, units::kSeconds, "Wait between doses",
kCfgSet, 0, m_cfg_vg),
m_state("watering_state", kStateWaitForNextCycle, "", "watering state", 0, m_vg),
m_watering_enabled("watering_enabled", false, "watering enabled", kCfgSet, m_cfg_vg),
m_reservoir_check_enabled("res_check_enabled", false, "reservior check enabled", kCfgSet,
Expand Down Expand Up @@ -193,7 +195,7 @@ void Watering::loop() {
// before the watering by more than they were during watering mode.
// The time in seconds that the state machine might have switched out of watering mode.
const float stateChangeSec =
static_cast<float>(m_pump.lastOnMsec() + kPumpOffMsec) / kMsecInSec;
static_cast<float>(m_pump.lastOnMsec()) / kMsecInSec + kPumpOffSec;
const float secSinceStateChange = static_cast<float>(nowMsec) / kMsecInSec - stateChangeSec;
// The growing sigma value that should be kKernelWateringSec when the state changed.
const float sigma1 = secSinceStateChange + kKernelWateringSec;
Expand Down Expand Up @@ -231,7 +233,7 @@ void Watering::loop() {
m_pump.turnOff();
// Don't consider turning the pump back on until it has been off for the
// required amount of time.
if (msecSincePump < kPumpOffMsec) {
if (msecSincePump < (m_between_doses_sec.value() * kMsecInSec)) {
setState(kStateEval, kWaitForNextCycleMsec, "pump not off for long enough");
} else if (reservoirCheckEnabled() && isReservoirEmpty()) {
// Reservoir may be low, so don't consider using the pump.
Expand Down Expand Up @@ -270,7 +272,7 @@ void Watering::loop() {
if (m_reservoir_check) {
m_reservoir_check->pumpRanForMsec(m_pump_dose_msec.value());
}
// Eval mode will wait until kPumpOffMsec until it will allow the pump to run again.
// Eval mode will wait until kPumpOffSec until it will allow the pump to run again.
setState(kStateEval, kWaitForNextCycleMsec, "continue watering");
break;

Expand Down
1 change: 1 addition & 0 deletions lib/watering/watering.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Watering : public Module {
FloatVariable m_max_moisture_target;
FloatVariable m_min_moisture_target;
FloatVariable m_pump_dose_msec;
FloatVariable m_between_doses_sec;
StateVariable m_state;
BoolVariable m_watering_enabled;
BoolVariable m_reservoir_check_enabled;
Expand Down
2 changes: 1 addition & 1 deletion lib/watering/watering_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr long kWaitBetweenPumpAndMoisureReadingMsec = kMsecInSec;
// < 5% means the sensor is probably not in soil.
constexpr float kMinPlausibleMoisture = 5.0f;
// Always wait 15 minutes between pump cycles.
constexpr long kPumpOffMsec = 15 * kMsecInMin;
constexpr long kPumpOffSec = 15 * kSecInMin;
// Wait 1 minute between checks in eval mode while waiting for moisture level to drop.
constexpr long kWaitForNextCycleMsec = 1 * kMsecInMin;

Expand Down
4 changes: 0 additions & 4 deletions secrets-usb.ini

This file was deleted.

3 changes: 0 additions & 3 deletions secrets.ini

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "watering.h"

#define SW_VERSION "0.7.1"
#define SW_VERSION "0.7.2"

namespace {

Expand Down

0 comments on commit f415eee

Please sign in to comment.