/*
 * buttoneventslogger.cpp
 *
 *  Created on: Nov 7, 2023
 *      Author: remi.heredero
 */

#include <app/buttoneventslogger.h>
#include "trace/trace.h"
#include "ButtonEvent.h"

ButtonEventsLogger::ButtonEventsLogger()
	: stWait(this) {

	stInitial.addInitialTransition(&stWait);
	stWait.addTransition(event::evButtonShortPressed, &stWait);
	stWait.addTransition(event::evButtonLongPressed, &stWait);
	stWait.registerOnEntry((XFState::callbackEv)&ButtonEventsLogger::logOnTrace);
}

void ButtonEventsLogger::onButtonShortPressed(ButtonIndex buttonIndex) {
	GEN(ButtonEvent(event::evButtonShortPressed, this, buttonIndex));
}

void ButtonEventsLogger::onButtonLongPressed(ButtonIndex buttonIndex) {
	GEN(ButtonEvent(event::evButtonLongPressed, this, buttonIndex));
}

void ButtonEventsLogger::logOnTrace(const XFEvent* ev) {
	ButtonEvent* buttonEvent = (ButtonEvent*)ev;
	int evid = buttonEvent->getId();
	if(evid == event::evButtonShortPressed){
			Trace::out("ButtonEventLogger: Button %d short pressed", buttonEvent->getButtonId());
	}
	if(evid == event::evButtonLongPressed){
			Trace::out("ButtonEventLogger: Button %d long pressed", buttonEvent->getButtonId());
	}
}
