Engine temp warning messages and bug fixes

This commit is contained in:
2026-03-30 16:29:16 +02:00
parent 3b2abd3f71
commit da6b23d78e
9 changed files with 126 additions and 29 deletions

View File

@@ -31,6 +31,8 @@ enum Type : uint8_t {
DisplayMsgTrackDetectOk,
DisplayMsgConfigNoTracks,
DisplayMsgBatteryLow,
DisplayMsgEngineTempLow,
DisplayMsgEngineTempHigh,
ConfigTrackDetect,
ConfigWriteTempTrack,
ConfigTrackDelete,

View File

@@ -15,9 +15,9 @@
}
void tengGlobalRead(double& out) {
out = vbat_global;
out = teng_global;
}
void tengGlobalWrite(const double& in) {
vbat_global = in;
teng_global = in;
}

View File

@@ -14,6 +14,7 @@
#include "base/module_base.h"
#include "base/router.h"
#include "modules/battery/battery.h"
#include "modules/thermocouple/thermocouple.h"
SystemLogger *logger = new SystemLogger(&Serial);
@@ -23,6 +24,8 @@ Gps *gps_module = new Gps(&Serial2, logger);
Config *system_config = new Config(logger);
Cmd *command_handler = new Cmd(&Serial, logger);
Battery *battery_module = new Battery(logger);
Thermocouple *thermocouple_module = new Thermocouple(logger);
void setup() {
@@ -33,6 +36,7 @@ void setup() {
module_registry[module::Config] = system_config;
module_registry[module::Cmd] = command_handler;
module_registry[module::Battery] = battery_module;
module_registry[module::Thermocouple] = thermocouple_module;
display->init();
display->printMessage("Starting Initialization");
@@ -62,6 +66,7 @@ void setup() {
display->printMessage("Sensors Init...");
battery_module->init();
thermocouple_module->init();
delay(1000);
display->printMessage("Sensors Init Complete");
delay(1000);
@@ -74,4 +79,5 @@ void loop() {
command_handler->parseTask();
system_config->loop();
battery_module->loop();
thermocouple_module->loop();
}

View File

@@ -44,10 +44,11 @@ int Battery::loop(unsigned long timeout_ms) {
vbatGlobalWrite(vbat_);
if (vbat_ < low_threshold_) {
if (warning_sent_at_ == 0 || millis() > warning_sent_at_ + warning_timeout_) {
router::send(module::Lcd, task::DisplayMsgBatteryLow, 2000);
warning_sent_at_ = millis();
}
if (warning_sent_at_ == 0 ||
millis() > warning_sent_at_ + warning_timeout_) {
router::send(module::Lcd, task::DisplayMsgBatteryLow, 2000);
warning_sent_at_ = millis();
}
}
last_read_at_ = millis();
}
@@ -66,19 +67,18 @@ int Battery::loop(unsigned long timeout_ms) {
break;
}
} else if (active_task.target_ == module::All) {
switch (active_task.type_)
{
case task::AllConfigUpdated: {
VehicleConfig config;
configGlobalRead(config);
calibration_ = config.vbat_calibration_;
low_threshold_ = config.vbat_low_;
break;
}
switch (active_task.type_) {
case task::AllConfigUpdated: {
VehicleConfig config;
configGlobalRead(config);
calibration_ = config.vbat_calibration_;
low_threshold_ = config.vbat_low_;
break;
}
default:
break;
}
default:
break;
}
}
}
return 0;

View File

@@ -483,7 +483,7 @@ int Cmd::handleThermoSetHigh(unsigned short argc, char* argv[]) {
logger_->info("Setting high level for TENG");
}
#endif
router::send(module::Config, task::ConfigTengSetLow, task_data);
router::send(module::Config, task::ConfigTengSetHigh, task_data);
return 0;
}

View File

@@ -62,6 +62,8 @@ bool Lcd::isMessageTask(task::Type type) {
case task::DisplayMsgTrackDetectOk:
case task::DisplayMsgConfigNoTracks:
case task::DisplayMsgBatteryLow:
case task::DisplayMsgEngineTempLow:
case task::DisplayMsgEngineTempHigh:
return true;
default:
@@ -151,6 +153,8 @@ int Lcd::renderDriverPrimary() {
double vbat;
vbatGlobalRead(vbat);
double teng;
tengGlobalRead(teng);
display_->setCursor(0,0);
this->print("GPS:");
@@ -165,9 +169,13 @@ int Lcd::renderDriverPrimary() {
this->print(gps_data.speed_.value_);
display_->setCursor(0,3);
this->print("VBAT:");
this->print("Vbat:");
this->print(vbat);
display_->setCursor(10,3);
this->print("Teng:");
this->print(teng);
return 0;
}
@@ -206,13 +214,31 @@ int Lcd::renderMsgConfigNoTracks() {
int Lcd::renderMsgBatteryLow() {
this->clear();
display_->setCursor(2, 1);
this->print("BATTERY WARNING");
display_->setCursor(6, 1);
this->print("WARNING");
display_->setCursor(6, 2);
this->print("VBAT LOW");
return 0;
}
int Lcd::renderMsgEngineTempLow() {
this->clear();
display_->setCursor(6, 1);
this->print("WARNING");
display_->setCursor(2, 2);
this->print("ENGINE TEMP LOW");
return 0;
}
int Lcd::renderMsgEngineTempHigh() {
this->clear();
display_->setCursor(6, 1);
this->print("WARNING");
display_->setCursor(2, 2);
this->print("ENGINE TEMP HIGH");
return 0;
}
int Lcd::push(const Task &task) {
return queue_.push(task);
}
@@ -414,6 +440,13 @@ int Lcd::loop(unsigned long timeout_ms) {
activateMessage(screen::MsgBatteryLow, next_task.data_);
break;
case task::DisplayMsgEngineTempLow:
activateMessage(screen::MsgEngineTempLow, next_task.data_);
break;
case task::DisplayMsgEngineTempHigh:
activateMessage(screen::MsgEngineTempLow, next_task.data_);
default:
break;
}
@@ -468,6 +501,14 @@ int Lcd::loop(unsigned long timeout_ms) {
this->renderMsgBatteryLow();
break;
case screen::MsgEngineTempLow:
this->renderMsgEngineTempLow();
break;
case screen::MsgEngineTempHigh:
this->renderMsgEngineTempHigh();
break;
default:
break;
}

View File

@@ -26,6 +26,8 @@ enum LcdScreen : uint8_t {
MsgTrackDetectOk,
MsgConfigNoTracks,
MsgBatteryLow,
MsgEngineTempLow,
MsgEngineTempHigh,
};
} // namespace screen
@@ -68,6 +70,8 @@ private:
int renderMsgTrackDetectOk();
int renderMsgConfigNoTracks();
int renderMsgBatteryLow();
int renderMsgEngineTempLow();
int renderMsgEngineTempHigh();
public:
int push(const Task &task) override;

View File

@@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "thermocouple.h"
#include "base/router.h"
#include "data/general_store.h"
int Thermocouple::push(const Task &task) { return queue_.push(task); }
@@ -14,17 +15,56 @@ Thermocouple::Thermocouple(SystemLogger *logger) : logger_(logger) {}
Thermocouple::~Thermocouple() {}
int Thermocouple::init() {
thermocouple_ = new MAX6675(THERMO_SCK, THERMO_CS, THERMO_SO);
return 0;
thermocouple_ = new MAX6675(THERMO_SCK, THERMO_CS, THERMO_SO);
VehicleConfig config;
configGlobalRead(config);
low_ = config.teng_low_;
high_ = config.teng_high_;
return 0;
}
int Thermocouple::loop(unsigned long timeout_ms) {
(void)timeout_ms;
(void)timeout_ms;
if (millis() > last_read_at_ + update_interval_) {
if (millis() > last_read_at_ + update_interval_) {
temperature_ = thermocouple_->readCelsius();
tengGlobalWrite(temperature_);
last_read_at_ = millis();
}
return 0;
if (temperature_ > high_) {
if (warning_sent_at_ == 0 ||
millis() > warning_sent_at_ + warning_timeout_) {
router::send(module::Lcd, task::DisplayMsgEngineTempHigh, 2000);
warning_sent_at_ = millis();
}
} else if (temperature_ < low_) {
if (warning_sent_at_ == 0 ||
millis() > warning_sent_at_ + warning_timeout_) {
router::send(module::Lcd, task::DisplayMsgEngineTempLow, 2000);
warning_sent_at_ = millis();
}
}
Task active_task;
int res = queue_.pop(active_task);
if (res == 0) {
if (active_task.target_ == module::Thermocouple) {
} else if (active_task.target_ == module::All) {
switch (active_task.type_) {
case task::AllConfigUpdated: {
VehicleConfig config;
configGlobalRead(config);
low_ = config.teng_low_;
high_ = config.teng_high_;
break;
}
default:
break;
}
};
}
return 0;
}
}

View File

@@ -18,8 +18,12 @@ private:
RingBuffer<Task, 16> queue_;
MAX6675 *thermocouple_;
double temperature_;
double low_;
double high_;
unsigned long update_interval_ = 1000;
unsigned long last_read_at_ = 0;
unsigned long warning_sent_at_ = 0;
unsigned long warning_timeout_ = 10000;
public:
int push(const Task &task) override;