36 lines
756 B
C++
36 lines
756 B
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <pico/stdlib.h>
|
|
|
|
|
|
class Valve {
|
|
public:
|
|
enum class State {
|
|
Unknown,
|
|
Opening,
|
|
Opened,
|
|
Closing,
|
|
Closed
|
|
};
|
|
|
|
Valve(uint gpio_motor1, uint gpio_motor2, uint gpio_start, uint gpio_end);
|
|
|
|
void open();
|
|
void close();
|
|
State process();
|
|
State getState() const { return state; }
|
|
|
|
private:
|
|
uint motor1, motor2;
|
|
uint start_pin, end_pin;
|
|
|
|
std::chrono::seconds timeout = std::chrono::seconds(10);
|
|
std::chrono::milliseconds transition = std::chrono::milliseconds(1000);
|
|
decltype(std::chrono::steady_clock::now()) start_time;
|
|
decltype(std::chrono::steady_clock::now()) transition_time;
|
|
|
|
State state = State::Unknown;
|
|
State pending_state = State::Unknown;
|
|
};
|