Class KPState

Class Documentation

class KPState

Public Functions

const char *getName() const

Get the Name object

Return
const char* pointer to the name assigned to this state

virtual void enter(KPStateMachine &machine) = 0

[Required] Subclass must override this method and specify the behavior when entering this state

Parameters
  • machine:

virtual void leave(KPStateMachine &machine)

When override, this method is called just before the transition to new state

Parameters
  • machine: State machine owning this state

virtual void update(KPStateMachine &machine)

Override to receive runtime lifecycle loop while in this state

Parameters
  • machine: State machine owning this state

unsigned long timeSinceLastTransition() const

Return time since the last call to enter lifecycle method

Return
unsigned long

void setTimeCondition(unsigned long seconds, std::function<void()> callback)

Convenient method for time-based state condition

Parameters
  • seconds: time until the callback is executed
  • callback: callback to execute when the time expires

void setCondition(std::function<bool()> conditionstd::function<void()> callback)

Set the state condition.

Parameters
  • condition: callable that returns true on abitary condition
  • callback: callable to be executed when condition returns true

Protected Functions

void begin()
void reserve(size_t size)

Protected Attributes

const char *name = nullptr
unsigned long startTime = 0
bool didEnter = false
size_t numberOfSchedules = 0
std::vector<KPStateSchedule> schedules