#ifndef COINACCEPTOR_H
#define COINACCEPTOR_H

#include "Arduino.h"

class CoinAcceptor {
private:
  uint8_t pulsePin, enablePin;
  uint8_t accState = ACC_DISABLED;
  
  volatile uint16_t coinPulses = 0;
  uint16_t coinValue = 0;
  volatile bool coinDetected = false;
  volatile unsigned long lastPulseAtMs = 0;
  static void IRAM_ATTR pulseIsrHandler(void* arg);

public:
  const uint8_t ACC_DISABLED = LOW;
  const uint8_t ACC_ENABLED = HIGH;
  const unsigned int* pulseValues;
  const size_t maxPulses = 0;
  const uint8_t pulseWidthMs = 0;
  uint8_t detectionError = 0;

  CoinAcceptor(uint8_t pulsePin, uint8_t enablePin, const unsigned int* pulseValues, const size_t maxPulses, const uint8_t pulseWidthMs );
  void begin();
  void disable();
  void enable();
  uint8_t state();
  bool detectCoin();
  uint16_t getCoinValue();

};


#endif