/*
 * ButtonsController.h
 *
 *  Created on: 14 nov. 2023
 *      Author: remi.heredero
 */

#ifndef F7_DISCO_GCC_BOARD_BUTTONSCONTROLLER_H_
#define F7_DISCO_GCC_BOARD_BUTTONSCONTROLLER_H_

#include "xf/behavior.h"
#include "interface/buttonirq.h"
#include "interface/buttonscontrollercallbackcaller.h"

class ButtonsController : public XFBehavior, public interface::ButtonIrq, public interface::ButtonsControllerCallbackCaller {
public:
	~ButtonsController() override = default;
	static ButtonsController* getInstance();

protected:
	ButtonsController();

	typedef enum {
		evButtonIrq = 10,
		evTimeout
	} event;

	interface::ButtonsControllerCallbackProvider* cbProvider;
	interface::ButtonsControllerCallbackProvider::CallbackMethod cbMethod;
	bool newState[4];
	bool buttonState[4];

	void fctCheckButtons(const XFEvent* ev);
	void fctScheduleTimeout(const XFEvent* ev);

	XFState stCheckButtons;
	XFState stDebounce;

public:
	virtual void onIrq() override;
	virtual bool registerCallback(
			interface::ButtonsControllerCallbackProvider *callbackProvider,
			interface::ButtonsControllerCallbackProvider::CallbackMethod callbackMethod)
					override;

};

#endif /* F7_DISCO_GCC_BOARD_BUTTONSCONTROLLER_H_ */
