-
Notifications
You must be signed in to change notification settings - Fork 0
/
waterbot.cpp
90 lines (70 loc) · 2.64 KB
/
waterbot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Do not remove the include below
#include "waterbot.h"
#include <Arduino.h>
#include <pins_arduino.h>
#include <stddef.h>
#include "src/infrastructure/Debugger.h"
#include "src/infrastructure/PauseService.h"
#include "src/infrastructure/pin/onboard/OnboardDigitalOutputPin.h"
#include "src/infrastructure/drystrategy/TimerDryStrategyFactory.h"
#include "src/infrastructure/pcf8574/PCF8574PotRepository.h"
#include "src/model/AutomaticWaterService.h"
#include "src/model/Pump.h"
#include "src/application/AutomaticWaterApplicationService.h"
#include "src/application/PauseApplicationService.h"
using waterbot::infrastructure::pin::onboard::OnboardDigitalOutputPin;
using waterbot::infrastructure::drystrategy::TimerDryStrategyFactory;
using waterbot::model::Pump;
using waterbot::model::AutomaticWaterService;
using waterbot::model::Pot;
using waterbot::application::AutomaticWaterApplicationService;
using waterbot::application::PauseApplicationService;
using waterbot::infrastructure::pcf8574::PCF8574PotRepository;
using waterbot::infrastructure::PauseService;
#if LOGGER == LOGGER_SD
#include "src/infrastructure/logger/SDLogger.h"
SDLogger logger(LOG_FILE);
#else
#include "src/infrastructure/logger/SerialLogger.h"
#include "src/infrastructure/LED.h"
using waterbot::infrastructure::LED;
OnboardDigitalOutputPin builtinLEDPin(LED_BUILTIN);
LED loggerLEDs(&builtinLEDPin);
SerialLogger logger(loggerLEDs, loggerLEDs);
#endif
#if PROFILE == PROFILE_DEV
#include "src/infrastructure/rtc/MillisRTC.h"
MillisRTC rtc;
#elif PROFILE == PROFILE_PRODUCTION
#include "src/infrastructure/rtc/DS1307RTC.h"
DS1307RTC rtc;
#endif
OnboardDigitalOutputPin pumpPin(PIN_PUMP);
Pump pump(&pumpPin, PUMP_TURN_OFF_DELAY_MILLIS);
AutomaticWaterService automaticWaterService(WATER_SECONDS, COOL_DOWN_SECONDS,
MAX_WATERLESS_DAYS);
TimerDryStrategyFactory dryTimerFactory(DRY_TIMER_HOURS);
PCF8574PotRepository potRepository;
AutomaticWaterApplicationService automaticWaterApplicationService(
&potRepository, &automaticWaterService);
PauseService pause;
PauseApplicationService pauseApplicationService(&potRepository, pause);
void setup() {
rtc.begin();
logger.begin();
Debugger::logAndClearResetReason();
potRepository.begin(&dryTimerFactory, &pump,
PIN_PCF8574_VALVE, VALVE_DELAY_MILLIS,
PIN_PCF8574_SENSOR, PIN_PCF8574_LED, PIN_PCF8574_ERROR_LED);
// Water all pots, as a visual self test
Pot** pots = potRepository.findAll();
for (int i = 0; i < potRepository.count(); i++) {
Pot* pot = pots[i];
pot->water(BOOT_WATER_SECONDS);
}
}
void loop() {
Debugger::logMemory();
automaticWaterApplicationService.waterAllPotsIfNeeded();
pauseApplicationService.pause(PAUSE_SECONDS);
}