Compare commits
2 Commits
f3cf12db3b
...
6ba4a2ce3d
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ba4a2ce3d | |||
| ea6a6bd218 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -10,3 +10,9 @@
|
|||||||
[submodule "fantemp/adc"]
|
[submodule "fantemp/adc"]
|
||||||
path = fantemp/adc
|
path = fantemp/adc
|
||||||
url = git@git.blackmark.me:avr/adc.git
|
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
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ double Controller::m_adcSample;
|
|||||||
double Controller::m_resistance;
|
double Controller::m_resistance;
|
||||||
double Controller::m_temperature;
|
double Controller::m_temperature;
|
||||||
uint8_t Controller::m_fanSpeed;
|
uint8_t Controller::m_fanSpeed;
|
||||||
|
bool Controller::m_dataAvailable = false;
|
||||||
|
|
||||||
volatile uint32_t Controller::m_adcSampleSum;
|
volatile uint32_t Controller::m_adcSampleSum;
|
||||||
volatile bool Controller::m_adcSampleReady = false;
|
volatile bool Controller::m_adcSampleReady = false;
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ void Controller::callback()
|
|||||||
{
|
{
|
||||||
if (m_adcSampleReady) {
|
if (m_adcSampleReady) {
|
||||||
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
|
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
|
||||||
|
m_dataAvailable = true;
|
||||||
m_adcSampleReady = false;
|
m_adcSampleReady = false;
|
||||||
|
|
||||||
m_resistance = m_thermistor.getResistance(m_adcSample);
|
m_resistance = m_thermistor.getResistance(m_adcSample);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Controller {
|
|||||||
static double m_resistance;
|
static double m_resistance;
|
||||||
static double m_temperature;
|
static double m_temperature;
|
||||||
static uint8_t m_fanSpeed;
|
static uint8_t m_fanSpeed;
|
||||||
|
static bool m_dataAvailable;
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
|||||||
1
fantemp/eeprom
Submodule
1
fantemp/eeprom
Submodule
Submodule fantemp/eeprom added at 33a4d55f03
@@ -231,6 +231,9 @@
|
|||||||
<Compile Include="controller.hpp">
|
<Compile Include="controller.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="eeprom\eeprom.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="flash\flash.hpp">
|
<Compile Include="flash\flash.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -246,6 +249,12 @@
|
|||||||
<Compile Include="pwm.hpp">
|
<Compile Include="pwm.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="statistics.cpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="statistics.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="terminal.hpp">
|
<Compile Include="terminal.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -255,6 +264,9 @@
|
|||||||
<Compile Include="thermistor.hpp">
|
<Compile Include="thermistor.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="type\type.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="uart\config.hpp">
|
<Compile Include="uart\config.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -273,14 +285,13 @@
|
|||||||
<Compile Include="uart\uart.hpp">
|
<Compile Include="uart\uart.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="uart\utils.hpp">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="flash" />
|
<Folder Include="flash" />
|
||||||
<Folder Include="io" />
|
<Folder Include="io" />
|
||||||
<Folder Include="adc" />
|
<Folder Include="adc" />
|
||||||
|
<Folder Include="eeprom" />
|
||||||
|
<Folder Include="type" />
|
||||||
<Folder Include="uart" />
|
<Folder Include="uart" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
|
|||||||
@@ -7,12 +7,15 @@
|
|||||||
|
|
||||||
#include "bootloader.hpp"
|
#include "bootloader.hpp"
|
||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
#include "terminal.hpp"
|
#include "terminal.hpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Bootloader::init([]() {});
|
Bootloader::init([]() {});
|
||||||
|
|
||||||
|
clk::init();
|
||||||
|
|
||||||
using serial = uart::Uart0<uart::Config<115200>>;
|
using serial = uart::Uart0<uart::Config<115200>>;
|
||||||
Terminal<serial> terminal;
|
Terminal<serial> terminal;
|
||||||
terminal.init();
|
terminal.init();
|
||||||
@@ -20,11 +23,13 @@ int main()
|
|||||||
Controller controller;
|
Controller controller;
|
||||||
controller.init();
|
controller.init();
|
||||||
|
|
||||||
clk::init();
|
Statistics statistics;
|
||||||
|
statistics.init();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
controller.callback();
|
controller.callback();
|
||||||
terminal.callback();
|
terminal.callback();
|
||||||
|
statistics.callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
62
fantemp/statistics.cpp
Normal file
62
fantemp/statistics.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#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<double>::max();
|
||||||
|
}
|
||||||
|
if (isnan(m_maxTemp)) {
|
||||||
|
m_maxTemp = type::numeric_limits<double>::lowest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Statistics::callback()
|
||||||
|
{
|
||||||
|
Eeprom<e_minTemp, true> eepromMinTemp;
|
||||||
|
Eeprom<e_maxTemp, true> 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<e_minTemp, true> eepromMinTemp;
|
||||||
|
return eepromMinTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Statistics::getMaxTemp()
|
||||||
|
{
|
||||||
|
Eeprom<e_maxTemp, true> eepromMaxTemp;
|
||||||
|
return eepromMaxTemp;
|
||||||
|
}
|
||||||
20
fantemp/statistics.hpp
Normal file
20
fantemp/statistics.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "clock.hpp"
|
#include "clock.hpp"
|
||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
@@ -20,9 +21,10 @@ GF(CURVE_CMD, "curve");
|
|||||||
GF(MONITOR_CMD, "monitor");
|
GF(MONITOR_CMD, "monitor");
|
||||||
GF(BOOTLOADER_CMD, "bootloader");
|
GF(BOOTLOADER_CMD, "bootloader");
|
||||||
GF(UPTIME_CMD, "uptime");
|
GF(UPTIME_CMD, "uptime");
|
||||||
|
GF(STATISTICS_CMD, "statistics");
|
||||||
|
|
||||||
GF(VERSION_CMD, "version");
|
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)
|
static inline bool substringEquals(const char *str, const ::detail::FlashString *flashStr, const size_t &size)
|
||||||
{
|
{
|
||||||
@@ -142,6 +144,8 @@ class Terminal {
|
|||||||
handleBootloader();
|
handleBootloader();
|
||||||
} else if (substringEquals(m_inputBuffer, detail::UPTIME_CMD, m_inputSize)) {
|
} else if (substringEquals(m_inputBuffer, detail::UPTIME_CMD, m_inputSize)) {
|
||||||
printUptime();
|
printUptime();
|
||||||
|
} else if (substringEquals(m_inputBuffer, detail::STATISTICS_CMD, m_inputSize)) {
|
||||||
|
printStatistics();
|
||||||
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
|
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
|
||||||
printVersion();
|
printVersion();
|
||||||
} else {
|
} else {
|
||||||
@@ -170,11 +174,13 @@ class Terminal {
|
|||||||
m_serial << detail::MONITOR_CMD << F(" ....: loops the show command until Ctrl + C is pressed") << detail::ENDL;
|
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::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::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;
|
m_serial << detail::VERSION_CMD << F(" ....: displays firmware version") << detail::ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showState()
|
static void showState()
|
||||||
{
|
{
|
||||||
|
if (Controller::m_dataAvailable) {
|
||||||
char floatBuffer[16];
|
char floatBuffer[16];
|
||||||
|
|
||||||
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
||||||
@@ -184,6 +190,9 @@ class Terminal {
|
|||||||
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
||||||
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
|
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
|
||||||
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << detail::ENDL;
|
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << detail::ENDL;
|
||||||
|
} else {
|
||||||
|
m_serial << F("No data available yet!") << detail::ENDL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printCurve()
|
static void printCurve()
|
||||||
@@ -228,6 +237,16 @@ class Terminal {
|
|||||||
m_serial << detail::ENDL;
|
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()
|
static void printVersion()
|
||||||
{
|
{
|
||||||
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;
|
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;
|
||||||
|
|||||||
1
fantemp/type
Submodule
1
fantemp/type
Submodule
Submodule fantemp/type added at ce31ef017f
Submodule fantemp/uart updated: 6f592dd098...ae03c8d43e
Reference in New Issue
Block a user