First round of bugfixes after new features.
This commit is contained in:
parent
96b4c5861e
commit
643dd04d6b
|
@ -19,9 +19,10 @@
|
||||||
// Velocity=5
|
// Velocity=5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MyCommandLine cli;
|
MyCommandLine cli;
|
||||||
List<IEnumerator<bool>> jobs;
|
List<IEnumerator<bool>> jobs;
|
||||||
Map<string, Door> doors;
|
Dictionary<string, Door> doors;
|
||||||
|
|
||||||
public class DoorHinge {
|
public class DoorHinge {
|
||||||
public DoorHinge(Program p, IMyMotorStator hinge) {
|
public DoorHinge(Program p, IMyMotorStator hinge) {
|
||||||
|
@ -32,12 +33,10 @@ public class DoorHinge {
|
||||||
// For these two functions, IMyMotorStator.Angle reports radians, but
|
// For these two functions, IMyMotorStator.Angle reports radians, but
|
||||||
// IMyMotorStator.RotateToAngle() expects degrees...
|
// IMyMotorStator.RotateToAngle() expects degrees...
|
||||||
public void OpenDoorHinge() {
|
public void OpenDoorHinge() {
|
||||||
foreach(IMyMotorStator hinge in Hinges) {
|
|
||||||
Hinge.RotorLock = false;
|
Hinge.RotorLock = false;
|
||||||
TargetAngle = DegToRad(OpenAngle);
|
TargetAngle = DegToRad(OpenAngle);
|
||||||
Hinge.RotateToAngle(MyRotationDirection.AUTO, OpenAngle, Velocity);
|
Hinge.RotateToAngle(MyRotationDirection.AUTO, OpenAngle, Velocity);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void CloseDoorHinge() {
|
public void CloseDoorHinge() {
|
||||||
Hinge.RotorLock = false;
|
Hinge.RotorLock = false;
|
||||||
|
@ -99,7 +98,7 @@ public class Door {
|
||||||
|
|
||||||
// Add a hinge to the door
|
// Add a hinge to the door
|
||||||
public void AddHinge(IMyMotorStator hinge) {
|
public void AddHinge(IMyMotorStator hinge) {
|
||||||
Hinges.Add(P, new DoorHinge(hinge));
|
Hinges.Add(new DoorHinge(P, hinge));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDoor() {
|
public void OpenDoor() {
|
||||||
|
@ -130,7 +129,7 @@ public class Door {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DoorHinge> hinges;
|
private List<DoorHinge> Hinges;
|
||||||
private Program P;
|
private Program P;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,17 +137,17 @@ public Program() {
|
||||||
cli = new MyCommandLine();
|
cli = new MyCommandLine();
|
||||||
jobs = new List<IEnumerator<bool>>();
|
jobs = new List<IEnumerator<bool>>();
|
||||||
|
|
||||||
doors = new Map<string, Door>();
|
doors = new Dictionary<string, Door>();
|
||||||
|
|
||||||
List<IMyMotorStator> allHinges = new List<IMyMotorStator>();
|
List<IMyMotorStator> allHinges = new List<IMyMotorStator>();
|
||||||
GridTerminalSystem.GetBlocksOfType(allHinges);
|
GridTerminalSystem.GetBlocksOfType(allHinges);
|
||||||
foreach(IMyMotorStator hinge in allHinges) {
|
foreach(IMyMotorStator hinge in allHinges) {
|
||||||
if (hinge.CustomName.StartsWith("Door")) {
|
if (hinge.CustomName.StartsWith("Door")) {
|
||||||
string doorName = hinge.CustomName;
|
string doorName = hinge.CustomName;
|
||||||
if (!hingeMap.ContainsKey(doorName)) {
|
if (!doors.ContainsKey(doorName)) {
|
||||||
hingeMap[doorName] = new Door(this);
|
doors[doorName] = new Door(this);
|
||||||
}
|
}
|
||||||
hingeMap[doorName].AddHinge(hinge);
|
doors[doorName].AddHinge(hinge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,12 +155,13 @@ public Program() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Main(string argument, UpdateType updateSource) {
|
public void Main(string argument, UpdateType updateSource) {
|
||||||
if (updateSource & (UpdateType.Trigger | UpdateType.Terminal)) {
|
if (updateSource == UpdateType.Trigger || updateSource == UpdateType.Terminal) {
|
||||||
// Create a new job
|
// Create a new job
|
||||||
cli.TryParse(argument);
|
cli.TryParse(argument);
|
||||||
|
|
||||||
List<Door> doorsToControl = new List<Door>();
|
List<Door> doorsToControl = new List<Door>();
|
||||||
foreach (string arg in argument) {
|
for (int i=0; i < cli.ArgumentCount; i++) {
|
||||||
|
string arg = cli.Argument(i);
|
||||||
if (!doors.ContainsKey($"Door{arg}")) {
|
if (!doors.ContainsKey($"Door{arg}")) {
|
||||||
Echo($"Door with identifier {arg} not found. Skipping.");
|
Echo($"Door with identifier {arg} not found. Skipping.");
|
||||||
continue;
|
continue;
|
||||||
|
@ -173,7 +173,7 @@ public void Main(string argument, UpdateType updateSource) {
|
||||||
doorsToControl.Add(doors[arg]);
|
doorsToControl.Add(doors[arg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doorsToControl.IsEmpty) {
|
if (doorsToControl.Count == 0) {
|
||||||
Echo("No doors found. Not creating new job.");
|
Echo("No doors found. Not creating new job.");
|
||||||
} else {
|
} else {
|
||||||
Echo("Creating new job.");
|
Echo("Creating new job.");
|
||||||
|
@ -192,28 +192,28 @@ public void Main(string argument, UpdateType updateSource) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jobs.IsEmpty) {
|
if (jobs.Count == 0) {
|
||||||
Runtime.UpdateFrequency = UpdateFrequency.None;
|
Runtime.UpdateFrequency = UpdateFrequency.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator<bool> OpenDoors(List<Door> doorsToControl) {
|
private IEnumerator<bool> OpenDoors(List<Door> doorsToControl) {
|
||||||
Echo("Opening doors.");
|
Echo("Opening doors.");
|
||||||
foreach (Door door in doors) {
|
foreach (Door door in doorsToControl) {
|
||||||
door.OpenDoor();
|
door.OpenDoor();
|
||||||
}
|
}
|
||||||
return ActuateDoors(doorsToCotrol);
|
return ActuateDoors(doorsToControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator<bool> CloseDoors(List<Door> doorsToControl) {
|
private IEnumerator<bool> CloseDoors(List<Door> doorsToControl) {
|
||||||
Echo("Closing doors.");
|
Echo("Closing doors.");
|
||||||
foreach (Door door in doorsToControl) {
|
foreach (Door door in doorsToControl) {
|
||||||
panel.CloseDoor();
|
door.CloseDoor();
|
||||||
}
|
}
|
||||||
return ActuateDoors(doorsToControl);
|
return ActuateDoors(doorsToControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator<bool> ActuateDoors(doorsToControl) {
|
private IEnumerator<bool> ActuateDoors(List<Door> doorsToControl) {
|
||||||
while (true) {
|
while (true) {
|
||||||
Echo("Actuating doors.");
|
Echo("Actuating doors.");
|
||||||
bool done = true; // assume we've finished, then falsify it below
|
bool done = true; // assume we've finished, then falsify it below
|
||||||
|
|
Loading…
Reference in New Issue
Block a user