Files
Bachelorarbeit-Rover/lib/Counter/counter.h
T
kleiax db74898b72 documentation checked and edit
for all files in lib folder
2023-10-12 18:45:12 +02:00

78 lines
1.5 KiB
C++

/**
* @file counter.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains a class that abstract the hardware counter from the esp32
* @version 0.1
* @date 2023-10-12
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include <Arduino.h>
#include <driver/pcnt.h>
#include <cinttypes>
/**
* @brief A class that abstract the hardware counter from the esp32
*/
class Counter
{
public:
/**
* @brief Construct a new Counter object
*
* @param pin with incoming pulses
*/
Counter(uint8_t pin);
/**
* @brief Pause the pulse counting
*/
void pause();
/**
* @brief Resume the pulse counting
*/
void resume();
/**
* @brief Start counting by zero again
*/
void clear();
/**
* @brief Get the counted pulses
*
* @return int16_t
*/
int16_t getValue() const;
/**
* @brief Set the filter value
*
* The filter skip all pulses after a pulse for the filter time.
* The filter time depends on the frequency of the processor. The time
* for a whole tact multiplied with the filter value results the filter time.
*
* @param value max 1023
*/
void setFilterValue(uint16_t value);
void filterEnable();
void filterDisable();
private:
static constexpr int16_t highLimit = INT16_MAX;
static constexpr uint8_t lowLimit = 0;
static constexpr uint8_t maxCounter = 6;
static uint8_t amountOfCounter;
bool initalized = false;
uint8_t pulsePin;
pcnt_unit_t unit;
};