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