51 lines
1.0 KiB
C++
51 lines
1.0 KiB
C++
//
|
|
// Created by robtor on 10.01.23.
|
|
//
|
|
|
|
#ifndef FLOATPUMP_PRESSURECHANNEL_H
|
|
#define FLOATPUMP_PRESSURECHANNEL_H
|
|
|
|
#include <cstdint>
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
namespace floatpump::io {
|
|
|
|
class PressureChannel {
|
|
|
|
public:
|
|
PressureChannel(ADC_HandleTypeDef *adc, GPIO_TypeDef *gpio, uint16_t port, const uint16_t avg_size = 50);;
|
|
|
|
void poll();
|
|
|
|
[[nodiscard]] uint16_t getRaw() const;
|
|
|
|
[[nodiscard]] int8_t getPercent() const;
|
|
|
|
[[maybe_unused]] void calibrateManualLow(uint16_t low);
|
|
|
|
[[maybe_unused]] void calibrateManualHigh(uint16_t high);
|
|
|
|
void calibrateLow();
|
|
|
|
void calibrateHigh();
|
|
|
|
private:
|
|
const uint16_t m_avg_size = 50;
|
|
const uint16_t m_avg_delay = 10;
|
|
const uint16_t m_cooldown = 500;
|
|
|
|
uint16_t m_lowcalib = 0;
|
|
uint16_t m_highcalib = 65535;
|
|
|
|
uint16_t m_raw = 0;
|
|
int8_t m_percent = 0;
|
|
|
|
ADC_HandleTypeDef *m_adc;
|
|
GPIO_TypeDef *m_gpio;
|
|
uint16_t m_gpio_port;
|
|
};
|
|
|
|
} // io
|
|
|
|
#endif //FLOATPUMP_PRESSURECHANNEL_H
|