From a81c7bac778e744c52d398e2ec8a48325149ac7c Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 3 Jun 2022 10:03:48 +0200 Subject: [PATCH 01/11] implement relais and lcd as modules Does NOT compile! Problem might be on the side of the ARM compiler. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 4 +- src/gbmanager.cpp | 10 ++-- src/lcd.cpp | 146 ++++++++++++++++++++++++++------------------- src/relais.cpp | 29 ++++++--- 5 files changed, 114 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 362656f..067f307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-volatile") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-volatile -fmodules-ts") # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdddc2f..6e2e75a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,12 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) +#add_compile_options(-fmodules-ts) + set(SOURCES - gbmanager.cpp lcd.cpp relais.cpp + gbmanager.cpp ) # Add executable. Default name is the project name, version 0.1 diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index a932d61..5ae7a7d 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -5,8 +5,10 @@ #include "pico/stdlib.h" #include "config.h" -#include "lcd.h" -#include "relais.h" +//#include "lcd.h" + +import lcd; +import relais; // GPIOs used constexpr uint I2C_SDA_PIN = 26; @@ -28,7 +30,7 @@ absolute_time_t lastPressed = get_absolute_time(); using std::string; -void buttonPressedCallback(uint gpio, uint32_t events) { +void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) { absolute_time_t now = get_absolute_time(); if (absolute_time_diff_us(lastPressed, now) < 750000) { return; @@ -54,7 +56,7 @@ int main() { stdio_init_all(); // Initialize the LCD - auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN); + auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN, 16, 2); myLCD.clear(); // Initialize the temp sensor diff --git a/src/lcd.cpp b/src/lcd.cpp index 52c512e..c8cf230 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -1,6 +1,12 @@ -#include "pico/binary_info.h" +module; -#include "lcd.h" +#include + +#include "hardware/i2c.h" +#include "pico/binary_info.h" +#include "pico/stdlib.h" + +export module lcd; // commands constexpr int LCD_CLEARDISPLAY = 0x01; @@ -29,74 +35,90 @@ constexpr int LCD_8BITMODE = 0x10; constexpr int LCD_BACKLIGHT = 0x08; constexpr int LCD_ENABLE_BIT = 0x04; -LCD::LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl, - const uint8_t i2c_addr, uint8_t num_cols, uint8_t num_lines) - : i2c{i2c}, i2c_addr{i2c_addr}, num_cols{num_cols}, num_lines{num_lines} { - i2c_init(i2c, 400 * 1000); - gpio_set_function(gpio_sda, GPIO_FUNC_I2C); - gpio_set_function(gpio_scl, GPIO_FUNC_I2C); - gpio_pull_up(gpio_sda); - gpio_pull_up(gpio_scl); - // Make the I2C pins available to picotool - bi_decl(bi_2pins_with_func(gpio_sda, gpio_scl, GPIO_FUNC_I2C)); +enum class Mode { COMMAND, CHARACTER }; - sendByte(0x03, Mode::COMMAND); - sendByte(0x03, Mode::COMMAND); - sendByte(0x03, Mode::COMMAND); - sendByte(0x02, Mode::COMMAND); +export class LCD { + public: + LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl, + const uint8_t i2c_addr, const uint8_t num_cols = 16, + const uint8_t num_lines = 2) + : i2c{i2c}, i2c_addr{i2c_addr}, num_cols{num_cols}, num_lines{ + num_lines} { + i2c_init(i2c, 400 * 1000); + gpio_set_function(gpio_sda, GPIO_FUNC_I2C); + gpio_set_function(gpio_scl, GPIO_FUNC_I2C); + gpio_pull_up(gpio_sda); + gpio_pull_up(gpio_scl); + // Make the I2C pins available to picotool + bi_decl(bi_2pins_with_func(gpio_sda, gpio_scl, GPIO_FUNC_I2C)); - sendByte(LCD_ENTRYMODESET | LCD_ENTRYLEFT, Mode::COMMAND); - sendByte(LCD_FUNCTIONSET | LCD_2LINE, Mode::COMMAND); - sendByte(LCD_DISPLAYCONTROL | LCD_DISPLAYON, Mode::COMMAND); - clear(); -} + sendByte(0x03, Mode::COMMAND); + sendByte(0x03, Mode::COMMAND); + sendByte(0x03, Mode::COMMAND); + sendByte(0x02, Mode::COMMAND); -// Go to location on LCD -void LCD::setCursor(int line, int position) { - int val = (line == 0) ? 0x80 + position : 0xC0 + position; - sendByte(val, Mode::COMMAND); - cursor_x = line; - cursor_y = position; -} + sendByte(LCD_ENTRYMODESET | LCD_ENTRYLEFT, Mode::COMMAND); + sendByte(LCD_FUNCTIONSET | LCD_2LINE, Mode::COMMAND); + sendByte(LCD_DISPLAYCONTROL | LCD_DISPLAYON, Mode::COMMAND); + clear(); + } -void LCD::sendChar(char val) { sendByte(val, Mode::CHARACTER); } - -void LCD::sendString(const std::string &str) { - for (const char &c : str) { - if (c == '\n') { - cursor_y++; - setCursor(cursor_y, 0); - } else { - sendChar(c); - cursor_x++; + void sendString(const std::string &str) { + for (const char &c : str) { + if (c == '\n') { + cursor_y++; + setCursor(cursor_y, 0); + } else { + sendChar(c); + cursor_x++; + } } } -} -void LCD::clear() { sendByte(LCD_CLEARDISPLAY, Mode::COMMAND); } + // Go to location on LCD + void setCursor(int line, int position) { + int val = (line == 0) ? 0x80 + position : 0xC0 + position; + sendByte(val, Mode::COMMAND); + cursor_x = line; + cursor_y = position; + } -void LCD::i2cWriteByte(uint8_t val) { - i2c_write_blocking(i2c, i2c_addr, &val, 1, false); -} + void clear() { sendByte(LCD_CLEARDISPLAY, Mode::COMMAND); } -void LCD::toggleEnable(uint8_t val) { - // Toggle enable pin on LCD display - // We cannot do this too quickly or things don't work - constexpr uint64_t DELAY_US = 600; - sleep_us(DELAY_US); - i2cWriteByte(val | LCD_ENABLE_BIT); - sleep_us(DELAY_US); - i2cWriteByte(val & ~LCD_ENABLE_BIT); - sleep_us(DELAY_US); -} + private: + void sendChar(char val) { sendByte(val, Mode::CHARACTER); } -// The display is sent a byte as two separate nibble transfers -void LCD::sendByte(uint8_t val, Mode mode) { - uint8_t high = static_cast(mode) | (val & 0xF0) | LCD_BACKLIGHT; - uint8_t low = static_cast(mode) | ((val << 4) & 0xF0) | LCD_BACKLIGHT; + void i2cWriteByte(uint8_t val) { + i2c_write_blocking(i2c, i2c_addr, &val, 1, false); + } - i2cWriteByte(high); - toggleEnable(high); - i2cWriteByte(low); - toggleEnable(low); -} + void toggleEnable(uint8_t val) { + // Toggle enable pin on LCD display + // We cannot do this too quickly or things don't work + constexpr uint64_t DELAY_US = 600; + sleep_us(DELAY_US); + i2cWriteByte(val | LCD_ENABLE_BIT); + sleep_us(DELAY_US); + i2cWriteByte(val & ~LCD_ENABLE_BIT); + sleep_us(DELAY_US); + } + + // The display is sent a byte as two separate nibble transfers + void sendByte(uint8_t val, Mode mode) { + uint8_t high = static_cast(mode) | (val & 0xF0) | LCD_BACKLIGHT; + uint8_t low = + static_cast(mode) | ((val << 4) & 0xF0) | LCD_BACKLIGHT; + + i2cWriteByte(high); + toggleEnable(high); + i2cWriteByte(low); + toggleEnable(low); + } + + i2c_inst_t *i2c; + uint8_t i2c_addr; + uint8_t num_cols; + uint8_t num_lines; + uint8_t cursor_x{0}; + uint8_t cursor_y{0}; +}; \ No newline at end of file diff --git a/src/relais.cpp b/src/relais.cpp index 6742c33..39bc970 100644 --- a/src/relais.cpp +++ b/src/relais.cpp @@ -1,13 +1,24 @@ -#include "relais.h" +module; -Relais::Relais(uint gpio) : gpio{gpio} { - gpio_init(gpio); - gpio_set_dir(gpio, GPIO_OUT); - off(); -} +#include "hardware/gpio.h" +#include "pico/stdlib.h" -void Relais::activate(bool active) { gpio_put(gpio, !active); } +export module relais; -void Relais::on() { activate(true); } +export class Relais { + public: + Relais(uint gpio) : gpio{gpio} { + gpio_init(gpio); + gpio_set_dir(gpio, GPIO_OUT); + off(); + } -void Relais::off() { activate(false); } \ No newline at end of file + void activate(bool active) { gpio_put(gpio, !active); } + + void on() { activate(true); } + + void off() { activate(false); } + + private: + uint gpio; +}; \ No newline at end of file From 7a79ff85b58f45b0926b563b6ac11cdb308a053c Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 3 Jun 2022 14:33:42 +0200 Subject: [PATCH 02/11] change sstream to fmt --- .gitmodules | 3 +++ CMakeLists.txt | 1 + modules/fmt | 1 + src/CMakeLists.txt | 2 +- src/gbmanager.cpp | 25 +++++++++++-------------- 5 files changed, 17 insertions(+), 15 deletions(-) create mode 160000 modules/fmt diff --git a/.gitmodules b/.gitmodules index f7e01f0..7dce60a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "modules/pico-onewire"] path = modules/pico-onewire url = https://github.com/adamboardman/pico-onewire.git +[submodule "modules/fmt"] + path = modules/fmt + url = https://github.com/fmtlib/fmt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 362656f..10d1e65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,5 @@ project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM) pico_sdk_init() add_subdirectory(modules/pico-onewire) +add_subdirectory(modules/fmt) add_subdirectory(src) \ No newline at end of file diff --git a/modules/fmt b/modules/fmt new file mode 160000 index 0000000..b6f4cea --- /dev/null +++ b/modules/fmt @@ -0,0 +1 @@ +Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdddc2f..a5256dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ else() endif() # Add the standard library to the build -target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib pico_one_wire) +target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib pico_one_wire fmt::fmt-header-only) # Add any user requested libraries target_link_libraries(${CMAKE_PROJECT_NAME} diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index a932d61..f6c8445 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -1,5 +1,6 @@ -#include +#include +#include "../modules/fmt/include/fmt/format.h" #include "../modules/pico-onewire/api/one_wire.h" #include "hardware/i2c.h" #include "pico/stdlib.h" @@ -28,7 +29,7 @@ absolute_time_t lastPressed = get_absolute_time(); using std::string; -void buttonPressedCallback(uint gpio, uint32_t events) { +void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) { absolute_time_t now = get_absolute_time(); if (absolute_time_diff_us(lastPressed, now) < 750000) { return; @@ -76,14 +77,14 @@ int main() { float temp_act{0}; float temp_diff{0.5}; - std::stringstream lcdText{}; + string lcdText{}; bool isHeating = false; string heatInfo{""}; string systemInfo{""}; - lcdText << " G" << CUSTOM_CHAR_AE << "rbox Manager\n (Ver. " - << PROJECT_VERSION << ")"; - myLCD.sendString(lcdText.str()); + lcdText = fmt::format(" G{}rbox Manager\n (Ver. {})", CUSTOM_CHAR_AE, + PROJECT_VERSION); + myLCD.sendString(lcdText); sleep_ms(3000); while (true) { @@ -103,14 +104,10 @@ int main() { relais.activate(isHeating); - lcdText.str(""); - lcdText.clear(); - lcdText.precision(4); - lcdText << "ACT: " << temp_act << CUSTOM_CHAR_DEG << "C " << heatInfo - << "\n" - << "TGT: " << temp_tgt << CUSTOM_CHAR_DEG << "C " << systemInfo; - + lcdText = fmt::format("ACT: {:05.2f} {}C {}\nACT: {:05.2f} {}C {}", + temp_act, CUSTOM_CHAR_DEG, heatInfo, temp_tgt, + CUSTOM_CHAR_DEG, systemInfo); myLCD.setCursor(0, 0); - myLCD.sendString(lcdText.str()); + myLCD.sendString(lcdText); } } \ No newline at end of file From 4fbb58f1c48caefa3bc952081b423daea59f8c13 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Sun, 5 Jun 2022 18:50:17 +0200 Subject: [PATCH 03/11] typo --- src/gbmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index f6c8445..1ac44aa 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -104,7 +104,7 @@ int main() { relais.activate(isHeating); - lcdText = fmt::format("ACT: {:05.2f} {}C {}\nACT: {:05.2f} {}C {}", + lcdText = fmt::format("ACT: {:05.2f}{}C {}\nACT: {:05.2f}{}C {}", temp_act, CUSTOM_CHAR_DEG, heatInfo, temp_tgt, CUSTOM_CHAR_DEG, systemInfo); myLCD.setCursor(0, 0); From 5dc8d5e76d14fed8383e9f4187344a7a1068b85f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Sun, 5 Jun 2022 18:50:43 +0200 Subject: [PATCH 04/11] vscode stuff --- .vscode/settings.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5fbeec4..87853fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,4 +17,12 @@ "cortex-debug.openocdPath": "${env:HOME}/src/openocd/src/openocd", "cmake.generator": "Unix Makefiles", "C_Cpp.clang_format_fallbackStyle": "LLVM", + "files.watcherExclude": { + "**/.git/objects/**": true, + "**/.git/subtree-cache/**": true, + "**/node_modules/*/**": true, + "**/.hg/store/**": true, + ".flatpak/**": true, + "_build/**": true + }, } From 7b56534fee00ad4c4936b1eefd2a310b6ea8d8ef Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 12:23:05 +0100 Subject: [PATCH 05/11] get it running in new dev environment --- .vscode/launch.json | 20 +++++++++----------- .vscode/settings.json | 2 -- CMakeLists.txt | 5 +++-- modules/pico-onewire | 2 +- src/CMakeLists.txt | 4 ++-- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c32afb1..aa54d5c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,4 +1,4 @@ -{ + { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 @@ -11,21 +11,19 @@ "request": "launch", "type": "cortex-debug", "servertype": "openocd", - "gdbPath" : "arm-none-eabi-gdb", + "gdbPath": "gdb-multiarch", "device": "RP2040", - //"showDevDebugOutput": "parsed", "configFiles": [ - "interface/picoprobe.cfg", + "interface/raspberrypi-swd.cfg", "target/rp2040.cfg" ], "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", "runToEntryPoint": "main", - // Give restart the same functionality as runToMain - //"postRestartCommands": [ - // "break main", - // "continue" - //], - "searchDir": ["${env:HOME}/src/openocd/tcl"], + // Give restart the same functionality as runToEntryPoint - main + "postRestartCommands": [ + "break main", + "continue" + ] } ] -} +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 87853fc..960b66b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,8 +14,6 @@ "visibility": "hidden" }, }, - "cortex-debug.openocdPath": "${env:HOME}/src/openocd/src/openocd", - "cmake.generator": "Unix Makefiles", "C_Cpp.clang_format_fallbackStyle": "LLVM", "files.watcherExclude": { "**/.git/objects/**": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index 10d1e65..576033b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,12 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-volatile") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-exceptions") # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) -set(PICO_SDK_PATH "/usr/share/pico-sdk") +#set(PICO_SDK_PATH "/usr/share/pico-sdk") +set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) include("cmake/pico_sdk_import.cmake") diff --git a/modules/pico-onewire b/modules/pico-onewire index d5af2a1..6399467 160000 --- a/modules/pico-onewire +++ b/modules/pico-onewire @@ -1 +1 @@ -Subproject commit d5af2a1e1d81c3cb21805e332c8185607ee74b1d +Subproject commit 6399467cf7687ecb7f8f4e4923303349e0ecf160 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5256dc..b9408f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,8 +14,8 @@ pico_set_program_name(${CMAKE_PROJECT_NAME} "gbmanager") pico_set_program_version(${CMAKE_PROJECT_NAME} ${PROJECT_VERSION}) if(CMAKE_BUILD_TYPE STREQUAL "Debug") - pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 1) - pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) + pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0) + pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 1) else() pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0) pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) From 0bbb794346b11acc3722c41f68312fba5368017f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 12:29:33 +0100 Subject: [PATCH 06/11] Disable on/off button temporarily fixes #1 --- src/gbmanager.cpp | 10 ++++++++-- src/relais.cpp | 18 ++++++++++++++++-- src/relais.h | 6 +++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index 1ac44aa..3b3cfdc 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -31,7 +31,7 @@ using std::string; void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) { absolute_time_t now = get_absolute_time(); - if (absolute_time_diff_us(lastPressed, now) < 750000) { + if (absolute_time_diff_us(lastPressed, now) < 500000) { return; } else { lastPressed = now; @@ -65,7 +65,9 @@ int main() { oneWire.single_device_read_rom(address); // Initialize the relais - Relais relais(RELAIS_PIN); + // It need the button callback function, since it has to disable the on/off + // button for a short amount of time + Relais relais(RELAIS_PIN, &buttonPressedCallback); // Initialize the Buttons gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true, @@ -88,6 +90,8 @@ int main() { sleep_ms(3000); while (true) { + uint64_t destTime = time_us_64() + 1000000; + oneWire.convert_temperature(address, true, false); temp_act = oneWire.temperature(address); @@ -109,5 +113,7 @@ int main() { CUSTOM_CHAR_DEG, systemInfo); myLCD.setCursor(0, 0); myLCD.sendString(lcdText); + + sleep_until((absolute_time_t){destTime}); } } \ No newline at end of file diff --git a/src/relais.cpp b/src/relais.cpp index 6742c33..9144eb2 100644 --- a/src/relais.cpp +++ b/src/relais.cpp @@ -1,12 +1,26 @@ #include "relais.h" -Relais::Relais(uint gpio) : gpio{gpio} { +Relais::Relais(uint gpio, gpio_irq_callback_t callback) + : gpio{gpio}, callback{callback} { gpio_init(gpio); gpio_set_dir(gpio, GPIO_OUT); off(); } -void Relais::activate(bool active) { gpio_put(gpio, !active); } +void Relais::activate(bool active) { + if (active == lastState) { + return; + } + + lastState = active; + + gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, false, + callback); + gpio_put(gpio, !active); + sleep_ms(100); + gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true, + callback); +} void Relais::on() { activate(true); } diff --git a/src/relais.h b/src/relais.h index fcc357e..1a13cbb 100644 --- a/src/relais.h +++ b/src/relais.h @@ -4,15 +4,19 @@ #include "hardware/gpio.h" #include "pico/stdlib.h" +extern const uint BUTTON_3_PIN; // declared in gbmanager.cpp + class Relais { public: - Relais(uint gpio); + Relais(uint gpio, gpio_irq_callback_t callback); void activate(bool active); void on(); void off(); private: uint gpio; + bool lastState; + gpio_irq_callback_t callback; }; #endif \ No newline at end of file From d4278d609844a8a2494bc0e83417d0478e6c88bf Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 12:30:11 +0100 Subject: [PATCH 07/11] increase version number --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 576033b..7aa6592 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) include("cmake/pico_sdk_import.cmake") -project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM) +project(gbmanager VERSION "1.0.1" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() From f19a5bab0d467c06f0427699a6fb797d6cdddc17 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 13:17:36 +0100 Subject: [PATCH 08/11] Better use C++17 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7aa6592..9caaa9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-exceptions") From 1e70cbb13d5de60e4dd141a9493bf662645aaead Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 13:29:10 +0100 Subject: [PATCH 09/11] fixes #2 --- CMakeLists.txt | 4 ++-- src/gbmanager.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9caaa9d..cc6ca64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,11 +13,11 @@ set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) include("cmake/pico_sdk_import.cmake") -project(gbmanager VERSION "1.0.1" LANGUAGES C CXX ASM) +project(gbmanager VERSION "1.0.2" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() add_subdirectory(modules/pico-onewire) add_subdirectory(modules/fmt) -add_subdirectory(src) \ No newline at end of file +add_subdirectory(src) diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index 3b3cfdc..19290e9 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -108,7 +108,7 @@ int main() { relais.activate(isHeating); - lcdText = fmt::format("ACT: {:05.2f}{}C {}\nACT: {:05.2f}{}C {}", + lcdText = fmt::format("ACT: {:05.2f}{}C {}\nTGT: {:05.2f}{}C {}", temp_act, CUSTOM_CHAR_DEG, heatInfo, temp_tgt, CUSTOM_CHAR_DEG, systemInfo); myLCD.setCursor(0, 0); @@ -116,4 +116,4 @@ int main() { sleep_until((absolute_time_t){destTime}); } -} \ No newline at end of file +} From 98cf010c4b166dfbff07d9a0b83240dc8a68a3bc Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Dec 2022 20:14:51 +0100 Subject: [PATCH 10/11] Also disable the other buttons temporarily. --- CMakeLists.txt | 6 +++--- src/relais.cpp | 10 +++++++++- src/relais.h | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc6ca64..29520c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-exceptions") # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) -#set(PICO_SDK_PATH "/usr/share/pico-sdk") -set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") +set(PICO_SDK_PATH "/usr/share/pico-sdk") +#set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) include("cmake/pico_sdk_import.cmake") -project(gbmanager VERSION "1.0.2" LANGUAGES C CXX ASM) +project(gbmanager VERSION "1.0.3" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() diff --git a/src/relais.cpp b/src/relais.cpp index 9144eb2..980b8f4 100644 --- a/src/relais.cpp +++ b/src/relais.cpp @@ -14,14 +14,22 @@ void Relais::activate(bool active) { lastState = active; + gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, false, + callback); + gpio_set_irq_enabled_with_callback(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, false, + callback); gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, false, callback); gpio_put(gpio, !active); sleep_ms(100); + gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true, + callback); + gpio_set_irq_enabled_with_callback(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, true, + callback); gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true, callback); } void Relais::on() { activate(true); } -void Relais::off() { activate(false); } \ No newline at end of file +void Relais::off() { activate(false); } diff --git a/src/relais.h b/src/relais.h index 1a13cbb..d8d4f9e 100644 --- a/src/relais.h +++ b/src/relais.h @@ -4,6 +4,8 @@ #include "hardware/gpio.h" #include "pico/stdlib.h" +extern const uint BUTTON_1_PIN; // declared in gbmanager.cpp +extern const uint BUTTON_2_PIN; // declared in gbmanager.cpp extern const uint BUTTON_3_PIN; // declared in gbmanager.cpp class Relais { @@ -19,4 +21,4 @@ class Relais { gpio_irq_callback_t callback; }; -#endif \ No newline at end of file +#endif From 819cc610321bafe52f11031a69516ed8582677f6 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 13 Aug 2024 15:07:59 +0200 Subject: [PATCH 11/11] remove explicit SDK path --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29520c3..ee8ec1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-exceptions") # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) -set(PICO_SDK_PATH "/usr/share/pico-sdk") -#set(PICO_SDK_PATH "/home/martin/pico/pico-sdk") +#set(PICO_SDK_PATH "/usr/share/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) include("cmake/pico_sdk_import.cmake")