Compare commits
14 Commits
Author | SHA1 | Date |
---|---|---|
Martin Brodbeck | 98cf010c4b | |
Martin Brodbeck | 1e70cbb13d | |
Martin Brodbeck | f19a5bab0d | |
Martin Brodbeck | d4278d6098 | |
Martin Brodbeck | 0bbb794346 | |
Martin Brodbeck | 7b56534fee | |
Martin Brodbeck | 5dc8d5e76d | |
Martin Brodbeck | 4fbb58f1c4 | |
Martin Brodbeck | 7a79ff85b5 | |
Martin Brodbeck | c56c52e458 | |
Martin Brodbeck | 679ccd95a3 | |
Martin Brodbeck | f012fbff77 | |
Martin Brodbeck | 80fb3c8cb5 | |
Martin Brodbeck | 7f6873284c |
|
@ -1,3 +1,6 @@
|
||||||
[submodule "modules/pico-onewire"]
|
[submodule "modules/pico-onewire"]
|
||||||
path = modules/pico-onewire
|
path = modules/pico-onewire
|
||||||
url = https://github.com/adamboardman/pico-onewire.git
|
url = https://github.com/adamboardman/pico-onewire.git
|
||||||
|
[submodule "modules/fmt"]
|
||||||
|
path = modules/fmt
|
||||||
|
url = https://github.com/fmtlib/fmt.git
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Hover to view descriptions of existing attributes.
|
// Hover to view descriptions of existing attributes.
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
@ -11,21 +11,19 @@
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cortex-debug",
|
"type": "cortex-debug",
|
||||||
"servertype": "openocd",
|
"servertype": "openocd",
|
||||||
"gdbPath" : "arm-none-eabi-gdb",
|
"gdbPath": "gdb-multiarch",
|
||||||
"device": "RP2040",
|
"device": "RP2040",
|
||||||
//"showDevDebugOutput": "parsed",
|
|
||||||
"configFiles": [
|
"configFiles": [
|
||||||
"interface/picoprobe.cfg",
|
"interface/raspberrypi-swd.cfg",
|
||||||
"target/rp2040.cfg"
|
"target/rp2040.cfg"
|
||||||
],
|
],
|
||||||
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
||||||
"runToEntryPoint": "main",
|
"runToEntryPoint": "main",
|
||||||
// Give restart the same functionality as runToMain
|
// Give restart the same functionality as runToEntryPoint - main
|
||||||
//"postRestartCommands": [
|
"postRestartCommands": [
|
||||||
// "break main",
|
"break main",
|
||||||
// "continue"
|
"continue"
|
||||||
//],
|
]
|
||||||
"searchDir": ["${env:HOME}/src/openocd/tcl"],
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -14,7 +14,13 @@
|
||||||
"visibility": "hidden"
|
"visibility": "hidden"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"cortex-debug.openocdPath": "${env:HOME}/src/openocd/src/openocd",
|
|
||||||
"cmake.generator": "Unix Makefiles",
|
|
||||||
"C_Cpp.clang_format_fallbackStyle": "LLVM",
|
"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
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-volatile")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-exceptions")
|
||||||
|
|
||||||
# Initialise pico_sdk from installed location
|
# Initialise pico_sdk from installed location
|
||||||
# (note this can come from environment, CMake cache etc)
|
# (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)
|
# Pull in Raspberry Pi Pico SDK (must be before project)
|
||||||
include("cmake/pico_sdk_import.cmake")
|
include("cmake/pico_sdk_import.cmake")
|
||||||
|
|
||||||
project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM)
|
project(gbmanager VERSION "1.0.3" LANGUAGES C CXX ASM)
|
||||||
|
|
||||||
|
|
||||||
# Initialise the Raspberry Pi Pico SDK
|
# Initialise the Raspberry Pi Pico SDK
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
add_subdirectory(modules/pico-onewire)
|
add_subdirectory(modules/pico-onewire)
|
||||||
add_subdirectory(src)
|
add_subdirectory(modules/fmt)
|
||||||
|
add_subdirectory(src)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9
|
|
@ -1 +1 @@
|
||||||
Subproject commit d5af2a1e1d81c3cb21805e332c8185607ee74b1d
|
Subproject commit 6399467cf7687ecb7f8f4e4923303349e0ecf160
|
|
@ -1,4 +1,5 @@
|
||||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${PROJECT_BINARY_DIR}/src/config.h)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
gbmanager.cpp
|
gbmanager.cpp
|
||||||
|
@ -13,17 +14,15 @@ pico_set_program_name(${CMAKE_PROJECT_NAME} "gbmanager")
|
||||||
pico_set_program_version(${CMAKE_PROJECT_NAME} ${PROJECT_VERSION})
|
pico_set_program_version(${CMAKE_PROJECT_NAME} ${PROJECT_VERSION})
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 1)
|
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0)
|
||||||
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0)
|
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 1)
|
||||||
else()
|
else()
|
||||||
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0)
|
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0)
|
||||||
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0)
|
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
pico_generate_pio_header(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/ds18b20.pio)
|
|
||||||
|
|
||||||
# Add the standard library to the build
|
# 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
|
# Add any user requested libraries
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <iomanip>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
#include "../modules/fmt/include/fmt/format.h"
|
||||||
#include "../modules/pico-onewire/api/one_wire.h"
|
#include "../modules/pico-onewire/api/one_wire.h"
|
||||||
#include "hardware/i2c.h"
|
#include "hardware/i2c.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
@ -30,11 +29,12 @@ absolute_time_t lastPressed = get_absolute_time();
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
void buttonPressedCallback(uint gpio, uint32_t events) {
|
void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) {
|
||||||
if (absolute_time_diff_us(lastPressed, get_absolute_time()) < 750000) {
|
absolute_time_t now = get_absolute_time();
|
||||||
|
if (absolute_time_diff_us(lastPressed, now) < 500000) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
lastPressed = get_absolute_time();
|
lastPressed = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (gpio) {
|
switch (gpio) {
|
||||||
|
@ -65,7 +65,9 @@ int main() {
|
||||||
oneWire.single_device_read_rom(address);
|
oneWire.single_device_read_rom(address);
|
||||||
|
|
||||||
// Initialize the relais
|
// 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
|
// Initialize the Buttons
|
||||||
gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true,
|
gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true,
|
||||||
|
@ -77,18 +79,19 @@ int main() {
|
||||||
|
|
||||||
float temp_act{0};
|
float temp_act{0};
|
||||||
float temp_diff{0.5};
|
float temp_diff{0.5};
|
||||||
std::stringstream lcdText{};
|
string lcdText{};
|
||||||
bool isHeating = false;
|
bool isHeating = false;
|
||||||
string heatInfo{""};
|
string heatInfo{""};
|
||||||
string systemInfo{""};
|
string systemInfo{""};
|
||||||
|
|
||||||
lcdText << " G" << CUSTOM_CHAR_AE << "rbox Manager\n (Ver. "
|
lcdText = fmt::format(" G{}rbox Manager\n (Ver. {})", CUSTOM_CHAR_AE,
|
||||||
<< PROJECT_VERSION << ")";
|
PROJECT_VERSION);
|
||||||
myLCD.sendString(lcdText.str());
|
myLCD.sendString(lcdText);
|
||||||
sleep_ms(3000);
|
sleep_ms(3000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
absolute_time_t start = get_absolute_time();
|
uint64_t destTime = time_us_64() + 1000000;
|
||||||
|
|
||||||
oneWire.convert_temperature(address, true, false);
|
oneWire.convert_temperature(address, true, false);
|
||||||
temp_act = oneWire.temperature(address);
|
temp_act = oneWire.temperature(address);
|
||||||
|
|
||||||
|
@ -99,27 +102,18 @@ int main() {
|
||||||
} else if (!isSystemOn) {
|
} else if (!isSystemOn) {
|
||||||
isHeating = false;
|
isHeating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isHeating ? heatInfo = ">H<" : heatInfo = " ";
|
isHeating ? heatInfo = ">H<" : heatInfo = " ";
|
||||||
isSystemOn ? systemInfo = "ON " : systemInfo = "OFF";
|
isSystemOn ? systemInfo = "ON " : systemInfo = "OFF";
|
||||||
|
|
||||||
relais.activate(isHeating);
|
relais.activate(isHeating);
|
||||||
|
|
||||||
lcdText.str("");
|
lcdText = fmt::format("ACT: {:05.2f}{}C {}\nTGT: {:05.2f}{}C {}",
|
||||||
lcdText.clear();
|
temp_act, CUSTOM_CHAR_DEG, heatInfo, temp_tgt,
|
||||||
lcdText.precision(4);
|
CUSTOM_CHAR_DEG, systemInfo);
|
||||||
lcdText << "ACT: " << temp_act << CUSTOM_CHAR_DEG << "C " << heatInfo
|
|
||||||
<< "\n"
|
|
||||||
<< "TGT: " << temp_tgt << CUSTOM_CHAR_DEG << "C " << systemInfo;
|
|
||||||
|
|
||||||
myLCD.setCursor(0, 0);
|
myLCD.setCursor(0, 0);
|
||||||
myLCD.sendString(lcdText.str());
|
myLCD.sendString(lcdText);
|
||||||
|
|
||||||
absolute_time_t stop = get_absolute_time();
|
sleep_until((absolute_time_t){destTime});
|
||||||
|
|
||||||
int64_t duration_ms = absolute_time_diff_us(start, stop) / 1000;
|
|
||||||
int64_t timeToSleep = 1000 - duration_ms;
|
|
||||||
|
|
||||||
if (timeToSleep > 0)
|
|
||||||
sleep_ms(timeToSleep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include "pico/binary_info.h"
|
||||||
|
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
|
@ -30,11 +32,13 @@ constexpr int LCD_ENABLE_BIT = 0x04;
|
||||||
LCD::LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl,
|
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)
|
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{i2c}, i2c_addr{i2c_addr}, num_cols{num_cols}, num_lines{num_lines} {
|
||||||
i2c_init(i2c1, 100 * 1000);
|
i2c_init(i2c, 400 * 1000);
|
||||||
gpio_set_function(gpio_sda, GPIO_FUNC_I2C);
|
gpio_set_function(gpio_sda, GPIO_FUNC_I2C);
|
||||||
gpio_set_function(gpio_scl, GPIO_FUNC_I2C);
|
gpio_set_function(gpio_scl, GPIO_FUNC_I2C);
|
||||||
gpio_pull_up(gpio_sda);
|
gpio_pull_up(gpio_sda);
|
||||||
gpio_pull_up(gpio_scl);
|
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(0x03, Mode::COMMAND);
|
sendByte(0x03, Mode::COMMAND);
|
||||||
sendByte(0x03, Mode::COMMAND);
|
sendByte(0x03, Mode::COMMAND);
|
||||||
|
|
|
@ -1,13 +1,35 @@
|
||||||
#include "relais.h"
|
#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_init(gpio);
|
||||||
gpio_set_dir(gpio, GPIO_OUT);
|
gpio_set_dir(gpio, GPIO_OUT);
|
||||||
off();
|
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_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::on() { activate(true); }
|
||||||
|
|
||||||
void Relais::off() { activate(false); }
|
void Relais::off() { activate(false); }
|
||||||
|
|
10
src/relais.h
10
src/relais.h
|
@ -4,15 +4,21 @@
|
||||||
#include "hardware/gpio.h"
|
#include "hardware/gpio.h"
|
||||||
#include "pico/stdlib.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 {
|
class Relais {
|
||||||
public:
|
public:
|
||||||
Relais(uint gpio);
|
Relais(uint gpio, gpio_irq_callback_t callback);
|
||||||
void activate(bool active);
|
void activate(bool active);
|
||||||
void on();
|
void on();
|
||||||
void off();
|
void off();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint gpio;
|
uint gpio;
|
||||||
|
bool lastState;
|
||||||
|
gpio_irq_callback_t callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue