From d299c431b247914d5b86e0bad6c67bec4c854fd4 Mon Sep 17 00:00:00 2001 From: GreenWizard Date: Mon, 25 Dec 2023 10:43:51 +0100 Subject: [PATCH] forgotten changes --- controller/tea_poor/.gitignore | 5 +++ .../WaterPumpController.cpp | 38 +++++++++++++++++++ .../WaterPumpController/WaterPumpController.h | 28 ++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 controller/tea_poor/.gitignore create mode 100644 controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp create mode 100644 controller/tea_poor/lib/WaterPumpController/WaterPumpController.h diff --git a/controller/tea_poor/.gitignore b/controller/tea_poor/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/controller/tea_poor/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp new file mode 100644 index 0000000..b8ce60f --- /dev/null +++ b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp @@ -0,0 +1,38 @@ +#include +#include "WaterPumpController.h" + +WaterPumpController::WaterPumpController(int directionPin, int brakePin, int powerPin) : + _directionPin(directionPin), + _brakePin(brakePin), + _powerPin(powerPin) +{ + +} + +WaterPumpController::~WaterPumpController() {} + +void WaterPumpController::setup() { + pinMode(_directionPin, OUTPUT); + pinMode(_brakePin, OUTPUT); + pinMode(_powerPin, OUTPUT); + // TODO: check that its okay to do during setup + stopPump(); +} + +void WaterPumpController::pour(int milliseconds) { + startPump(); + delay(milliseconds); + stopPump(); +} + +void WaterPumpController::startPump() { + _state = PUMP_ON; + digitalWrite(_brakePin, LOW); // release breaks + analogWrite(_powerPin, 255); +} + +void WaterPumpController::stopPump() { + digitalWrite(_brakePin, HIGH); // activate breaks + analogWrite(_powerPin, 0); + _state = PUMP_OFF; +} diff --git a/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h new file mode 100644 index 0000000..8561876 --- /dev/null +++ b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h @@ -0,0 +1,28 @@ +#ifndef WATERPUMPCONTROLLER_H +#define WATERPUMPCONTROLLER_H + +class WaterPumpController { +public: + enum EPumpState { + PUMP_OFF, + PUMP_ON + }; +private: + const int _directionPin; + const int _brakePin; + const int _powerPin; + const int _maxPower = 255; + EPumpState _state = PUMP_OFF; +public: + WaterPumpController(int directionPin, int brakePin, int powerPin); + ~WaterPumpController(); + + void setup(); + void pour(int miliseconds); + void startPump(); + void stopPump(); + + EPumpState state() const { return _state; } +}; + +#endif // WATERPUMPCONTROLLER_H