diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 04dadee..bf9b0f0 100755 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,7 +16,7 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pip3 install --user -r requirements.txt", + "postCreateCommand": "sudo apt-get update; sudo apt-get -y install python3-tk; pip3 install --user -r requirements.txt", // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. diff --git a/src/piston.py b/src/piston.py index 7a46391..8823b2d 100755 --- a/src/piston.py +++ b/src/piston.py @@ -7,9 +7,11 @@ import time is_pi = True try: import RPi.GPIO as GPIO + os.environ["DISPLAY"] = ":0" print("Detected Raspberry Pi!") -except RuntimeError: +except (ModuleNotFoundError, TypeError, RuntimeError): print("Detected not a Raspberry Pi!") + os.environ["DISPLAY"] = "192.168.1.133:0" is_pi = False @@ -85,7 +87,7 @@ class PistonApp: self.manual_mode_var = tk.BooleanVar() self.manual_mode_var.set(False) self.manual_mode_checkbox = tk.Checkbutton( - self.root, text="Minecraft Mode", font=("Arial", 30), variable=self.manual_mode_var, command=self.toggle_manual_mode) + self.root, text="Manual Mode", font=("Arial", 30), variable=self.manual_mode_var, command=self.toggle_manual_mode) self.manual_mode_checkbox.pack() self.next_button = tk.Button( @@ -94,7 +96,7 @@ class PistonApp: self.root.after(1000, self.synchronize_engine) - + def toggle_manual_mode(self): self.manual_mode = self.manual_mode_var.get() @@ -137,6 +139,7 @@ class PistonApp: self.canvas.coords(self.connecting_rod, px, py, px2, py2) def animate_downstroke(self): + self.canvas.move(self.piston, 0, self.stroke_length) if self.stroke == 1: self.canvas.itemconfig(self.piston, fill='blue') @@ -149,6 +152,7 @@ class PistonApp: self.stroke += 1 self.rotate_crankshaft() self.last_stroke = 'down' + if self.manual_mode: self.next_button.config(state='normal') self.canvas.update() @@ -176,6 +180,8 @@ class PistonApp: self.next_button.config(state='normal') self.canvas.update() perform_movement_operation() + time.sleep(self.delay/1000) + self.canvas.update() self.stroke_label.update() @@ -188,4 +194,4 @@ class PistonApp: if __name__ == '__main__': app = PistonApp() - app.root.mainloop() \ No newline at end of file + app.root.mainloop()