All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.silverspoon.bulldog.devices.motor.AbstractStepper Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package io.silverspoon.bulldog.devices.motor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import io.silverspoon.bulldog.devices.actuators.Actuator;
import io.silverspoon.bulldog.devices.actuators.movement.Move;

public abstract class AbstractStepper implements Actuator {

   private ExecutorService executor = Executors.newSingleThreadExecutor();
   private Future currentMove = null;

   public abstract void forward();

   public abstract void backward();

   public abstract void stop();

   public void move(Move move) {
      move.execute(this);
   }

   public void moveAsync(final Move move) {
      currentMove = executor.submit(new Runnable() {

         @Override
         public void run() {
            move(move);
         }

      });
   }

   public void awaitMoveCompleted() {
      if (currentMove != null) {
         try {
            currentMove.get();
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy