Skip to content
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

SzittyaPetro implementation #8

Merged
merged 1 commit into from
Mar 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TrainControllerImpl implements TrainController {
private int step = 0;
private int referenceSpeed = 0;
private int speedLimit = 0;

private Thread trainThickThread;
@Override
public void followSpeed() {
if (referenceSpeed < 0) {
Expand All @@ -24,6 +24,33 @@ public void followSpeed() {

enforceSpeedLimit();
}
@Override
public void startTrainTickThread(int ThickInterval) throws
IllegalArgumentException{
if (trainThickThread != null){
throw new IllegalArgumentException("Thread exists already");
}
this.trainThickThread= new Thread(()->{
while (true){
synchronized(this){
followSpeed();
}
try{
Thread.sleep(ThickInterval);
}catch(InterruptedException e){
System.out.println("Thread interrupted");
}
}
});
}
@Override
public void stopTrainTickThread(){
if(trainThickThread!=null){
trainThickThread.interrupt();
trainThickThread=null;
System.out.println("Thread stopped");
}
}

@Override
public int getReferenceSpeed() {
Expand Down Expand Up @@ -51,4 +78,5 @@ public void setJoystickPosition(int joystickPosition) {
public void setEmergencyBrake(boolean EmergencyBrake){referenceSpeed=0;}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public interface TrainController {

public void setEmergencyBrake(boolean EmergencyBrake);

public void startTrainTickThread(int ThickInterval);

public void stopTrainTickThread();

}
Loading