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, DisplayMsgTrackDetectOk,
DisplayMsgConfigNoTracks, DisplayMsgConfigNoTracks,
DisplayMsgBatteryLow, DisplayMsgBatteryLow,
DisplayMsgEngineTempLow,
DisplayMsgEngineTempHigh,
ConfigTrackDetect, ConfigTrackDetect,
ConfigWriteTempTrack, ConfigWriteTempTrack,
ConfigTrackDelete, ConfigTrackDelete,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include "thermocouple.h" #include "thermocouple.h"
#include "base/router.h"
#include "data/general_store.h" #include "data/general_store.h"
int Thermocouple::push(const Task &task) { return queue_.push(task); } int Thermocouple::push(const Task &task) { return queue_.push(task); }
@@ -15,6 +16,10 @@ Thermocouple::~Thermocouple() {}
int Thermocouple::init() { int Thermocouple::init() {
thermocouple_ = new MAX6675(THERMO_SCK, THERMO_CS, THERMO_SO); thermocouple_ = new MAX6675(THERMO_SCK, THERMO_CS, THERMO_SO);
VehicleConfig config;
configGlobalRead(config);
low_ = config.teng_low_;
high_ = config.teng_high_;
return 0; return 0;
} }
@@ -25,6 +30,41 @@ int Thermocouple::loop(unsigned long timeout_ms) {
temperature_ = thermocouple_->readCelsius(); temperature_ = thermocouple_->readCelsius();
tengGlobalWrite(temperature_); tengGlobalWrite(temperature_);
last_read_at_ = millis(); last_read_at_ = millis();
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; return 0;
}
} }

View File

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