
#if !defined(_CHANNEL_CV_H_)
#define _CHANNEL_CV_H_

#include <stdint.h>
#include "ring_buffer.h"
#include "calibration.h"

//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------

namespace slab {

/*!
 * @brief Processes ADC data for CV inputs.
 */
class ChannelCV
{
public:
    ChannelCV();
    ~ChannelCV()=default;

    void init(uint32_t number, const calibration::Points & points);

    //! @brief Convert ADC reading to V/oct.
    float process(uint32_t value);

    //! @brief Clear filter history.
    void reset();

    //! @brief Get the CV input's channel number.
    uint32_t get_number() const { return _number; }

protected:
    uint32_t _number;   //!< Channel number.
    float _offset;  //!< Calibration offset.
    float _scale;   //!< Calibration scale factor.
    float _out; //!< y^-1 value for filtering.
#if DEBUG
    RingBuffer<uint16_t, 128> _history;
#endif
};

} // namespace slab

#endif // _CHANNEL_CV_H_
//------------------------------------------------------------------------------
// EOF
//------------------------------------------------------------------------------
