Package com.cos399.sumo.sensors

Source Code of com.cos399.sumo.sensors.Ultrasonic

/*
*
*/

package com.cos399.sumo.sensors;

import com.cos399.sumo.utils.SumoDataExchange;

import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;

public class Ultrasonic extends Thread {

  private static Ultrasonic ultrasonic = null;
  private static UltrasonicSensor us = null;
  private static SensorPort port = null;
  private static SumoDataExchange de = null;
 
  private Ultrasonic () { }
 
  public static Ultrasonic getInstance() {
    if (ultrasonic == null) {
      ultrasonic = new Ultrasonic();
      us = new UltrasonicSensor(port);
      us.setMode(2); //set to continuous
      de = SumoDataExchange.getInstance();
    }
   
    return ultrasonic;
  }
 
  public static Ultrasonic getInstance(SensorPort port) {
    Ultrasonic.port = port;
   
    return getInstance();
  }
 
  public void setPort(SensorPort port){
    Ultrasonic.port = port;
  }
 
  public void setContinuous() {
    us.continuous();
    de.setUltrasonicMode(2);
  }
 
  public void setCapture() {
    us.capture();
    de.setUltrasonicMode(3);
  }
 
  public void setPing() {
    us.ping();
    de.setUltrasonicMode(1);
   
  }
 
  public void setOff() {
    us.off();
    de.setUltrasonicMode(0);
  }
 
  @Override
  public void run() {
    while(true) {
      de.setUltrasonicDistance(us.getDistance());
    }
  }
 
}
TOP

Related Classes of com.cos399.sumo.sensors.Ultrasonic

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.