|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#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"
|
|
|
|
@ -30,11 +29,12 @@ absolute_time_t lastPressed = get_absolute_time();
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
void buttonPressedCallback(uint gpio, uint32_t events) {
|
|
|
|
|
if (absolute_time_diff_us(lastPressed, get_absolute_time()) < 750000) {
|
|
|
|
|
void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) {
|
|
|
|
|
absolute_time_t now = get_absolute_time();
|
|
|
|
|
if (absolute_time_diff_us(lastPressed, now) < 500000) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
lastPressed = get_absolute_time();
|
|
|
|
|
lastPressed = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (gpio) {
|
|
|
|
@ -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,
|
|
|
|
@ -77,18 +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) {
|
|
|
|
|
absolute_time_t start = get_absolute_time();
|
|
|
|
|
uint64_t destTime = time_us_64() + 1000000;
|
|
|
|
|
|
|
|
|
|
oneWire.convert_temperature(address, true, false);
|
|
|
|
|
temp_act = oneWire.temperature(address);
|
|
|
|
|
|
|
|
|
@ -99,27 +102,18 @@ int main() {
|
|
|
|
|
} else if (!isSystemOn) {
|
|
|
|
|
isHeating = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isHeating ? heatInfo = ">H<" : heatInfo = " ";
|
|
|
|
|
isSystemOn ? systemInfo = "ON " : systemInfo = "OFF";
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
absolute_time_t stop = get_absolute_time();
|
|
|
|
|
|
|
|
|
|
int64_t duration_ms = absolute_time_diff_us(start, stop) / 1000;
|
|
|
|
|
int64_t timeToSleep = 1000 - duration_ms;
|
|
|
|
|
|
|
|
|
|
if (timeToSleep > 0)
|
|
|
|
|
sleep_ms(timeToSleep);
|
|
|
|
|
sleep_until((absolute_time_t){destTime});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|