From e705f97fccc2262e177ed2bde4e579640ec6c80e Mon Sep 17 00:00:00 2001 From: Andrey Bychkov Date: Sun, 4 Feb 2024 22:50:25 +0300 Subject: [PATCH] starting some code --- .vscode/settings.json | 25 +++++++++++++---------- ValveController.cpp | 46 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cc71307..05dc4e3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,17 +1,22 @@ { "cmake.configureOnOpen": false, "cmake.statusbar.advanced": { - "debug" : { + "debug": { "visibility": "hidden" - }, - "launch" : { + }, + "launch": { "visibility": "hidden" - }, - "build" : { + }, + "build": { "visibility": "hidden" - }, - "buildTarget" : { + }, + "buildTarget": { "visibility": "hidden" - }, - }, -} + }, + }, + "clang-format.executable": "C:/qt/qt-creator-8_win_x64/bin/clang-format.exe", + "editor.formatOnSave": true, + "[cpp]": { + "editor.defaultFormatter": "demiaochen.clang-format-indent-4", + }, +} \ No newline at end of file diff --git a/ValveController.cpp b/ValveController.cpp index 35845af..6a2dc32 100644 --- a/ValveController.cpp +++ b/ValveController.cpp @@ -1,14 +1,50 @@ -#include #include "pico/stdlib.h" +void gpio_init_out(uint gpio) { + gpio_set_dir(gpio, GPIO_OUT); + gpio_put(gpio, 0); + gpio_set_function(gpio, GPIO_FUNC_SIO); +} +void gpio_callback(uint gpio, uint32_t events) {} -int main() -{ - stdio_init_all(); +class Valve { + public: + Valve(uint gpio_motor1, uint gpio_motor2, uint gpio_start, uint gpio_end) + : motor1(gpio_motor1), motor2(gpio_motor2), start_pin(gpio_start), + end_pin(gpio_end) { + gpio_init_out(motor1); + gpio_init_out(motor2); + gpio_set_irq_enabled_with_callback(start_pin, GPIO_IRQ_EDGE_RISE, true, + &gpio_callback); + gpio_set_irq_enabled_with_callback(end_pin, GPIO_IRQ_EDGE_RISE, true, + &gpio_callback); + } + void open() { + gpio_put(motor2, 0); + gpio_put(motor1, 1); + } - puts("Hello, world!"); + void close() { + gpio_put(motor1, 0); + gpio_put(motor2, 1); + } + private: + uint motor1, motor2; + uint start_pin, end_pin; +}; + +int main() { + Valve *v = new Valve(0, 1, 4, 5); + + gpio_init_out(PICO_DEFAULT_LED_PIN); + while (true) { + gpio_put(PICO_DEFAULT_LED_PIN, 1); + sleep_ms(200); + gpio_put(PICO_DEFAULT_LED_PIN, 0); + sleep_ms(200); + } return 0; }