Skip to content

Commit

Permalink
Merge pull request #92 from fransjacobs/67-error-when-recreating-sens…
Browse files Browse the repository at this point in the history
…ors-when-the-sensor-is-also-linked-to-a-block

Minor fix in simulated driving
  • Loading branch information
fransjacobs authored Sep 21, 2024
2 parents 00fe984 + 96b2561 commit 31fa334
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/main/java/jcs/commandStation/autopilot/AutoPilot.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public final class AutoPilot {
private AutoPilot() {
}

public static void runAutoPilot(boolean flag) {
if (flag) {
executor.execute(() -> startAutoMode());
} else {
executor.execute(() -> stopAutoMode());
}
}

public synchronized static void startAutoMode() {
if (JCS.getJcsCommandStation().isPowerOn()) {
if (autoPilotThread != null && autoPilotThread.isRunning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,7 @@ public void changeVelocity(int locUid, int speed, LocomotiveBean.Direction direc
if (AutoPilot.isAutoModeActive() && speed > 0) {
simulateDriving(locUid, speed, direction);
}

});

//When a locomotive has a speed change (>0) check if Auto mode is on.
//When in Auto mode try to simulate the first sensor the locomotive is suppose to hit.
// if (AutoPilot.getInstance().isAutoModeActive() && speed > 0) {
// this.executor.execute(() -> simulateDriving(locUid, speed, direction));
// }
} else {
if (!this.power) {
Logger.warn("Can't change velocity locUid: " + locUid + " Power is OFF!");
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/jcs/ui/layout/LayoutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,16 +1007,15 @@ private void autoPilotBtnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_aut

if (this.autoPilotBtn.isSelected()) {
this.startAllLocomotivesBtn.setEnabled(true);

AutoPilot.startAutoMode();
} else {
if (this.startAllLocomotivesBtn.isSelected()) {
startAllLocomotivesBtn.doClick();
}
this.startAllLocomotivesBtn.setEnabled(false);

AutoPilot.stopAutoMode();
}

AutoPilot.runAutoPilot(this.autoPilotBtn.isSelected());

}//GEN-LAST:event_autoPilotBtnActionPerformed

private void startAllLocomotivesBtnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_startAllLocomotivesBtnActionPerformed
Expand Down

0 comments on commit 31fa334

Please sign in to comment.