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