From 2c15ae43ae58856a8c3b2361f54c792b8a9ea276 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 27 Mar 2026 23:23:14 +0100 Subject: [PATCH] Initial thermocouple impl --- platformio.ini | 1 + src/main.cpp | 4 +-- src/modules/thermocouple/thermocouple.cpp | 24 ++++++++++++++++++ src/modules/thermocouple/thermocouple.h | 31 +++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/modules/thermocouple/thermocouple.cpp create mode 100644 src/modules/thermocouple/thermocouple.h diff --git a/platformio.ini b/platformio.ini index 565c2e4..46ad391 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,3 +19,4 @@ monitor_filters = send_on_enter lib_deps = marcoschwartz/LiquidCrystal_I2C@^1.1.4 mikalhart/TinyGPSPlus@^1.1.0 + adafruit/MAX6675 library@^1.1.2 diff --git a/src/main.cpp b/src/main.cpp index f27f51f..0a66fb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,10 +61,10 @@ void setup() { driver_display->print_message("GPS Init Complete"); delay(1000); - driver_display->print_message("Bat Init..."); + driver_display->print_message("Sensors Init..."); battery_handler->init(); delay(1000); - driver_display->print_message("Bat Init Complete"); + driver_display->print_message("Sensors Init Complete"); delay(1000); router::send(MOD_LCD, TASK_DISPLAY_DRIVER_PRIMARY); } diff --git a/src/modules/thermocouple/thermocouple.cpp b/src/modules/thermocouple/thermocouple.cpp new file mode 100644 index 0000000..eb02cf4 --- /dev/null +++ b/src/modules/thermocouple/thermocouple.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2026 Hector van der Aa +// Copyright (C) 2026 Association Exergie +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "thermocouple.h" + +int thermocouple::push(const Task &task) { return _queue.push(task); } + +thermocouple::thermocouple() : _logger(nullptr) {} + +thermocouple::thermocouple(system_logger *logger) : _logger(logger) {} + +thermocouple::~thermocouple() {} + +int thermocouple::init() { + _thermocouple = new MAX6675(THERMO_SCK, THERMO_CS, THERMO_SO); + return 0; +} + +int thermocouple::loop(unsigned long timeout_ms) { + if (millis() > _last_read + _update_interval) { + _temp = _thermocouple->readCelsius(); + } +} \ No newline at end of file diff --git a/src/modules/thermocouple/thermocouple.h b/src/modules/thermocouple/thermocouple.h new file mode 100644 index 0000000..e6778ec --- /dev/null +++ b/src/modules/thermocouple/thermocouple.h @@ -0,0 +1,31 @@ +// Copyright (C) 2026 Hector van der Aa +// Copyright (C) 2026 Association Exergie +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once +#define THERMO_CS A1 +#define THERMO_SO A0 +#define THERMO_SCK A2 +#include "base/module_base.h" +#include "base/ring_buffer.h" +#include "custom_types.h" +#include "modules/logger/system_logger.h" +#include +#include + +class thermocouple : public module_base { +private: + system_logger *_logger; + ring_buffer _queue; + MAX6675 *_thermocouple; + double _temp; + unsigned long _update_interval = 1000; + unsigned long _last_read = 0; + +public: + int push(const Task &task) override; + thermocouple(); + thermocouple(system_logger *logger); + ~thermocouple(); + int init(); + int loop(unsigned long timeout_ms = 500); +}; \ No newline at end of file