Compare commits
7 Commits
05a220110d
...
c86d0e1d8b
| Author | SHA1 | Date | |
|---|---|---|---|
| c86d0e1d8b | |||
| 8c041766c9 | |||
| 779933be32 | |||
| 06b3e37138 | |||
| 2a7f02c5e3 | |||
| e11a9383ee | |||
| 182a2bce7d |
214
src/bin/Disk.hx
214
src/bin/Disk.hx
@@ -1,124 +1,130 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import lib.CLIAppBase;
|
||||||
import kernel.ps.Process;
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
class Disk implements Process {
|
class Disk extends CLIAppBase {
|
||||||
private var handle:ProcessHandle;
|
public function new() {
|
||||||
|
registerSyncSubcommand("ls", (args)->{
|
||||||
|
Peripheral.instance.getDrives().foreach(drive -> {
|
||||||
|
var addr = drive.getAddr();
|
||||||
|
var label = drive.getDiskLabel();
|
||||||
|
var id = drive.getDiskID();
|
||||||
|
|
||||||
public function new() {}
|
if (drive.isDiskPresent()){
|
||||||
|
if (drive.hasAudio()){
|
||||||
public function run(handle:ProcessHandle):Void {
|
handle.writeLine('${addr} => ${label} [AUDIO]');
|
||||||
this.handle = handle;
|
}else{
|
||||||
var subcommand = handle.args[0];
|
handle.writeLine('${addr} => ${label} (${id})');
|
||||||
var driveAddr:Null<String> = handle.args[1];
|
|
||||||
|
|
||||||
switch (subcommand) {
|
|
||||||
case "ls":
|
|
||||||
Peripheral.instance.getDrives().foreach(drive -> {
|
|
||||||
var addr = drive.getAddr();
|
|
||||||
var label = drive.getDiskLabel();
|
|
||||||
var id = drive.getDiskID();
|
|
||||||
|
|
||||||
if (drive.isDiskPresent()){
|
|
||||||
if (drive.hasAudio()){
|
|
||||||
handle.writeLine('${addr} => ${label} [AUDIO]');
|
|
||||||
}else{
|
|
||||||
handle.writeLine('${addr} => ${label} (${id})');
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
handle.writeLine('${addr} => [NO DISK]');
|
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
return true;
|
handle.writeLine('${addr} => [NO DISK]');
|
||||||
});
|
|
||||||
case "play":
|
|
||||||
var drive = Peripheral.instance.getDrive(driveAddr);
|
|
||||||
|
|
||||||
if (drive == null){
|
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
return true;
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSyncSubcommand("play", (args)->{
|
||||||
|
if (args.length < 1){
|
||||||
|
handle.writeLine("Missing drive address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return audioDiskPlayPause(args[0], true);
|
||||||
|
},"<drive>");
|
||||||
|
|
||||||
|
registerSyncSubcommand("stop", (args) -> {
|
||||||
|
if (args.length < 1){
|
||||||
|
handle.writeLine("Missing drive address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return audioDiskPlayPause(args[0], false);
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSyncSubcommand("eject", (args)->{
|
||||||
|
if (args.length < 1){
|
||||||
|
handle.writeLine("Missing drive address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var driveAddr = args[0];
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
drive.ejectDisk();
|
||||||
|
return true;
|
||||||
|
},"<drive>");
|
||||||
|
|
||||||
|
registerSyncSubcommand("lable",(args) -> {
|
||||||
|
if (args.length < 1){
|
||||||
|
handle.writeLine("Missing drive address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var driveAddr = args[0];
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
var label:String = args[1];
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (label == null || label == ""){
|
||||||
|
handle.writeLine(drive.getDiskLabel());
|
||||||
|
}else{
|
||||||
|
var err = drive.setDiskLabel(label);
|
||||||
|
if (err != null){
|
||||||
|
handle.writeLine("Failed to set lable");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!drive.hasAudio()){
|
return true;
|
||||||
handle.writeLine("Disk in drive " + driveAddr + " does not have audio");
|
},"<drive> [label]");
|
||||||
}
|
}
|
||||||
|
|
||||||
drive.playAudio();
|
private function audioDiskPlayPause(driveAddr: String, play: Bool): Bool {
|
||||||
case "stop":
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
var drive = Peripheral.instance.getDrive(driveAddr);
|
|
||||||
|
|
||||||
if (drive == null){
|
if (drive == null){
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
}
|
return false;
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drive.hasAudio()){
|
|
||||||
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
|
||||||
}
|
|
||||||
|
|
||||||
drive.stopAudio();
|
|
||||||
|
|
||||||
case "eject":
|
|
||||||
var drive = Peripheral.instance.getDrive(driveAddr);
|
|
||||||
|
|
||||||
if (drive == null){
|
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
drive.ejectDisk();
|
|
||||||
case "lable":
|
|
||||||
var drive = Peripheral.instance.getDrive(driveAddr);
|
|
||||||
var label:String = handle.args[2];
|
|
||||||
|
|
||||||
if (drive == null){
|
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (label == null || label == ""){
|
|
||||||
handle.writeLine(drive.getDiskLabel());
|
|
||||||
}else{
|
|
||||||
var err = drive.setDiskLabel(label);
|
|
||||||
if (err != null){
|
|
||||||
handle.writeLine("Failed to set lable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "help":
|
|
||||||
case null:
|
|
||||||
printHelp();
|
|
||||||
default:
|
|
||||||
handle.writeLine("Unknown subcommand: " + subcommand);
|
|
||||||
printHelp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle.close(true);
|
if (!drive.isDiskPresent()){
|
||||||
}
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private function printHelp() {
|
if (!drive.hasAudio()){
|
||||||
handle.writeLine("Usage: disk <subcommand> [args]");
|
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
||||||
handle.writeLine("Subcommands:");
|
return false;
|
||||||
handle.writeLine(" ls");
|
}
|
||||||
handle.writeLine(" play <drive>");
|
|
||||||
handle.writeLine(" stop <drive>");
|
if (play){
|
||||||
handle.writeLine(" eject <drive>");
|
drive.playAudio();
|
||||||
handle.writeLine(" label <drive> [label]");
|
}else{
|
||||||
|
drive.stopAudio();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
src/bin/GPS.hx
133
src/bin/GPS.hx
@@ -1,97 +1,70 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import lib.CLIAppBase;
|
||||||
import kernel.ps.Process;
|
|
||||||
import kernel.gps.INS;
|
import kernel.gps.INS;
|
||||||
import lib.Pos3;
|
import lib.Pos3;
|
||||||
import lib.Vec.Vec3;
|
import lib.Vec.Vec3;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class GPS implements Process {
|
class GPS extends CLIAppBase {
|
||||||
private var handle:ProcessHandle;
|
public function new() {
|
||||||
|
registerSyncSubcommand("set", (args)->{
|
||||||
|
var x: Float = Std.parseFloat(args[0]);
|
||||||
|
var y: Float = Std.parseFloat(args[1]);
|
||||||
|
var z: Float = Std.parseFloat(args[2]);
|
||||||
|
|
||||||
public function new() {}
|
var pos: Pos3 = new Vec3<Float>(x, y, z);
|
||||||
|
|
||||||
public function run(handle: ProcessHandle):Void {
|
kernel.gps.GPS.instance.setManualPosition(pos);
|
||||||
this.handle = handle;
|
|
||||||
|
|
||||||
var subcommand = handle.args[0];
|
|
||||||
var subcommand_args = handle.args.slice(1);
|
|
||||||
|
|
||||||
switch (subcommand) {
|
|
||||||
case "set":
|
|
||||||
handle.close(setManuelPos(subcommand_args));
|
|
||||||
case "status":
|
|
||||||
handle.close(getGPSStatus());
|
|
||||||
case "locate":
|
|
||||||
kernel.gps.GPS.instance.locate().handle((pos)->{
|
|
||||||
if (pos != null) {
|
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
|
||||||
handle.close(true);
|
|
||||||
} else {
|
|
||||||
handle.writeLine("Position not available");
|
|
||||||
handle.close(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
case "ins":
|
|
||||||
INS.instance.align().handle(()->{
|
|
||||||
handle.writeLine("INS aligned");
|
|
||||||
handle.close(true);
|
|
||||||
});
|
|
||||||
default:
|
|
||||||
handle.writeLine("Unknown subcommand: " + subcommand);
|
|
||||||
printHelp();
|
|
||||||
handle.close(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function printHelp(){
|
|
||||||
handle.writeLine("GPS commands:");
|
|
||||||
handle.writeLine("set <x> <y> <z> - set manual position");
|
|
||||||
handle.writeLine("status - get current position and accuracy");
|
|
||||||
handle.writeLine("locate - get current position");
|
|
||||||
handle.writeLine("ins - align INS");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setManuelPos(args: Array<String>): Bool {
|
|
||||||
var x: Float = Std.parseFloat(args[0]);
|
|
||||||
var y: Float = Std.parseFloat(args[1]);
|
|
||||||
var z: Float = Std.parseFloat(args[2]);
|
|
||||||
|
|
||||||
var pos: Pos3 = new Vec3<Float>(x, y, z);
|
|
||||||
|
|
||||||
kernel.gps.GPS.instance.setManualPosition(pos);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getGPSStatus(): Bool {
|
|
||||||
|
|
||||||
var pos = kernel.gps.GPS.instance.getPosition();
|
|
||||||
if (pos != null) {
|
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
|
||||||
} else {
|
|
||||||
handle.writeLine("Position not available");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
},"<x> <y> <z>");
|
||||||
|
|
||||||
var acc = kernel.gps.GPS.instance.getAccuracy();
|
registerSyncSubcommand("status",(args)->{
|
||||||
if (acc == 1){
|
var pos = kernel.gps.GPS.instance.getPosition();
|
||||||
handle.writeLine("Accuracy: Low");
|
if (pos != null) {
|
||||||
} else if (acc == 2){
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
handle.writeLine("Accuracy: Medium");
|
} else {
|
||||||
} else if (acc == 3){
|
handle.writeLine("Position not available");
|
||||||
handle.writeLine("Accuracy: High");
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ins = INS.instance.getHeading();
|
var acc = kernel.gps.GPS.instance.getAccuracy();
|
||||||
if (ins != null) {
|
if (acc == 1){
|
||||||
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
handle.writeLine("Accuracy: Low");
|
||||||
} else {
|
} else if (acc == 2){
|
||||||
handle.writeLine("INS heading not available");
|
handle.writeLine("Accuracy: Medium");
|
||||||
}
|
} else if (acc == 3){
|
||||||
|
handle.writeLine("Accuracy: High");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
var ins = INS.instance.getHeading();
|
||||||
|
if (ins != null) {
|
||||||
|
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
||||||
|
} else {
|
||||||
|
handle.writeLine("INS heading not available");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("locate",(args)->{
|
||||||
|
return kernel.gps.GPS.instance.locate().map((pos)->{
|
||||||
|
if (pos != null) {
|
||||||
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
|
} else {
|
||||||
|
handle.writeLine("Position not available");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("ins",(args)->{
|
||||||
|
return INS.instance.align().map((_)->{
|
||||||
|
handle.writeLine("INS aligned");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
139
src/bin/Net.hx
139
src/bin/Net.hx
@@ -1,102 +1,65 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import lib.CLIAppBase;
|
||||||
import kernel.ps.Process;
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
import kernel.net.Routing;
|
import kernel.net.Routing;
|
||||||
import haxe.ds.ReadOnlyArray;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Net implements Process {
|
class Net extends CLIAppBase {
|
||||||
private var handle:ProcessHandle;
|
public function new() {
|
||||||
|
registerSyncSubcommand("route", (args)->{
|
||||||
|
var routes = Routing.instance.getRouteTable();
|
||||||
|
|
||||||
public function new() {}
|
for(k => v in routes) {
|
||||||
|
handle.writeLine('${k} => ${v.interf.name()}(${v.cost})');
|
||||||
public function run(handle:ProcessHandle):Void {
|
|
||||||
this.handle = handle;
|
|
||||||
|
|
||||||
var subcommand = handle.args[0];
|
|
||||||
var subcommand_args = handle.args.slice(1);
|
|
||||||
|
|
||||||
switch (subcommand) {
|
|
||||||
case "route":
|
|
||||||
route(subcommand_args);
|
|
||||||
return handle.close();
|
|
||||||
case "iface":
|
|
||||||
iface(subcommand_args);
|
|
||||||
return handle.close();
|
|
||||||
case "help":
|
|
||||||
printHelp();
|
|
||||||
return handle.close();
|
|
||||||
case "ping":
|
|
||||||
ping(subcommand_args);
|
|
||||||
// Closes itself
|
|
||||||
case "proto":
|
|
||||||
protos();
|
|
||||||
return handle.close();
|
|
||||||
default:
|
|
||||||
handle.write("Unknown subcommand: " + subcommand);
|
|
||||||
printHelp();
|
|
||||||
return handle.close(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function printHelp() {
|
|
||||||
handle.write("net route");
|
|
||||||
handle.write("net iface");
|
|
||||||
handle.write("net help");
|
|
||||||
handle.write("net proto");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function route(args:ReadOnlyArray<String>):Void {
|
|
||||||
var routes = Routing.instance.getRouteTable();
|
|
||||||
|
|
||||||
for(k => v in routes) {
|
|
||||||
handle.write('${k} => ${v.interf.name()}(${v.cost})');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function iface(args:ReadOnlyArray<String>):Bool {
|
|
||||||
var modems = Peripheral.instance.getModems();
|
|
||||||
|
|
||||||
for (modem in modems) {
|
|
||||||
handle.write(modem.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ping(args:ReadOnlyArray<String>): Void {
|
|
||||||
if (args.length != 1) {
|
|
||||||
handle.write("Usage: net ping id");
|
|
||||||
return handle.close(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
var toID:Null<Int> = Std.parseInt(args[0]);
|
|
||||||
|
|
||||||
if (toID == null) {
|
|
||||||
handle.write("Invalid ID");
|
|
||||||
return handle.close(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
kernel.net.Net.instance.ping(toID).handle(result -> {
|
|
||||||
switch (result){
|
|
||||||
case Success(_):
|
|
||||||
handle.write("Ping succeeded");
|
|
||||||
return handle.close();
|
|
||||||
case Failure(failure):
|
|
||||||
handle.write("Ping failed: " + failure);
|
|
||||||
return handle.close(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function protos():Void {
|
registerSyncSubcommand("iface", (args)->{
|
||||||
var protos = kernel.net.Net.instance.getActiveProtocols();
|
var modems = Peripheral.instance.getModems();
|
||||||
|
|
||||||
for (proto in protos) {
|
for (modem in modems) {
|
||||||
handle.write(proto);
|
handle.writeLine(modem.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSyncSubcommand("proto",(args)->{
|
||||||
|
var protos = kernel.net.Net.instance.getActiveProtocols();
|
||||||
|
|
||||||
|
for (proto in protos) {
|
||||||
|
handle.writeLine(proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("ping",(args)->{
|
||||||
|
if (args.length < 1) {
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var toID:Null<Int> = Std.parseInt(args[0]);
|
||||||
|
|
||||||
|
if (toID == null) {
|
||||||
|
handle.write("Invalid ID");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return kernel.net.Net.instance.ping(toID).map(result -> {
|
||||||
|
switch (result){
|
||||||
|
case Success(_):
|
||||||
|
handle.write("Ping succeeded");
|
||||||
|
case Failure(failure):
|
||||||
|
handle.write("Ping failed: " + failure);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
},"<id>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,26 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import lib.CLIAppBase;
|
||||||
import kernel.ps.Process;
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
import kernel.peripherals.Side;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Redstone implements Process {
|
class Redstone extends CLIAppBase{
|
||||||
public function new() {}
|
public function new() {
|
||||||
|
registerSyncSubcommand("on", (args)-> {
|
||||||
|
Peripheral.instance.getRedstone(args[0]).setOutput(true);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
public function run(handle: ProcessHandle):Void {
|
registerSyncSubcommand("off", (args)-> {
|
||||||
var subcommand = handle.args[0];
|
Peripheral.instance.getRedstone(args[0]).setOutput(false);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
if (subcommand == null) {
|
registerSyncSubcommand("get", (args)-> {
|
||||||
handle.write("Usage: redstone <on|off|get> <side>");
|
var value = Peripheral.instance.getRedstone(args[0]).getAnalogInput();
|
||||||
return handle.close(false);
|
handle.write("Analog input: " + value);
|
||||||
}
|
return true;
|
||||||
|
});
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,11 +117,24 @@ class Terminal implements Process {
|
|||||||
ProcessManager.run(ps,{
|
ProcessManager.run(ps,{
|
||||||
args: commandArgs,
|
args: commandArgs,
|
||||||
onWrite: (s:String) -> {
|
onWrite: (s:String) -> {
|
||||||
|
if (s == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hadInput) {
|
if (!hadInput) {
|
||||||
|
// Add a new line, so that the input is not on the same line as the command
|
||||||
this.backlog.push("");
|
this.backlog.push("");
|
||||||
hadInput = true;
|
hadInput = true;
|
||||||
}
|
}
|
||||||
this.backlog[this.backlog.length - 1] += s;
|
|
||||||
|
for (line in s.split("\n")) {
|
||||||
|
if (line == ""){
|
||||||
|
this.backlog.push("");
|
||||||
|
} else {
|
||||||
|
this.backlog[this.backlog.length - 1] += s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
},
|
},
|
||||||
onExit: (success:Bool) -> {
|
onExit: (success:Bool) -> {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class ProcessHandle {
|
|||||||
private final closeFuture: Future<Bool>;
|
private final closeFuture: Future<Bool>;
|
||||||
private var closeFutureResolev: Bool -> Void;
|
private var closeFutureResolev: Bool -> Void;
|
||||||
private final windowContexts: Array<WindowContext> = [];
|
private final windowContexts: Array<WindowContext> = [];
|
||||||
|
private final cbLinks:Array<CallbackLink> = [];
|
||||||
|
|
||||||
@:allow(kernel.ps.ProcessManager)
|
@:allow(kernel.ps.ProcessManager)
|
||||||
private function new(config: HandleConfig,pid: PID) {
|
private function new(config: HandleConfig,pid: PID) {
|
||||||
@@ -34,8 +35,6 @@ class ProcessHandle {
|
|||||||
if (this.config.onExit != null) {
|
if (this.config.onExit != null) {
|
||||||
this.closeFuture.handle(this.config.onExit);
|
this.closeFuture.handle(this.config.onExit);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.closeFuture.eager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onExit(): Future<Bool> {
|
public function onExit(): Future<Bool> {
|
||||||
@@ -75,7 +74,17 @@ class ProcessHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function dispose() {
|
private function dispose() {
|
||||||
// TODO
|
for (link in this.cbLinks) {
|
||||||
|
link.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPid(): PID {
|
||||||
|
return this.pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCallbackLink(link: CallbackLink) {
|
||||||
|
this.cbLinks.push(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_args():ReadOnlyArray<String> {
|
function get_args():ReadOnlyArray<String> {
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ abstract class CLIAppBase implements Process {
|
|||||||
|
|
||||||
private function registerSyncSubcommand(command: String, callback: (Array<String>) -> Bool, synopsis: String = null) {
|
private function registerSyncSubcommand(command: String, callback: (Array<String>) -> Bool, synopsis: String = null) {
|
||||||
_subcommandsSync.set(command, callback);
|
_subcommandsSync.set(command, callback);
|
||||||
_subcommandsSynopsis.push(command + " " + synopsis);
|
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerAsyncSubcommand(command: String, callback: (Array<String>) -> Future<Bool>, synopsis: String = null) {
|
private function registerAsyncSubcommand(command: String, callback: (Array<String>) -> Future<Bool>, synopsis: String = null) {
|
||||||
_subcommandsAsync.set(command, callback);
|
_subcommandsAsync.set(command, callback);
|
||||||
_subcommandsSynopsis.push(command + " " + synopsis);
|
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function printHelp() {
|
private function printHelp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user