some fixes

This commit is contained in:
2024-02-05 17:44:00 +03:00
parent ad13871093
commit b1007e815d

View File

@@ -30,8 +30,8 @@ public:
, end_pin(gpio_end) { , end_pin(gpio_end) {
gpio_init_out(motor1); gpio_init_out(motor1);
gpio_init_out(motor2); gpio_init_out(motor2);
gpio_init(start_pin); gpio_init_input(start_pin);
gpio_init(end_pin); gpio_init_input(end_pin);
start_time = std::chrono::steady_clock::now(); start_time = std::chrono::steady_clock::now();
} }
@@ -56,11 +56,11 @@ public:
} }
State process() { State process() {
if (state == State::Opening && gpio_get(start_pin) == 0) { if ((state == State::Opening) && (gpio_get(start_pin) == 0)) {
gpio_put(motor1, 0); gpio_put(motor1, 0);
state = State::Opened; state = State::Opened;
} }
if (state == State::Closing && gpio_get(end_pin) == 0) { if ((state == State::Closing) && (gpio_get(end_pin) == 0)) {
gpio_put(motor2, 0); gpio_put(motor2, 0);
state = State::Closed; state = State::Closed;
} }
@@ -95,7 +95,7 @@ int main() {
gpio_init_input(button_open); gpio_init_input(button_open);
gpio_init_input(button_close); gpio_init_input(button_close);
const int tick_ms = 500; const int tick_ms = 50;
while (true) { while (true) {
if (gpio_get(button_open) == 0) { if (gpio_get(button_open) == 0) {
cold_valve.open(); cold_valve.open();
@@ -105,12 +105,14 @@ int main() {
cold_valve.close(); cold_valve.close();
hot_valve.close(); hot_valve.close();
} }
gpio_put(PICO_DEFAULT_LED_PIN, 1); sleep_ms(tick_ms);
sleep_ms(tick_ms / 2); const auto cst = cold_valve.process();
cold_valve.process();
hot_valve.process(); hot_valve.process();
gpio_put(PICO_DEFAULT_LED_PIN, 0); if (cst == Valve::State::Opened || cst == Valve::State::Closed) {
sleep_ms(tick_ms / 2); gpio_put(PICO_DEFAULT_LED_PIN, 1);
} else {
gpio_put(PICO_DEFAULT_LED_PIN, 0);
}
} }
return 0; return 0;
} }