#ifndef _INPUT_H_
#define _INPUT_H_
//----------------------------------------------------------------------------
///
/// \brief  Just a simple Input
///
///         See implementation for further information.
///
/// \date   20121107
/// \author Maximilian Seesslen <development@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <biwak/gpio.hpp>
#include <biwak/exti.h>
#include <biwak/timer.hpp>      // hrtimer_t
#include <lepto/signal.h>
#include <lepto/lepto.h>         // IS_ENABLED( )


//---Declaration--------------------------------------------------------------


enum EIntputSlopeType
{
      eIntputSlopeTypeNone=0,
      eIntputSlopeTypeRising=1,
      eIntputSlopeTypeFalling=2,
      eIntputSlopeTypeRisingFalling=3,
};


class CInputDecoder
{
protected:
   //int successCount=0;
   //int errorCount=0;

public:
   virtual void slope(bool value)=0;
};


class CInput
         :public CGpio
         ,public CExti
{
   public:

   private:
      #if IS_ENABLED( CONFIG_BIWAK_USE_INPUT_FILTER )
      EIntputSlopeType m_filterSlopeType = eIntputSlopeTypeNone;
      #endif
      
      #if IS_ENABLED( CONFIG_BIWAK_USE_INPUT_DECODER )
         CInputDecoder *m_decoder=nullptr;
      #endif
      //bool m_enabled=false;
      //volatile int blocked;

   public:
      #if IS_ENABLED( CONFIG_BIWAK_USE_INPUT_SIGNAL )
      CSignal<void, bool> interruptSignal;
      #endif

      CInput(EGpioPeripheral _eGpioPeripheral, EGpioPin _eGpioPin
               , const SExtiConfig &configData
               , const SGpioMode &gpioMode=gpioModeInputInterrupt
           );
      
      CInput( const SExtiConfig &configData
             , const SGpioMode &gpioMode=gpioModeInputInterrupt
             );
      
      CInput(CGpio &gpio, const SExtiConfig &configData
               , const SGpioMode &gpioMode=  gpioModeInput
           );
      
      ~CInput();
      
      #if IS_ENABLED( CONFIG_BIWAK_USE_INPUT_FILTER )
      void filterSlopes(EIntputSlopeType filterSlopeType)
      {
         m_filterSlopeType=filterSlopeType;
      }
      #endif
      
      virtual void interrupt() override;
      
      #if IS_ENABLED( CONFIG_BIWAK_USE_INPUT_DECODER )
      void setDecoder(CInputDecoder *decoder)
      {
         m_decoder=decoder;
      }
      #endif
};


//---fin----------------------------------------------------------------------
#endif // ? ! _INPUT_H_
