#ifndef ATMBUTTON_H
#define ATMBUTTON_H

#include <Arduino.h>

class AtmButton {
private:

    uint8_t pin, ledPin;
    uint8_t ledState = LEDOFF;
    volatile bool pressed = false;
    volatile unsigned long last_pressed_ms = 0;
    volatile unsigned long pressed_at_ms = 0;
    volatile unsigned long pressed_after_ms = 0;
    volatile unsigned long pressed_count = 0;
    
    bool activeWaiting = false; 
    unsigned long startWaitTime = 0;
    unsigned long lastWaitLedToggle = 0;

    static void IRAM_ATTR buttonIsrHandler(void* arg);  // Interrupt Service Routine (ISR)

public:
    const uint8_t LEDON = HIGH;
    const uint8_t LEDOFF = LOW;
    const unsigned long DEBOUNCE_BUTTON_MS = 200;	// wait that number of ms before counting the button pressed pulse -> debouncing

    AtmButton(uint8_t, uint8_t );
    void begin();
    void reset();
    void softPress();
    bool wasPressed();
    void ledOn();
    void ledOff();
    void ledToggle();
    bool iswaitingUntilPressed(unsigned long maxTimeToWaitMs, unsigned long blinkPeriodMs);
};

#endif
