53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
|
/*
|
||
|
* ButtonEventsHandler.h
|
||
|
*
|
||
|
* Created on: 19 nov. 2023
|
||
|
* Author: remi.heredero
|
||
|
*/
|
||
|
|
||
|
#ifndef BUTTON_BUTTONEVENTSHANDLER_H_
|
||
|
#define BUTTON_BUTTONEVENTSHANDLER_H_
|
||
|
|
||
|
#include "xf/behavior.h"
|
||
|
#include "interface/buttonscontrollercallbackprovider.h"
|
||
|
#include "interface/buttoneventshandlersubject.h"
|
||
|
#include "interface/buttoneventshandlerobserver.h"
|
||
|
#include "button/ButtonStateSm.h"
|
||
|
|
||
|
#define MAX_OBSERVER 5
|
||
|
|
||
|
class ButtonEventsHandler : public XFBehavior, public interface::ButtonsControllerCallbackProvider, public interface::ButtonEventsHandlerSubject {
|
||
|
public:
|
||
|
~ButtonEventsHandler() override = default;
|
||
|
static ButtonEventsHandler* getInstance();
|
||
|
|
||
|
void onButtonChangeState(uint16_t buttonIndex, bool pressed);
|
||
|
|
||
|
virtual bool subscribe(interface::ButtonEventsHandlerObserver* observer);
|
||
|
virtual void unsubscribe(interface::ButtonEventsHandlerObserver* observer);
|
||
|
|
||
|
virtual void notifyButtonShortPressed(ButtonIndex buttonIndex);
|
||
|
virtual void notifyButtonLongPressed(ButtonIndex buttonIndex);
|
||
|
|
||
|
protected:
|
||
|
ButtonEventsHandler();
|
||
|
XFEventStatus processEvent() override;
|
||
|
|
||
|
typedef enum {
|
||
|
initial,
|
||
|
run
|
||
|
} state ;
|
||
|
|
||
|
state currentState_;
|
||
|
state oldState_;
|
||
|
bool changeState_;
|
||
|
|
||
|
interface::ButtonEventsHandlerObserver* observer_[MAX_OBSERVER];
|
||
|
ButtonStateSm buttonStateSm_[4];
|
||
|
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif /* BUTTON_BUTTONEVENTSHANDLER_H_ */
|