Last active
February 8, 2017 17:12
-
-
Save ThomPuiman/2b05517c898055cbed50b73f75fbdc2b to your computer and use it in GitHub Desktop.
Revisions
-
ThomPuiman revised this gist
Feb 8, 2017 . No changes.There are no files selected for viewing
-
ThomPuiman revised this gist
Feb 8, 2017 . No changes.There are no files selected for viewing
-
ThomPuiman revised this gist
Feb 8, 2017 . No changes.There are no files selected for viewing
-
ThomPuiman revised this gist
Feb 8, 2017 . No changes.There are no files selected for viewing
-
ThomPuiman created this gist
Feb 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ from enum import Enum; class DoorState(Enum): CLOSING = 1 CLOSED = 2 STOPPED_WHILE_CLOSING = 3 OPEN = 4 OPENING = 5 STOPPED_WHILE_OPENING = 6 EMERGENCY_OPENING = 7 OPEN_BLOCKED = 8 class DoorOperator(): state = DoorState.CLOSED; def getCommand(self, command): { 'button_click': self.buttonClick, 'cycle_complete': self.cycleComplete, 'block_detected': self.blockDetected, 'block_cleared': self.blockCleared }[command](); return "Door: " + self.state.name; def buttonClick(self): self.state = self.getTransition(); def cycleComplete(self): if(self.state.value in [5,3]): self.state = DoorState.OPEN; if(self.state.value in [1,6]): self.state = DoorState.CLOSED; def blockDetected(self): self.state = DoorState.EMERGENCY_OPENING; def blockCleared(self): self.state = DoorState.OPEN; def getTransition(self): return { DoorState.CLOSING: DoorState.STOPPED_WHILE_CLOSING, DoorState.CLOSED: DoorState.OPENING, DoorState.OPENING: DoorState.STOPPED_WHILE_OPENING, DoorState.STOPPED_WHILE_OPENING: DoorState.CLOSING, DoorState.STOPPED_WHILE_CLOSING: DoorState.OPENING, DoorState.OPEN: DoorState.CLOSING, DoorState.EMERGENCY_OPENING: DoorState.OPEN_BLOCKED, DoorState.OPEN_BLOCKED: DoorState.OPEN_BLOCKED }[self.state]; operator = DoorOperator(); while(True): print(operator.getCommand(input("> ")))