#ifndef __MC_HID_SERVER_HPP
#define __MC_HID_SERVER_HPP

#include <stdint.h>
//#include <dbus-c++-1/dbus-c++/dbus.h> // Done thhrough <mc-hid-server-glue.hpp>
#include <boost/signals2.hpp>

#include "mc-hid-server-glue.hpp"

#include "thread/thread.hpp"
#include "buttontimer/buttontimer.hpp"
#include "gpio/gpio.hpp"

class HidServer 
  : public nl::miqra::MediaCore::Hid_adaptor, // << This will be generated by the makefile using dbusxx-xml2cpp on mc-hid-introspect.xml
  public DBus::IntrospectableAdaptor,
  public DBus::ObjectAdaptor,
  public Thread
{
public:

    HidServer(DBus::Connection &connection);
    ~HidServer();
    
    virtual void SetColor(const uint8_t& r, const uint8_t& g, const uint8_t& b);
    virtual void PulseColor(const uint8_t& r, const uint8_t& g, const uint8_t& b, const double& interval);
    virtual void ClearColor();

    bool onValidatePress(uint8_t gpio);
    void onShortPress(uint8_t gpio);
    void onLongPress(uint8_t gpio);
    void onBtChange(uint8_t gpio, GpioEdge edge, bool level);

protected:
	virtual void ThreadLoop();
    //void onChange(int gpio, int level, uint32_t tick);

private:
    ButtonTimer *btnTimer;
    RgbLed *rgbLed;
    GpioPin *btHome;
    GpioPin *btCancel;
    GpioPins *btOther;
    
	uint8_t pulseR, pulseG, pulseB, pulseI,pulseMin;
    int32_t pulseTime;
    int32_t pulseSteps;
	bool pulseDirUp;
	
    void initHardware(void);
    
	std::string getBtnName(uint8_t gpio);

    //static void onChangeEx(int gpio, int level, uint32_t tick, void *user);

    boost::signals2::connection onBtHomeConnection;
    boost::signals2::connection onBtOtherConnection;
	boost::signals2::connection onInterruptErrorConnection;
    boost::signals2::connection onShortPressConnection;
    boost::signals2::connection onLongPressConnection;
    boost::signals2::connection onValidatePressConnection;
};

#endif//__MC_HID_SERVER_HPP