Compare commits
	
		
			3 Commits
		
	
	
		
			6046e76a85
			...
			6bdda947ef
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 6bdda947ef | ||
|  | 4b71555ce8 | ||
|  | 44b7812949 | 
| @@ -16,7 +16,7 @@ | |||||||
| 	// Use 'forwardPorts' to make a list of ports inside the container available locally. | 	// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||||||
| 	// "forwardPorts": [], | 	// "forwardPorts": [], | ||||||
| 	// Use 'postCreateCommand' to run commands after the container is created. | 	// 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. | 	// Configure tool-specific properties. | ||||||
| 	// "customizations": {}, | 	// "customizations": {}, | ||||||
| 	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | 	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								requirements.txt
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										1
									
								
								requirements.txt
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -1 +0,0 @@ | |||||||
| tkinter |  | ||||||
| @@ -7,9 +7,11 @@ import time | |||||||
| is_pi = True | is_pi = True | ||||||
| try: | try: | ||||||
|     import RPi.GPIO as GPIO |     import RPi.GPIO as GPIO | ||||||
|  |     os.environ["DISPLAY"] = ":0" | ||||||
|     print("Detected Raspberry Pi!") |     print("Detected Raspberry Pi!") | ||||||
| except RuntimeError: | except (ModuleNotFoundError, TypeError, RuntimeError): | ||||||
|     print("Detected not a Raspberry Pi!") |     print("Detected not a Raspberry Pi!") | ||||||
|  |     os.environ["DISPLAY"] = "192.168.1.133:0" | ||||||
|     is_pi = False |     is_pi = False | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -85,7 +87,7 @@ class PistonApp: | |||||||
|         self.manual_mode_var = tk.BooleanVar() |         self.manual_mode_var = tk.BooleanVar() | ||||||
|         self.manual_mode_var.set(False) |         self.manual_mode_var.set(False) | ||||||
|         self.manual_mode_checkbox = tk.Checkbutton( |         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.manual_mode_checkbox.pack() | ||||||
|  |  | ||||||
|         self.next_button = tk.Button( |         self.next_button = tk.Button( | ||||||
| @@ -94,7 +96,7 @@ class PistonApp: | |||||||
|  |  | ||||||
|         self.root.after(1000, self.synchronize_engine) |         self.root.after(1000, self.synchronize_engine) | ||||||
|  |  | ||||||
|  |      | ||||||
|  |  | ||||||
|     def toggle_manual_mode(self): |     def toggle_manual_mode(self): | ||||||
|         self.manual_mode = self.manual_mode_var.get() |         self.manual_mode = self.manual_mode_var.get() | ||||||
| @@ -137,6 +139,7 @@ class PistonApp: | |||||||
|         self.canvas.coords(self.connecting_rod, px, py, px2, py2) |         self.canvas.coords(self.connecting_rod, px, py, px2, py2) | ||||||
|  |  | ||||||
|     def animate_downstroke(self): |     def animate_downstroke(self): | ||||||
|  |          | ||||||
|         self.canvas.move(self.piston, 0, self.stroke_length) |         self.canvas.move(self.piston, 0, self.stroke_length) | ||||||
|         if self.stroke == 1: |         if self.stroke == 1: | ||||||
|             self.canvas.itemconfig(self.piston, fill='blue') |             self.canvas.itemconfig(self.piston, fill='blue') | ||||||
| @@ -149,6 +152,7 @@ class PistonApp: | |||||||
|         self.stroke += 1 |         self.stroke += 1 | ||||||
|         self.rotate_crankshaft() |         self.rotate_crankshaft() | ||||||
|         self.last_stroke = 'down' |         self.last_stroke = 'down' | ||||||
|  |  | ||||||
|         if self.manual_mode: |         if self.manual_mode: | ||||||
|             self.next_button.config(state='normal') |             self.next_button.config(state='normal') | ||||||
|         self.canvas.update() |         self.canvas.update() | ||||||
| @@ -176,6 +180,8 @@ class PistonApp: | |||||||
|             self.next_button.config(state='normal') |             self.next_button.config(state='normal') | ||||||
|         self.canvas.update() |         self.canvas.update() | ||||||
|         perform_movement_operation() |         perform_movement_operation() | ||||||
|  |         time.sleep(self.delay/1000) | ||||||
|  |  | ||||||
|         self.canvas.update() |         self.canvas.update() | ||||||
|         self.stroke_label.update() |         self.stroke_label.update() | ||||||
|  |  | ||||||
| @@ -188,4 +194,4 @@ class PistonApp: | |||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     app = PistonApp() |     app = PistonApp() | ||||||
|     app.root.mainloop() |     app.root.mainloop() | ||||||
|   | |||||||
							
								
								
									
										76
									
								
								system/etc/init.d/piston
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								system/etc/init.d/piston
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | ### BEGIN INIT INFO | ||||||
|  | # Provides:          exampledaemon | ||||||
|  | # Required-Start:    $local_fs $network $syslog | ||||||
|  | # Required-Stop:     $local_fs $network $syslog | ||||||
|  | # Default-Start:     2 3 4 5 | ||||||
|  | # Default-Stop:      0 1 6 | ||||||
|  | # Short-Description: Example | ||||||
|  | # Description:       Example start-stop-daemon - Debian | ||||||
|  | ### END INIT INFO | ||||||
|  |  | ||||||
|  | NAME="Piston Service" | ||||||
|  | PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" | ||||||
|  | APPDIR="/root" | ||||||
|  | APPBIN="/root/S99piston" | ||||||
|  | APPARGS="" | ||||||
|  | USER="root" | ||||||
|  | GROUP="root" | ||||||
|  |  | ||||||
|  | # Include functions | ||||||
|  | set -e | ||||||
|  | . /lib/lsb/init-functions | ||||||
|  |  | ||||||
|  | start() { | ||||||
|  |   printf "Starting '$NAME'... " | ||||||
|  |   start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS || true | ||||||
|  |   printf "done\n" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #We need this function to ensure the whole process tree will be killed | ||||||
|  | killtree() { | ||||||
|  |     local _pid=$1 | ||||||
|  |     local _sig=${2-TERM} | ||||||
|  |     for _child in $(ps -o pid --no-headers --ppid ${_pid}); do | ||||||
|  |         killtree ${_child} ${_sig} | ||||||
|  |     done | ||||||
|  |     kill -${_sig} ${_pid} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | stop() { | ||||||
|  |   printf "Stopping '$NAME'... " | ||||||
|  |   [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \ | ||||||
|  |   while test -d /proc/$(cat /var/run/$NAME.pid); do | ||||||
|  |     killtree $(cat /var/run/$NAME.pid) 15 | ||||||
|  |     sleep 0.5 | ||||||
|  |   done | ||||||
|  |   [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid | ||||||
|  |   printf "done\n" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | status() { | ||||||
|  |   status_of_proc -p /var/run/$NAME.pid "" $NAME && exit 0 || exit $? | ||||||
|  | } | ||||||
|  |  | ||||||
|  | case "$1" in | ||||||
|  |   start) | ||||||
|  |     start | ||||||
|  |     ;; | ||||||
|  |   stop) | ||||||
|  |     stop | ||||||
|  |     ;; | ||||||
|  |   restart) | ||||||
|  |     stop | ||||||
|  |     start | ||||||
|  |     ;; | ||||||
|  |   status) | ||||||
|  |     status | ||||||
|  |     ;; | ||||||
|  |   *) | ||||||
|  |     echo "Usage: $NAME {start|stop|restart|status}" >&2 | ||||||
|  |     exit 1 | ||||||
|  |     ;; | ||||||
|  | esac | ||||||
|  |  | ||||||
|  | exit 0 | ||||||
		Reference in New Issue
	
	Block a user