refactored Redstone bin
This commit is contained in:
		
							parent
							
								
									8c041766c9
								
							
						
					
					
						commit
						c86d0e1d8b
					
				@ -1,44 +1,26 @@
 | 
			
		||||
package bin;
 | 
			
		||||
 | 
			
		||||
import kernel.ps.ProcessHandle;
 | 
			
		||||
import kernel.ps.Process;
 | 
			
		||||
import lib.CLIAppBase;
 | 
			
		||||
import kernel.peripherals.Peripherals.Peripheral;
 | 
			
		||||
import kernel.peripherals.Side;
 | 
			
		||||
 | 
			
		||||
using tink.CoreApi;
 | 
			
		||||
 | 
			
		||||
class Redstone implements Process {
 | 
			
		||||
	public function new() {}
 | 
			
		||||
class Redstone extends CLIAppBase{
 | 
			
		||||
	public function new() {
 | 
			
		||||
		registerSyncSubcommand("on", (args)-> {
 | 
			
		||||
			Peripheral.instance.getRedstone(args[0]).setOutput(true);
 | 
			
		||||
			return true;
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	public function run(handle: ProcessHandle):Void {
 | 
			
		||||
		var subcommand = handle.args[0];
 | 
			
		||||
		registerSyncSubcommand("off", (args)-> {
 | 
			
		||||
			Peripheral.instance.getRedstone(args[0]).setOutput(false);
 | 
			
		||||
			return true;
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if (subcommand == null) {
 | 
			
		||||
			handle.write("Usage: redstone <on|off|get> <side>");
 | 
			
		||||
			return handle.close(false);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var side:Null<Side> = handle.args[1];
 | 
			
		||||
		if (side == null) {
 | 
			
		||||
			handle.write("Invalid side");
 | 
			
		||||
			return handle.close(false);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		switch (subcommand) {
 | 
			
		||||
			case "on":
 | 
			
		||||
				Peripheral.instance.getRedstone(side).setOutput(true);
 | 
			
		||||
			case "off":
 | 
			
		||||
				Peripheral.instance.getRedstone(side).setOutput(false);
 | 
			
		||||
			case "get":
 | 
			
		||||
				var value = Peripheral.instance.getRedstone(side).getAnalogInput();
 | 
			
		||||
				handle.write("Analog input: " + value);
 | 
			
		||||
			case "help":
 | 
			
		||||
				handle.write("Usage: redstone <on|off|get> <side>");
 | 
			
		||||
			default:
 | 
			
		||||
				handle.write("Invalid subcommand");
 | 
			
		||||
				return handle.close(false);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return handle.close();
 | 
			
		||||
		registerSyncSubcommand("get", (args)-> {
 | 
			
		||||
			var value = Peripheral.instance.getRedstone(args[0]).getAnalogInput();
 | 
			
		||||
			handle.write("Analog input: " + value);
 | 
			
		||||
			return true;
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user