SimpleFSM icon indicating copy to clipboard operation
SimpleFSM copied to clipboard

Improve GraphViz output by using named events

Open marcelstoer opened this issue 1 year ago • 6 comments

Including GraphViz/dot support is a very nifty idea, thanks!

The only issue I see is the lack of named events. The example at https://github.com/LennartHennigs/SimpleFSM/blob/master/README.md#graphviz-generation would be a lot more legible IMO if instead of "(ID = 1)" it said "press button". I understand this won't be possible out-of-the-box as events are defined by number rather than by name (usually through an enum).

However, what if we could pass something like an "event name array" to the SimpleFSM constructor (or through a setter)? Use a preprocessor macro to generate said array or hand-craft it.

enum events {
  button_clicked,
  button_double_clicked,
};

#define IDNAME(name) #name
const char* eventNames[] = {IDNAME(button_clicked), IDNAME(button_double_clicked)};

void setup() {
  ...
  fsm.setEventNames(eventNames);
  ...
}

(borrowed from here)

marcelstoer avatar Feb 05 '24 15:02 marcelstoer