46 lines
911 B
C++
46 lines
911 B
C++
#pragma once
|
|
|
|
#include "adc/adc.hpp"
|
|
#include "io/io.hpp"
|
|
|
|
#include "pwm.hpp"
|
|
#include "thermistor.hpp"
|
|
|
|
class Controller {
|
|
public:
|
|
static double m_adcSample;
|
|
static double m_resistance;
|
|
static double m_temperature;
|
|
static uint8_t m_fanSpeed;
|
|
static bool m_dataAvailable;
|
|
|
|
static void init();
|
|
|
|
static void callback();
|
|
|
|
static uint8_t mapTemperature(double temperature);
|
|
|
|
private:
|
|
using adc_conf = adc::Config<adc::FreeRunningMode>;
|
|
static adc::Adc<adc_conf, io::P, io::P::C0> m_adcPin;
|
|
|
|
static constexpr auto NUM_ADC_SAMPLES = 1000;
|
|
|
|
static volatile uint32_t m_adcSampleSum;
|
|
static volatile bool m_adcSampleReady;
|
|
|
|
static Thermistor m_thermistor;
|
|
|
|
static void sampleCallback(const uint16_t &adcSample);
|
|
|
|
template <typename T>
|
|
static T clamp(double value, T lower, T upper)
|
|
{
|
|
if (value < lower)
|
|
return lower;
|
|
if (value > upper)
|
|
return upper;
|
|
return static_cast<T>(value);
|
|
}
|
|
};
|