Compare commits
2 Commits
f3cf12db3b
...
6ba4a2ce3d
Author | SHA1 | Date | |
---|---|---|---|
6ba4a2ce3d | |||
ea6a6bd218 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -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
|
||||
|
@ -7,6 +7,8 @@ double Controller::m_adcSample;
|
||||
double Controller::m_resistance;
|
||||
double Controller::m_temperature;
|
||||
uint8_t Controller::m_fanSpeed;
|
||||
bool Controller::m_dataAvailable = false;
|
||||
|
||||
volatile uint32_t Controller::m_adcSampleSum;
|
||||
volatile bool Controller::m_adcSampleReady = false;
|
||||
|
||||
@ -21,6 +23,7 @@ void Controller::callback()
|
||||
{
|
||||
if (m_adcSampleReady) {
|
||||
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
|
||||
m_dataAvailable = true;
|
||||
m_adcSampleReady = false;
|
||||
|
||||
m_resistance = m_thermistor.getResistance(m_adcSample);
|
||||
|
@ -12,6 +12,7 @@ class Controller {
|
||||
static double m_resistance;
|
||||
static double m_temperature;
|
||||
static uint8_t m_fanSpeed;
|
||||
static bool m_dataAvailable;
|
||||
|
||||
static void init();
|
||||
|
||||
|
1
fantemp/eeprom
Submodule
1
fantemp/eeprom
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 33a4d55f03451f487ace046a6f2328351fda69ee
|
@ -231,6 +231,9 @@
|
||||
<Compile Include="controller.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="eeprom\eeprom.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="flash\flash.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
@ -246,6 +249,12 @@
|
||||
<Compile Include="pwm.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="statistics.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="statistics.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="terminal.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
@ -255,6 +264,9 @@
|
||||
<Compile Include="thermistor.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="type\type.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="uart\config.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
@ -273,14 +285,13 @@
|
||||
<Compile Include="uart\uart.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="uart\utils.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="flash" />
|
||||
<Folder Include="io" />
|
||||
<Folder Include="adc" />
|
||||
<Folder Include="eeprom" />
|
||||
<Folder Include="type" />
|
||||
<Folder Include="uart" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
|
@ -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<uart::Config<115200>>;
|
||||
Terminal<serial> 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;
|
||||
|
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 "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,20 +174,25 @@ 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;
|
||||
}
|
||||
|
||||
static void showState()
|
||||
{
|
||||
char floatBuffer[16];
|
||||
if (Controller::m_dataAvailable) {
|
||||
char floatBuffer[16];
|
||||
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
||||
m_serial << F("ADC value ...: ") << floatBuffer << F(" / 1023") << detail::ENDL;
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_resistance);
|
||||
m_serial << F("Resistance ..: ") << floatBuffer << F(" Ohm") << detail::ENDL;
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
||||
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
|
||||
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << detail::ENDL;
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
||||
m_serial << F("ADC value ...: ") << floatBuffer << F(" / 1023") << detail::ENDL;
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_resistance);
|
||||
m_serial << F("Resistance ..: ") << floatBuffer << F(" Ohm") << detail::ENDL;
|
||||
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
||||
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << 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()
|
||||
@ -228,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;
|
||||
|
1
fantemp/type
Submodule
1
fantemp/type
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit ce31ef017f738baaca6f0cbf99dac9d59b5e6811
|
@ -1 +1 @@
|
||||
Subproject commit 6f592dd0987cae4f7f826056e5ff358ad26d3127
|
||||
Subproject commit ae03c8d43e46dfbd396a052f71670727b293ac76
|
Loading…
Reference in New Issue
Block a user