Add documentation.
authorBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 9 Nov 2022 14:29:47 +0000 (15:29 +0100)
committerBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 9 Nov 2022 14:29:47 +0000 (15:29 +0100)
conf.json
doc/DebugView.png [new file with mode: 0644]
doc/index.md

index 04fe43ab918613cceef5a11ab9f972928defd8ef..45773d74878399687d436b21532a5a63b763b0f2 100644 (file)
--- a/conf.json
+++ b/conf.json
@@ -1,5 +1,5 @@
 {
-    "Example Server": {
+    "Debug": {
         "plugin": "WSServer",
         "port": 8080,
         "web": {
@@ -7,16 +7,6 @@
                    "location": "Debug" }
         }
     },
-    "Lubrication Button": {
-        "plugin": "Alias",
-        "from": {
-            "target": { "const": "Lubrication Button" },
-            "command": { "const": "press" }
-        },
-        "to": {
-            "event": "pressed"
-        }
-    },
     "Engine Button": {
         "plugin": "Alias",
         "from": {
             "event": "pressed"
         }
     },
-    "Lubrication": {
-        "plugin": "State"
-    },
     "Engine": {
         "plugin": "State"
     },
+    "Delay": {
+        "plugin": "Wait",
+        "seconds": 5
+    },
     "Machine": {
         "plugin": "StateMachine",
         "init": "off",
                         "target": "Engine",
                         "command": "set state",
                         "new state": false
-                    },
-                    {
-                        "target": "Lubrication",
-                        "command": "set state",
-                        "new state": false
                     }
                 ],
                 "transitions": [
                         "target": "Engine",
                         "command": "set state",
                         "new state": false
-                    },
-                    {
-                        "target": "Lubrication",
-                        "command": "set state",
-                        "new state": false
                     }
                 ],
                 "transitions": [
                     },
                     {
                         "trigger": {
-                            "sender": { "const": "Lubrication Button" },
+                            "sender": { "const": "Engine Button" },
                             "event": { "const": "pressed" }
                         },
-                        "to": "lubrication on"
+                        "to": "on"
                     }
                 ]
             },
-            "lubrication on": {
+            "on": {
                 "commands": [
                     {
                         "target": "Engine",
                         "command": "set state",
-                        "new state": false
-                    },
-                    {
-                        "target": "Lubrication",
-                        "command": "set state",
                         "new state": true
                     }
                 ],
                         },
                         "to": "emergency"
                     },
-                    {
-                        "trigger": {
-                            "sender": { "const": "Lubrication Button" },
-                            "event": { "const": "pressed" }
-                        },
-                        "to": "off"
-                    },
                     {
                         "trigger": {
                             "sender": { "const": "Engine Button" },
                             "event": { "const": "pressed" }
                         },
-                        "to": "engine on"
+                        "to": "delay"
                     }
                 ]
             },
-            "engine on": {
+            "delay": {
                 "commands": [
                     {
-                        "target": "Engine",
-                        "command": "set state",
-                        "new state": true
-                    },
-                    {
-                        "target": "Lubrication",
-                        "command": "set state",
-                        "new state": true
+                        "target": "Delay",
+                        "command": "wait"
                     }
                 ],
                 "transitions": [
                     },
                     {
                         "trigger": {
-                            "sender": { "const": "Engine Button" },
-                            "event": { "const": "pressed" }
+                            "sender": { "const": "Delay" },
+                            "event": { "const": "finished" }
                         },
-                        "to": "lubrication on"
+                        "to": "off"
                     }
                 ]
             }
diff --git a/doc/DebugView.png b/doc/DebugView.png
new file mode 100644 (file)
index 0000000..8345b9d
Binary files /dev/null and b/doc/DebugView.png differ
index b52b6674a57a567c51a1f50433ac09b81adaa78a..11baa12fa4bf24ab8eebb31178f9af86f71532db 100644 (file)
@@ -29,4 +29,164 @@ es auch direkt, ohne einen git-Clone installiert werden:
 ```
 
 ## Benutzung
-…
+Eine minimale ControlPi-Konfiguration, die dieses Plugin benutzt, ist im
+git-Repository enthalten:
+```json
+{
+    "Debug": {
+        "plugin": "WSServer",
+        "port": 8080,
+        "web": {
+            "/": { "module": "controlpi_plugins.wsserver",
+                   "location": "Debug" }
+        }
+    },
+    "Engine Button": {
+        "plugin": "Alias",
+        "from": {
+            "target": { "const": "Engine Button" },
+            "command": { "const": "press" }
+        },
+        "to": {
+            "event": "pressed"
+        }
+    },
+    "Emergency Button": {
+        "plugin": "Alias",
+        "from": {
+            "target": { "const": "Emergency Button" },
+            "command": { "const": "press"}
+        },
+        "to": {
+            "event": "pressed"
+        }
+    },
+    "Engine": {
+        "plugin": "State"
+    },
+    "Delay": {
+        "plugin": "Wait",
+        "seconds": 5
+    },
+    "Machine": {
+        "plugin": "StateMachine",
+        "init": "off",
+        "states": {
+            "emergency": {
+                "commands": [
+                    {
+                        "target": "Engine",
+                        "command": "set state",
+                        "new state": false
+                    }
+                ],
+                "transitions": [
+                    {
+                        "trigger": {
+                            "sender": { "const": "Emergency Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "off"
+                    }
+                ]
+            },
+            "off": {
+                "commands": [
+                    {
+                        "target": "Engine",
+                        "command": "set state",
+                        "new state": false
+                    }
+                ],
+                "transitions": [
+                    {
+                        "trigger": {
+                            "sender": { "const": "Emergency Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "emergency"
+                    },
+                    {
+                        "trigger": {
+                            "sender": { "const": "Engine Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "on"
+                    }
+                ]
+            },
+            "on": {
+                "commands": [
+                    {
+                        "target": "Engine",
+                        "command": "set state",
+                        "new state": true
+                    }
+                ],
+                "transitions": [
+                    {
+                        "trigger": {
+                            "sender": { "const": "Emergency Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "emergency"
+                    },
+                    {
+                        "trigger": {
+                            "sender": { "const": "Engine Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "delay"
+                    }
+                ]
+            },
+            "delay": {
+                "commands": [
+                    {
+                        "target": "Delay",
+                        "command": "wait"
+                    }
+                ],
+                "transitions": [
+                    {
+                        "trigger": {
+                            "sender": { "const": "Emergency Button" },
+                            "event": { "const": "pressed" }
+                        },
+                        "to": "emergency"
+                    },
+                    {
+                        "trigger": {
+                            "sender": { "const": "Delay" },
+                            "event": { "const": "finished" }
+                        },
+                        "to": "off"
+                    }
+                ]
+            }
+        }
+    }
+}
+```
+
+In der Debug-Oberfläche sieht das Beispiel folgendermaßen aus:
+![Debug-Oberfläche](graphit/controlpi-statemachine/DebugView.png)
+
+Die beiden `Alias`-Instanzen simulieren Taster und die `State`-Instanz
+`Engine` einen Motor, der von der Statemachine gesteuert wird.
+Aus dem initialen Zustand `off` kann durch Drücken des `Engine Button` in
+den Zustand `on` gewechselt werden.
+
+Nochmaliges Drücken des `Engine Button` schaltet die Maschine aber nicht
+sofort ab, sondern wechelt in einen fünf-sekündigen Nachlauf im Zustand
+`delay`.
+Dies wird dadurch erreicht, dass beim Betreten des Zustands dem
+`Wait`-Plugin `Delay` das Kommando `wait` geschickt wird und der Zustand
+dann durch eine Transition, die auf das `finished`-Event reagiert verlassen
+wird.
+
+Außerdem kann die Maschine aus jedem Zustand heraus durch Drücken des
+`Emergency Button` sofort abgeschaltet werden, wobei in den Zustand
+`emergency` gewechselt wird.
+Dieser kann nur verlassen werden, wenn durch nochmaliges Drücken des
+`Emergency Button` bestätigt wird, dass die Gefahr vorüber ist.