Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
819cc61032 | |||
98cf010c4b | |||
1e70cbb13d | |||
f19a5bab0d | |||
d4278d6098 | |||
0bbb794346 | |||
7b56534fee | |||
5dc8d5e76d | |||
4fbb58f1c4 | |||
7a79ff85b5 |
11 changed files with 151 additions and 148 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||
|
|
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
|
@ -14,7 +14,13 @@
|
|||
"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,
|
||||
"**/.git/subtree-cache/**": true,
|
||||
"**/node_modules/*/**": true,
|
||||
"**/.hg/store/**": true,
|
||||
".flatpak/**": true,
|
||||
"_build/**": true
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
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 -Wno-volatile -fmodules-ts")
|
||||
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")
|
||||
|
||||
# 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.3" 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)
|
1
modules/fmt
Submodule
1
modules/fmt
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9
|
|
@ -1 +1 @@
|
|||
Subproject commit d5af2a1e1d81c3cb21805e332c8185607ee74b1d
|
||||
Subproject commit 6399467cf7687ecb7f8f4e4923303349e0ecf160
|
|
@ -1,12 +1,10 @@
|
|||
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
|
||||
|
@ -16,15 +14,15 @@ 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)
|
||||
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}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "../modules/fmt/include/fmt/format.h"
|
||||
#include "../modules/pico-onewire/api/one_wire.h"
|
||||
#include "hardware/i2c.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "config.h"
|
||||
//#include "lcd.h"
|
||||
|
||||
import lcd;
|
||||
import relais;
|
||||
#include "lcd.h"
|
||||
#include "relais.h"
|
||||
|
||||
// GPIOs used
|
||||
constexpr uint I2C_SDA_PIN = 26;
|
||||
|
@ -32,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;
|
||||
|
@ -56,7 +55,7 @@ int main() {
|
|||
stdio_init_all();
|
||||
|
||||
// Initialize the LCD
|
||||
auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN, 16, 2);
|
||||
auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN);
|
||||
myLCD.clear();
|
||||
|
||||
// Initialize the temp sensor
|
||||
|
@ -66,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,
|
||||
|
@ -78,17 +79,19 @@ 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) {
|
||||
uint64_t destTime = time_us_64() + 1000000;
|
||||
|
||||
oneWire.convert_temperature(address, true, false);
|
||||
temp_act = oneWire.temperature(address);
|
||||
|
||||
|
@ -105,14 +108,12 @@ 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 {}\nTGT: {: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);
|
||||
|
||||
sleep_until((absolute_time_t){destTime});
|
||||
}
|
||||
}
|
62
src/lcd.cpp
62
src/lcd.cpp
|
@ -1,12 +1,6 @@
|
|||
module;
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hardware/i2c.h"
|
||||
#include "pico/binary_info.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
export module lcd;
|
||||
#include "lcd.h"
|
||||
|
||||
// commands
|
||||
constexpr int LCD_CLEARDISPLAY = 0x01;
|
||||
|
@ -35,15 +29,9 @@ constexpr int LCD_8BITMODE = 0x10;
|
|||
constexpr int LCD_BACKLIGHT = 0x08;
|
||||
constexpr int LCD_ENABLE_BIT = 0x04;
|
||||
|
||||
enum class Mode { COMMAND, CHARACTER };
|
||||
|
||||
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} {
|
||||
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);
|
||||
|
@ -63,7 +51,17 @@ export class LCD {
|
|||
clear();
|
||||
}
|
||||
|
||||
void sendString(const std::string &str) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
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++;
|
||||
|
@ -75,24 +73,13 @@ export class LCD {
|
|||
}
|
||||
}
|
||||
|
||||
// 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::clear() { sendByte(LCD_CLEARDISPLAY, Mode::COMMAND); }
|
||||
|
||||
void clear() { sendByte(LCD_CLEARDISPLAY, Mode::COMMAND); }
|
||||
|
||||
private:
|
||||
void sendChar(char val) { sendByte(val, Mode::CHARACTER); }
|
||||
|
||||
void i2cWriteByte(uint8_t val) {
|
||||
void LCD::i2cWriteByte(uint8_t val) {
|
||||
i2c_write_blocking(i2c, i2c_addr, &val, 1, false);
|
||||
}
|
||||
|
||||
void toggleEnable(uint8_t val) {
|
||||
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;
|
||||
|
@ -104,21 +91,12 @@ export class LCD {
|
|||
}
|
||||
|
||||
// The display is sent a byte as two separate nibble transfers
|
||||
void sendByte(uint8_t val, Mode mode) {
|
||||
void LCD::sendByte(uint8_t val, Mode mode) {
|
||||
uint8_t high = static_cast<int>(mode) | (val & 0xF0) | LCD_BACKLIGHT;
|
||||
uint8_t low =
|
||||
static_cast<int>(mode) | ((val << 4) & 0xF0) | LCD_BACKLIGHT;
|
||||
uint8_t low = static_cast<int>(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};
|
||||
};
|
|
@ -1,24 +1,35 @@
|
|||
module;
|
||||
#include "relais.h"
|
||||
|
||||
#include "hardware/gpio.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
export module relais;
|
||||
|
||||
export class Relais {
|
||||
public:
|
||||
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 activate(bool active) { gpio_put(gpio, !active); }
|
||||
void Relais::activate(bool active) {
|
||||
if (active == lastState) {
|
||||
return;
|
||||
}
|
||||
|
||||
void on() { activate(true); }
|
||||
lastState = active;
|
||||
|
||||
void off() { activate(false); }
|
||||
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);
|
||||
}
|
||||
|
||||
private:
|
||||
uint gpio;
|
||||
};
|
||||
void Relais::on() { activate(true); }
|
||||
|
||||
void Relais::off() { activate(false); }
|
||||
|
|
|
@ -4,15 +4,21 @@
|
|||
#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 {
|
||||
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
|
Loading…
Reference in a new issue