#ifndef PROXIMITY_SENSOR_H
#define PROXIMITY_SENSOR_H

#include "../Addon.h"

//  Typical proximity switch (testing for inductivity). Change ::read for NO or NC 
//  Wiring :
//    Blue  -> GND
//    Brown -> 6 - 36 V
//    Black -> Digital In

#include "../types.h"
#include "../enums.h"
#include "../config.h"


class ProximitySensor : public Addon
{
public:
   ProximitySensor(short _pin) : pin(_pin),
                                 Addon(PLUNGER_HOME_STR, PLUNGER_HOME),
                                 value(false){}
   short setup()
   {
      // setFlag(DEBUG);
      return E_OK;      
   }
   short loop()
   {
      value = read();
      return E_OK;
   }   
   bool read()
   {
      return !digitalRead(pin);
   }
   virtual void debug(Stream *stream)
    {
        *stream << this->name << ":" << SPACE(value);
    }


private:
   bool value;
   short pin;
};

#endif
