gbmanager/gbmanager.cpp

80 lines
2 KiB
C++
Raw Normal View History

2022-05-31 12:31:29 +02:00
#include <iomanip>
2022-05-30 14:10:48 +02:00
#include <iostream>
2022-05-31 12:31:29 +02:00
#include <sstream>
2022-05-30 14:10:48 +02:00
2022-05-30 16:09:42 +02:00
#include "hardware/i2c.h"
2022-05-30 14:10:48 +02:00
#include "pico/stdlib.h"
2022-05-31 13:01:10 +02:00
#include "config.h"
2022-05-31 09:47:29 +02:00
#include "ds18b20.h"
2022-05-31 12:31:29 +02:00
#include "lcd.h"
2022-05-31 13:53:19 +02:00
#include "relais.h"
2022-05-30 16:09:42 +02:00
2022-05-31 13:53:19 +02:00
// GPIOs used
2022-05-30 16:09:42 +02:00
constexpr uint I2C_SDA_PIN = 26;
constexpr uint I2C_SCL_PIN = 27;
2022-05-31 12:31:29 +02:00
constexpr uint DS18B20_PIN = 28;
2022-05-31 13:53:19 +02:00
constexpr uint RELAIS_PIN = 18;
2022-05-31 12:31:29 +02:00
2022-05-31 13:53:19 +02:00
// Custom chars for the LCD
2022-05-31 12:31:29 +02:00
constexpr char CUSTOM_CHAR_DEG = 0xDF;
constexpr char CUSTOM_CHAR_AE = 0xE1;
using std::string;
2022-05-30 16:09:42 +02:00
int main() {
2022-05-31 12:31:29 +02:00
// Enable UART so we can print status output
stdio_init_all();
2022-05-31 13:53:19 +02:00
// Initialize the LCD
2022-05-31 12:31:29 +02:00
auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN);
myLCD.clear();
2022-05-31 13:53:19 +02:00
// Initialize the temp sensor
2022-05-31 12:31:29 +02:00
// DS18B20 ds = DS18B20(pio0, DS18B20_PIN);
2022-05-31 13:53:19 +02:00
// Initialize the relais
Relais relais(RELAIS_PIN);
2022-05-31 12:31:29 +02:00
float temp_act{0};
float temp_tgt{28.0};
2022-05-31 13:01:10 +02:00
float temp_diff{0.5};
2022-05-31 12:31:29 +02:00
std::stringstream lcdText{};
bool isHeating = false;
2022-05-31 13:01:10 +02:00
bool isSystemOn = false;
2022-05-31 12:31:29 +02:00
string heatInfo{" "};
string systemInfo{"OFF"};
2022-05-31 13:01:10 +02:00
lcdText << " G" << CUSTOM_CHAR_AE << "rbox Manager\n (Ver. "
<< PROJECT_VERSION << ")";
myLCD.sendString(lcdText.str());
sleep_ms(3000);
2022-05-31 12:31:29 +02:00
while (true) {
// ds.convert();
sleep_ms(750);
// temp_act = ds.getTemperature();
temp_act = 23.5;
2022-05-30 14:10:48 +02:00
2022-05-31 13:01:10 +02:00
if (isSystemOn && temp_act < temp_tgt - temp_diff) {
isHeating = true;
} else if (isSystemOn && temp_act > temp_tgt + temp_diff) {
isHeating = false;
} else if (!isSystemOn) {
isHeating = false;
}
isHeating ? heatInfo = ">H<" : heatInfo = " ";
2022-05-31 13:53:19 +02:00
relais.activate(isHeating);
2022-05-31 12:31:29 +02:00
lcdText.str("");
lcdText.clear();
lcdText.precision(4);
2022-05-31 13:01:10 +02:00
lcdText << "ACT: " << temp_act << CUSTOM_CHAR_DEG << "C " << heatInfo
<< "\n"
2022-05-31 12:31:29 +02:00
<< "TGT: " << temp_tgt << CUSTOM_CHAR_DEG << "C " << systemInfo;
2022-05-30 16:09:42 +02:00
2022-05-31 12:31:29 +02:00
myLCD.setCursor(0, 0);
myLCD.sendString(lcdText.str());
}
2022-05-30 14:10:48 +02:00
}