2023-01-10 10:34:40 +00:00
|
|
|
//
|
|
|
|
// Created by robtor on 10.01.23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FLOATPUMP_PRESSURECHANNEL_H
|
|
|
|
#define FLOATPUMP_PRESSURECHANNEL_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
2023-01-12 14:16:20 +00:00
|
|
|
#include <memory>
|
2023-01-10 10:34:40 +00:00
|
|
|
#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();
|
|
|
|
|
2023-01-13 10:50:03 +00:00
|
|
|
void LinkCalibConfig(uint16_t *low, uint16_t *high);
|
|
|
|
|
2023-01-10 10:34:40 +00:00
|
|
|
private:
|
|
|
|
const uint16_t m_avg_size = 50;
|
|
|
|
const uint16_t m_avg_delay = 10;
|
|
|
|
const uint16_t m_cooldown = 500;
|
|
|
|
|
2023-01-13 10:50:03 +00:00
|
|
|
uint16_t *m_lowcalib = new uint16_t(0);
|
|
|
|
uint16_t *m_highcalib = new uint16_t(65535);
|
2023-01-10 10:34:40 +00:00
|
|
|
|
|
|
|
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
|