50 lines
No EOL
1.3 KiB
C++
50 lines
No EOL
1.3 KiB
C++
#ifndef COINACCEPTOR_H
|
|
#define COINACCEPTOR_H
|
|
|
|
#include "Arduino.h"
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
class CoinAcceptor {
|
|
private:
|
|
uint8_t pulsePin, enablePin;
|
|
uint8_t accState = ACC_DISABLED;
|
|
|
|
volatile uint16_t coinPulses = 0;
|
|
volatile uint16_t allPulses = 0;
|
|
uint16_t coinValue = 0;
|
|
uint16_t sumValue = 0;
|
|
std::string sumValueStr = "";
|
|
volatile bool coinDetected = false;
|
|
volatile unsigned long currentMs = 0;
|
|
volatile unsigned long lastPulseAtMs = 0;
|
|
void IRAM_ATTR pulseIsrHandler();
|
|
|
|
public:
|
|
const uint8_t ACC_DISABLED = LOW;
|
|
const uint8_t ACC_ENABLED = HIGH;
|
|
const unsigned int* pulseValues;
|
|
unsigned int* coinNumbers;
|
|
const size_t maxPulses = 0;
|
|
const uint8_t pulseWidthMs = 0;
|
|
const uint16_t maxAllowedCentToInsert = 0;
|
|
uint8_t detectionError = 0;
|
|
|
|
CoinAcceptor(uint8_t pulsePin, uint8_t enablePin, const unsigned int* pulseValues, const size_t maxPulses, const uint8_t pulseWidthMs, const uint16_t maxAllowedCentToInsert);
|
|
~CoinAcceptor();
|
|
void begin();
|
|
void disable();
|
|
void enable();
|
|
uint8_t state();
|
|
bool detectCoin();
|
|
uint16_t getCoinValue();
|
|
uint16_t getSumValue();
|
|
void resetSumValue();
|
|
std::string getSumValueStr();
|
|
std::string getCoinsNumStr() const;
|
|
std::string getCoinsValStr() const;
|
|
|
|
};
|
|
|
|
|
|
#endif |