Skip to content

Commit

Permalink
Added StepperTaskWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9849 committed Dec 25, 2023
1 parent dfca1a0 commit bf44fa4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,22 @@ public void cancel() {
@Override
protected void pumpRun() {
this.driver = stepperPump.getMotorDriver();
synchronized (driver) {
if (isRunInfinity()) {
//Pick a very large number
stepsToRun = 10000000000L;
} else if (stepsToRun == 0) {
stepsToRun = 1;
}
if (getDirection() == Direction.BACKWARD) {
driver.move(-stepsToRun);
} else {
driver.move(stepsToRun);
}
Future<Void> future = StepperTaskWorker.getInstance().submitTask(driver);
while (driver.distanceToGo() != 0 && !isCancelledExecutionThread()) {
try {
future.get();
} catch (ExecutionException | InterruptedException ignored) {}
}
if (isRunInfinity()) {
//Pick a very large number
stepsToRun = 10000000000L;
} else if (stepsToRun == 0) {
stepsToRun = 1;
}
if (getDirection() == Direction.BACKWARD) {
driver.move(-stepsToRun);
} else {
driver.move(stepsToRun);
}
Future<Void> future = StepperTaskWorker.getInstance().submitTask(driver);
while (driver.distanceToGo() != 0 && !isCancelledExecutionThread()) {
try {
future.get();
} catch (ExecutionException | InterruptedException ignored) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class PumpMaintenanceService {

private final Logger logger = LoggerFactory.getLogger(PumpMaintenanceService.class);

private final ExecutorService liveTasksExecutor;
private final ExecutorService liveTasksExecutor = Executors.newCachedThreadPool();
private final ScheduledExecutorService scheduledTasksExecutor = Executors.newSingleThreadScheduledExecutor();
private ReversePumpSettings reversePumpSettings;
private ScheduledFuture<?> automaticPumpBackTask;
Expand All @@ -58,13 +58,6 @@ public class PumpMaintenanceService {
private Direction direction = Direction.FORWARD;
private IOutputPin directionPin;

public PumpMaintenanceService() {
this.liveTasksExecutor = Executors.newCachedThreadPool(r -> {
Thread t = new Thread(r);
t.setPriority(Thread.MAX_PRIORITY);
return t;
});
}
public synchronized void postConstruct() {
configureReversePumpSettings(true);
this.stopAllPumps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public synchronized void start() {
if(Thread.interrupted()) {
return;
}
//Thread.yield();
}
}
try {
Expand Down

0 comments on commit bf44fa4

Please sign in to comment.