//-----------------------------------------------------------------------------
///
/// \brief  Just a simple Button
///
///         A GPButton.
///
//-----------------------------------------------------------------------------


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


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

#include <biwak/button.hpp>
#include <biwak/gpio.hpp>
#include <biwak/lltools.h>        // setExti()
#include <lepto/signal.h>         // queuePendingSignal


//---Implementation------------------------------------------------------------


char buttonCount=0;


/// \brief  Le contructeur
///
CButton::CButton(EGpioPeripheral _eGpioPeripheral, EGpioPin _eGpioPin
                 , const SExtiConfig &configData)
   :CInput( _eGpioPeripheral, _eGpioPin, configData, gpioModeButton)
{
   #if defined(OLD_STATE)
      m_oldState=static_cast<EButtonState>(getValue());
   #endif
}


CButton::~CButton()
{

}


void CButton::interrupt() /* virtual override */
{
   EButtonState value __attribute__((unused))
         = static_cast<EButtonState>(getValue());

   #if defined(OLD_STATE)
   if ( value == m_oldState )
      return;
   #endif

   #if defined (USE_PENDING_SIGNALS)
      // emit the signal when button was released
      if( value == EButtonState::pressed )
         queueSignal( new CPendingSignal0<void>( pressed ) );
   #else
      pressed.emitSignal();
   #endif

   #if defined(OLD_STATE)
      m_oldState=value;
   #endif

   return;
}


//---fin-----------------------------------------------------------------------
