#pragma once

#include <cstddef>
#include <stdint.h>
#include <array>
/**
 * @brief This class implements an FIR Filter, and contains it's own storage for input values.
 * Namely, this filter produces the following output:
 *
 * y[n] = a0*x[n] + a1*x[n-1] + a2*x[n-2] + ...
 *
 * Coefficients are passed via a pointer to an array of doubles, along with the number of
 * coefficients.
 */

class FIR_Filter
{
  public:
	FIR_Filter();

	// Initialize all values of dataBuff_ to initialValue
	void init(const double initialValue);

	// Update the filter with newValue, using filter coefficients in coeffs.
	// If the filter has not been initialized with an initial value, it will be
	// initialized to 0.
	double update(const double newValue, const double* coeffs, const size_t num_coeffs);

	// Return most recent filter value.
	double getLastFilteredValue() const;

	// Ensure FILTER_LENGTH is > num_coeff for all implementations!
	static constexpr size_t FILTER_LENGTH = 32;

  private:
	bool isInitialized_;
	double dataBuff_[FILTER_LENGTH];
	double lastFilteredValue_;
};