From: Lukáš Jiřiště Date: Mon, 18 Nov 2024 09:59:08 +0000 (+0100) Subject: Refactor open_barely out of Valve class to a child X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=ae31ccb08c0d10c1adb98798501a0b080f31dac8;p=Servomatic.git Refactor open_barely out of Valve class to a child Because the open_barely method would only be used barely, I think it is better to separate it. --- diff --git a/CellValve.h b/CellValve.h new file mode 100644 index 0000000..ada5a2e --- /dev/null +++ b/CellValve.h @@ -0,0 +1,23 @@ +#ifndef CELLVALVE_H +# define CELLVALVE_H + +#include "Valve.h" + +class CellValve : public Valve +{ + private: + const int m_usec_barely_opened; + + public: + CellValve() = delete; + CellValve(const CellValve &other) = delete; + CellValve(pin pwm_pin, int usec_opened, int usec_barely_opened, + int isec_closed); + ~CellValve(); + + CellValve &operator=(const CellValve &other) = delete; + + void open_barely(float seconds = 5); +}; + +#endif // CELLVALVE_H diff --git a/CellValve.ino b/CellValve.ino new file mode 100644 index 0000000..ad2c8b0 --- /dev/null +++ b/CellValve.ino @@ -0,0 +1,17 @@ +#include "CellValve.h" + +CellValve::CellValve(pin pwm_pin, int usec_opened, int usec_barely_opened, + int usec_closed) + : Valve{pwm_pin, usec_opened, usec_closed} + , m_usec_barely_opened{usec_barely_opened} +{ +} + +CellValve::~CellValve() +{ +} + +void CellValve::open_barely(float seconds) +{ + write_usec_timed(m_usec_barely_opened, seconds); +} diff --git a/Makefile b/Makefile index 4d94553..97a5eea 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ endif SRCS := Servomatic.ino \ PressureSensor.ino \ Valve.ino \ + CellValve.ino \ Measurement.ino \ diff --git a/Valve.h b/Valve.h index f0f514f..9ae0a8a 100644 --- a/Valve.h +++ b/Valve.h @@ -6,29 +6,27 @@ class Valve { private: - typedef int pin; - const Servo m_servo; const int m_usec_opened; - const int m_usec_barely_opened; const int m_usec_closed; int m_usec_current; - void write_usec_timed(int usec_wanted, float seconds); void update_pos(); + protected: + typedef int pin; + + void write_usec_timed(int usec_wanted, float seconds); + public: Valve() = delete; Valve(const Valve &other) = delete; - Valve(pin pwm_pin, int usec_opened, int usec_barely_opened, - int isec_closed); + Valve(pin pwm_pin, int usec_opened, int isec_closed); ~Valve(); Valve &operator=(const Valve &other) = delete; void open(float seconds = 5); - void open_barely(float seconds = 5); void close(float seconds = 5); }; - #endif // VALVE_H diff --git a/Valve.ino b/Valve.ino index 13cb83c..1c18584 100644 --- a/Valve.ino +++ b/Valve.ino @@ -1,9 +1,8 @@ #include "Valve.h" -Valve::Valve(pin pwm_pin, int usec_opened, int usec_barely_opened, int usec_closed) +Valve::Valve(pin pwm_pin, int usec_opened, int usec_closed) : m_servo{} , m_usec_opened{usec_opened} - , m_usec_barely_opened{usec_barely_opened} , m_usec_closed{usec_closed} , m_usec_current{usec_closed} { @@ -52,11 +51,6 @@ void Valve::open(float seconds) write_usec_timed(m_usec_opened, seconds); } -void Valve::open_barely(float seconds) -{ - write_usec_timed(m_usec_barely_opened, seconds); -} - void Valve::close(float seconds) { write_usec_timed(m_usec_closed, seconds);