Skip to content

Minor fix in simulated driving #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading