本文整理汇总了Java中lejos.hardware.port.Port类的典型用法代码示例。如果您正苦于以下问题:Java Port类的具体用法?Java Port怎么用?Java Port使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Port类属于lejos.hardware.port包,在下文中一共展示了Port类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initRegulatedMotor
import lejos.hardware.port.Port; //导入依赖的package包/类
private void initRegulatedMotor(ActorPort actorPort, Actor actorType, Port hardwarePort) {
this.lcd.clear();
// Hal.formatInfoMessage("Initializing motor on port " + actorPort, this.lcd);
switch ( actorType.getName() ) {
case LARGE:
this.lejosRegulatedMotors.put(actorPort, new EV3LargeRegulatedMotor(hardwarePort));
break;
case MEDIUM:
this.lejosRegulatedMotors.put(actorPort, new EV3MediumRegulatedMotor(hardwarePort));
break;
case REGULATED:
this.lejosRegulatedMotors.put(actorPort, new NXTRegulatedMotor(hardwarePort));
break;
default:
throw new DbcException("Actor type " + actorType.getName() + " does not exists!");
}
}
示例2: getActualSensorConfig
import lejos.hardware.port.Port; //导入依赖的package包/类
/**
* Initialise sensor ports and retrieve their modename.<br>
*
* @return sensorname per port in an array
*/
private String[] getActualSensorConfig() {
int sensorCount = 4;
String[] actualSensorConfig = new String[sensorCount];
Port[] p = new Port[sensorCount];
p[0] = LocalEV3.get().getPort("S1");
p[1] = LocalEV3.get().getPort("S2");
p[2] = LocalEV3.get().getPort("S3");
p[3] = LocalEV3.get().getPort("S4");
for ( int i = 0; i < actualSensorConfig.length; i++ ) {
actualSensorConfig[i] = getSensorName(p[i]).trim(); // remove spaces
// map the sensor mode names to lejos sensor class names!
actualSensorConfig[i] = this.sensorModes.getProperty(actualSensorConfig[i]);
}
return actualSensorConfig;
}
示例3: BasicMotor
import lejos.hardware.port.Port; //导入依赖的package包/类
/**
* Constructor
*
* @param motorPort port
*/
public BasicMotor(final Port motorPort) {
if(!this.getPlatform().equals(EV3DevPlatform.EV3BRICK)){
throw new RuntimeException("This device is not supported in this platform");
}
final String port = this.getMotorPort(motorPort);
log.debug("Detecting motor on port: {}", port);
this.detect(LEGO_PORT, port);
log.debug("Setting port in mode: {}", DC_MOTOR);
this.setStringAttribute(MODE, DC_MOTOR);
Delay.msDelay(500);
this.detect(DC_MOTOR, port);
}
示例4: EV3DevSensorDevice
import lejos.hardware.port.Port; //导入依赖的package包/类
/**
* Every device connected in a EV3 Brick with EV3Dev appears in /sys/class in a determinated category.
* It is necessary to indicate the type and ports.
*
* @param portName The ports where is connected the sensors or the actuators.
* @param mode mode
* @param device device
*/
protected EV3DevSensorDevice(final Port portName, final String mode, final String device) {
final String port = this.getSensorPort(portName);
//EV3 Brick detect in a automatic way the sensors
if(this.getPlatform().equals(EV3DevPlatform.EV3BRICK)){
this.detect(LEGO_SENSOR, port);
}else {
//With Pi Boards, it is necessary to detect in 2 paths the sensors
this.detect(LEGO_PORT, port);
log.info("detected lego port: {}", this.PATH_DEVICE);
this.setStringAttribute(MODE, mode);
this.setStringAttribute(DEVICE, device);
Delay.msDelay(1000);
this.detect(LEGO_SENSOR, port);
log.info("detected lego sensor: {}", this.PATH_DEVICE);
}
}
示例5: getSensorPort
import lejos.hardware.port.Port; //导入依赖的package包/类
private static Port getSensorPort(String p) throws EV3ScriptException {
switch (p) {
case "1":
case EV3Constants.S1:
return SensorPort.S1;
case "2":
case EV3Constants.S2:
return SensorPort.S2;
case "3":
case EV3Constants.S3:
return SensorPort.S3;
case "4":
case EV3Constants.S4:
return SensorPort.S4;
}
throw new EV3ScriptException(EV3ScriptException.INVALID_SENSOR_PORT, MapBuilder.buildHashMap("port", p).build());
}
示例6: SimpleEV3ColorSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public SimpleEV3ColorSensor(Port port) {
delegate = new EV3ColorSensor(port);
logger = SensorMonitorFactory.getLogger(port);
// Reflected light mode
reflectedLightMode = delegate.getRedMode();
reflectedLightSample = new float[reflectedLightMode.sampleSize()];
// Ambient light mode
ambientLightMode = delegate.getAmbientMode();
ambientLightSample = new float[ambientLightMode.sampleSize()];
// Color mode
colorMode = delegate.getColorIDMode();
colorModeSample = new float[colorMode.sampleSize()];
}
示例7: RMIRemoteSampleProvider
import lejos.hardware.port.Port; //导入依赖的package包/类
protected RMIRemoteSampleProvider(String portName, String sensorName, String modeName) throws RemoteException {
super(0);
try {
Class<?> c = Class.forName(sensorName);
Class<?>[] params = new Class<?>[1];
params[0] = Port.class;
Constructor<?> con = c.getConstructor(params);
Object[] args = new Object[1];
args[0] = LocalEV3.get().getPort(portName);
Object obj = con.newInstance(args);
provider = (SampleProvider) obj;
closer = (Closeable) obj;
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: MediumRegulatedMotor
import lejos.hardware.port.Port; //导入依赖的package包/类
public MediumRegulatedMotor(Port motorPort) throws IOException {
super(motorPort);
this.motor = createMotor(motorPort);
this.motortype = Motors.MediumRegulatedMotor;
this.motorState = new RegulatedMotorMessages.MotorState();
}
示例9: EV3UltrasonicSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public EV3UltrasonicSensor(Port sensorPort, SensorMessages.SensorMode_ mode) {
super(SensorSampleRates.SENS_ULTRASONIC_SAMPLERATE);
isSensorCreated = create(sensorPort, Sensors.EV3UltrasonicSensor,mode); //Creates Lejos.EV3ColorSensor. acceptable
if(isSensorCreated){
sendSensorData();
}
System.out.println(toString());;
}
示例10: EV3IRSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public EV3IRSensor(Port sensorPort, SensorMessages.SensorMode_ mode) {
super(SensorSampleRates.SENS_IR_SAMPLERATE);
isSensorCreated = create(sensorPort, Sensors.EV3IRSensor,mode); //Creates Lejos.EV3ColorSensor. acceptable
if(isSensorCreated){
sendSensorData();
}
System.out.println(toString());;
}
示例11: EV3TouchSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public EV3TouchSensor(Port sensorPort, SensorMessages.SensorMode_ mode) {
super(SensorSampleRates.SENS_TOUCH_SAMPLERATE);
isSensorCreated = create(sensorPort, Sensors.EV3TouchSensor,mode); //Creates Lejos.EV3ColorSensor. acceptable
if(isSensorCreated){
sendSensorData();
}
System.out.println(toString());;
}
示例12: EV3GyroSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public EV3GyroSensor(Port sensorPort, SensorMessages.SensorMode_ mode) {
super(SensorSampleRates.SENS_GYRO_SAMPLERATE);
isSensorCreated = create(sensorPort, Sensors.EV3GyroSensor,mode); //Creates Lejos.EV3ColorSensor. acceptable
if(isSensorCreated){
sendSensorData();
}
System.out.println(toString());;}
示例13: EV3ColorSensor
import lejos.hardware.port.Port; //导入依赖的package包/类
public EV3ColorSensor(Port sensorPort,SensorMessages.SensorMode_ mode){
super(SensorSampleRates.SENS_COLOR_SAMPLERATE);
isSensorCreated = create(sensorPort,Sensors.EV3ColorSensor,mode); //Creates Lejos.EV3ColorSensor. acceptable
if(isSensorCreated){
sendSensorData();
}
System.out.println(toString());;
}
示例14: create
import lejos.hardware.port.Port; //导入依赖的package包/类
protected boolean create(Port sensorPort,Sensors sensortype,SensorMessages.SensorMode_ sensormode) {
assert sensortype != null && sensorPort != null && sensormode != null;
this.sensorPort = sensorPort;
switch(sensortype){
case EV3ColorSensor:
this.sensor = new EV3ColorSensor(sensorPort);
this.sensortype = Sensors.EV3ColorSensor;
break;
case EV3UltrasonicSensor:
this.sensor = new EV3UltrasonicSensor(sensorPort);
this.sensortype = Sensors.EV3UltrasonicSensor;
break;
case EV3GyroSensor:
this.sensor = new EV3GyroSensor(sensorPort);
this.sensortype = Sensors.EV3GyroSensor;
break;
case EV3IRSensor:
this.sensor = new EV3IRSensor(sensorPort);
this.sensortype = Sensors.EV3IRSensor;
break;
case EV3TouchSensor:
this.sensor = new EV3TouchSensor(sensorPort);
this.sensortype = Sensors.EV3TouchSensor;
break;
default: return false;
}
if(sensor != null && setSensorMode(sensormode)){
this.sensormode = sensormode;
}
return true;
}
示例15: createMotorEndpoint
import lejos.hardware.port.Port; //导入依赖的package包/类
/**
*
* @param port
* @param motorType
* @param networkPort
* @throws IOException
*/
private boolean createMotorEndpoint(Port port, Motors motorType, int networkPort) {
try {
return mm.createMotorEndpoint(port,motorType,networkPort);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}