diff --git a/.gitmodules b/.gitmodules
index 29dd130..65d439e 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,9 @@
[submodule "fantemp/adc"]
path = fantemp/adc
url = git@git.blackmark.me:avr/adc.git
+[submodule "fantemp/type"]
+ path = fantemp/type
+ url = git@git.blackmark.me:avr/type.git
+[submodule "fantemp/eeprom"]
+ path = fantemp/eeprom
+ url = git@git.blackmark.me:avr/eeprom.git
diff --git a/fantemp/eeprom b/fantemp/eeprom
new file mode 160000
index 0000000..33a4d55
--- /dev/null
+++ b/fantemp/eeprom
@@ -0,0 +1 @@
+Subproject commit 33a4d55f03451f487ace046a6f2328351fda69ee
diff --git a/fantemp/fantemp.cppproj b/fantemp/fantemp.cppproj
index e4e1237..a4d9ead 100644
--- a/fantemp/fantemp.cppproj
+++ b/fantemp/fantemp.cppproj
@@ -231,6 +231,9 @@
compile
+
+ compile
+
compile
@@ -246,6 +249,12 @@
compile
+
+ compile
+
+
+ compile
+
compile
@@ -255,6 +264,9 @@
compile
+
+ compile
+
compile
@@ -273,14 +285,13 @@
compile
-
- compile
-
+
+
diff --git a/fantemp/main.cpp b/fantemp/main.cpp
index 64149fa..11a04bf 100644
--- a/fantemp/main.cpp
+++ b/fantemp/main.cpp
@@ -7,12 +7,15 @@
#include "bootloader.hpp"
#include "controller.hpp"
+#include "statistics.hpp"
#include "terminal.hpp"
int main()
{
Bootloader::init([]() {});
+ clk::init();
+
using serial = uart::Uart0>;
Terminal terminal;
terminal.init();
@@ -20,11 +23,13 @@ int main()
Controller controller;
controller.init();
- clk::init();
+ Statistics statistics;
+ statistics.init();
while (true) {
controller.callback();
terminal.callback();
+ statistics.callback();
}
return 0;
diff --git a/fantemp/statistics.cpp b/fantemp/statistics.cpp
new file mode 100644
index 0000000..4d7b655
--- /dev/null
+++ b/fantemp/statistics.cpp
@@ -0,0 +1,62 @@
+#include "statistics.hpp"
+
+#include
+
+#include "eeprom/eeprom.hpp"
+#include "type/type.hpp"
+
+#include "clock.hpp"
+#include "controller.hpp"
+
+uint64_t Statistics::m_lastTempSave = 0;
+double Statistics::m_minTemp;
+double Statistics::m_maxTemp;
+
+EEVAR(double, e_minTemp);
+EEVAR(double, e_maxTemp);
+
+void Statistics::init()
+{
+ m_minTemp = getMinTemp();
+ m_maxTemp = getMaxTemp();
+
+ if (isnan(m_minTemp)) {
+ m_minTemp = type::numeric_limits::max();
+ }
+ if (isnan(m_maxTemp)) {
+ m_maxTemp = type::numeric_limits::lowest();
+ }
+}
+
+void Statistics::callback()
+{
+ Eeprom eepromMinTemp;
+ Eeprom eepromMaxTemp;
+
+ if (Controller::m_dataAvailable) {
+ if (Controller::m_temperature < m_minTemp) {
+ m_minTemp = Controller::m_temperature;
+ }
+ if (Controller::m_temperature > m_maxTemp) {
+ m_maxTemp = Controller::m_temperature;
+ }
+
+ if (clk::millis() >= m_lastTempSave + TEMP_SAVE_DELAY) {
+ eepromMinTemp = m_minTemp;
+ eepromMaxTemp = m_maxTemp;
+ m_lastTempSave = clk::millis();
+ }
+ }
+}
+
+double Statistics::getMinTemp()
+{
+ Eeprom eepromMinTemp;
+ return eepromMinTemp;
+}
+
+double Statistics::getMaxTemp()
+{
+ Eeprom eepromMaxTemp;
+ return eepromMaxTemp;
+}
diff --git a/fantemp/statistics.hpp b/fantemp/statistics.hpp
new file mode 100644
index 0000000..a77356d
--- /dev/null
+++ b/fantemp/statistics.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include
+
+class Statistics {
+ public:
+ static void init();
+ static void callback();
+
+ static double getMinTemp();
+ static double getMaxTemp();
+
+ private:
+ static constexpr auto TEMP_SAVE_DELAY = 60000;
+
+ static uint64_t m_lastTempSave;
+
+ static double m_minTemp;
+ static double m_maxTemp;
+};
diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp
index b5bad56..359290c 100644
--- a/fantemp/terminal.hpp
+++ b/fantemp/terminal.hpp
@@ -10,6 +10,7 @@
#include "clock.hpp"
#include "controller.hpp"
+#include "statistics.hpp"
namespace detail {
@@ -20,9 +21,10 @@ GF(CURVE_CMD, "curve");
GF(MONITOR_CMD, "monitor");
GF(BOOTLOADER_CMD, "bootloader");
GF(UPTIME_CMD, "uptime");
+GF(STATISTICS_CMD, "statistics");
GF(VERSION_CMD, "version");
-GF(VERSION, "1.3");
+GF(VERSION, "1.4");
static inline bool substringEquals(const char *str, const ::detail::FlashString *flashStr, const size_t &size)
{
@@ -142,6 +144,8 @@ class Terminal {
handleBootloader();
} else if (substringEquals(m_inputBuffer, detail::UPTIME_CMD, m_inputSize)) {
printUptime();
+ } else if (substringEquals(m_inputBuffer, detail::STATISTICS_CMD, m_inputSize)) {
+ printStatistics();
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
printVersion();
} else {
@@ -170,6 +174,7 @@ class Terminal {
m_serial << detail::MONITOR_CMD << F(" ....: loops the show command until Ctrl + C is pressed") << detail::ENDL;
m_serial << detail::BOOTLOADER_CMD << F(" .: enters the bootloader after 3 seconds") << detail::ENDL;
m_serial << detail::UPTIME_CMD << F(" .....: show system uptime") << detail::ENDL;
+ m_serial << detail::STATISTICS_CMD << F(" .: Print overall statistics like min and max temp") << detail::ENDL;
m_serial << detail::VERSION_CMD << F(" ....: displays firmware version") << detail::ENDL;
}
@@ -232,6 +237,16 @@ class Terminal {
m_serial << detail::ENDL;
}
+ static void printStatistics()
+ {
+ char floatBuffer[16];
+
+ sprintf(floatBuffer, "%.2f", Statistics::getMinTemp());
+ m_serial << F("Minimum temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
+ sprintf(floatBuffer, "%.2f", Statistics::getMaxTemp());
+ m_serial << F("Maximum temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
+ }
+
static void printVersion()
{
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;
diff --git a/fantemp/type b/fantemp/type
new file mode 160000
index 0000000..ce31ef0
--- /dev/null
+++ b/fantemp/type
@@ -0,0 +1 @@
+Subproject commit ce31ef017f738baaca6f0cbf99dac9d59b5e6811
diff --git a/fantemp/uart b/fantemp/uart
index 6f592dd..ae03c8d 160000
--- a/fantemp/uart
+++ b/fantemp/uart
@@ -1 +1 @@
-Subproject commit 6f592dd0987cae4f7f826056e5ff358ad26d3127
+Subproject commit ae03c8d43e46dfbd396a052f71670727b293ac76