diff --git a/examples/elevator/Makefile b/examples/elevator/Makefile index 4c97905..59375a3 100644 --- a/examples/elevator/Makefile +++ b/examples/elevator/Makefile @@ -18,6 +18,7 @@ RM_R = rm -rf CP = cp MKDIR_P = mkdir -p DOXYGEN = doxygen +DOT = dot SRC_DIRS = . @@ -26,6 +27,8 @@ INCLUDE = -I ../../include SRCS = $(wildcard $(addsuffix /*.cpp, $(SRC_DIRS))) OBJS = $(SRCS:.cpp=.o) DEPENDS = $(OBJS:.o=.d) +DOT_FILES = $(wildcard $(addsuffix /*.dot, $(SRC_DIRS))) +PNG_FILES = $(DOT_FILES:.dot=.png) EXE = $(PROJECT) MAP = $(PROJECT).map @@ -80,7 +83,7 @@ LDFLAGS += -fno-rtti .PHONY: all clean -all: $(EXE) +all: $(EXE) $(PNG_FILES) $(EXE): $(OBJS) $(LD) $(OBJS) $(LDFLAGS) -o $(EXE) @@ -89,6 +92,9 @@ $(EXE): $(OBJS) %.o: %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< +%.png: %.dot + $(DOT) -Tpng $^ -o $@ + clean: $(RM) *.o $(RM) *.d diff --git a/examples/elevator/README.md b/examples/elevator/README.md index 6de14ce..241f9b1 100644 --- a/examples/elevator/README.md +++ b/examples/elevator/README.md @@ -28,11 +28,14 @@ each other: - State: Moving - State: Panic +![Elevator states](./elevator_state.png) + 2. Motor - State: Stopped - State: Up - State: Down +![Machine states](./machine_state.png) A good state machine design avoids circular dependencies at all cost: While the elevator sends events to the motor, the motor NEVER diff --git a/examples/elevator/elevator_state.dot b/examples/elevator/elevator_state.dot new file mode 100644 index 0000000..81d7a81 --- /dev/null +++ b/examples/elevator/elevator_state.dot @@ -0,0 +1,13 @@ +digraph "G" { + // Colour palette from https://venngage.com/blog/color-blind-friendly-palette/ + + "Idle" -> "Idle" [label="Call" color="#601A4A" fontcolor="#601A4A"] + "Idle" -> "Moving" [label="Call" color="#601A4A" fontcolor="#601A4A"] + "Idle" -> "Panic" [label="Alarm" color="#EE442F" fontcolor="#EE442F"] + + "Moving" -> "Panic" [label="FloorSensor" color="#63ACBE" fontcolor="#63ACBE"] + "Moving" -> "Idle" [label="FloorSensor" color="#63ACBE" fontcolor="#63ACBE"] + + "Panic" -> "Panic" [label="Alarm" color="#EE442F" fontcolor="#EE442F"] + +} \ No newline at end of file diff --git a/examples/elevator/elevator_state.png b/examples/elevator/elevator_state.png new file mode 100644 index 0000000..f15e807 Binary files /dev/null and b/examples/elevator/elevator_state.png differ diff --git a/examples/elevator/machine_state.dot b/examples/elevator/machine_state.dot new file mode 100644 index 0000000..88d2b99 --- /dev/null +++ b/examples/elevator/machine_state.dot @@ -0,0 +1,15 @@ +digraph "G" { + // Colour palette from https://venngage.com/blog/color-blind-friendly-palette/ + + "Up" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ] + "Down" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ] + "Stopped" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ] + + "Up" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ] + "Down" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ] + "Stopped" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ] + + "Up" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ] + "Down" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ] + "Stopped" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ] +} \ No newline at end of file diff --git a/examples/elevator/machine_state.png b/examples/elevator/machine_state.png new file mode 100644 index 0000000..86acb07 Binary files /dev/null and b/examples/elevator/machine_state.png differ