lejos.hardware.sensor.MindSensorsPressureSensor Maven / Gradle / Ivy
Show all versions of lejos-ev3-api Show documentation
package lejos.hardware.sensor;
import lejos.hardware.port.I2CPort;
import lejos.hardware.port.Port;
import lejos.utility.EndianTools;
/**
* MindSensors Pressure Sensor
* This sensor measures pressures produced by LEGO Pneumatics systems and lot more!
*
*
* The code for this sensor has not been tested. Please report test results to
* the leJOS forum.
*
*
*
*
*
* Supported modes
*
*
* Mode name
* Description
* unit(s)
* Getter
*
*
* Pressure
* Measures the absolute pressure
* Pascal
* {@link #getPressureMode() }
*
*
*
*
*
* Sensor configuration
* Description of default sensor configuration (when that matters). Description
* of available methods for configuration.
*
*
*
* See Sensor datasheet
* See Sensor Product page
* See The
* leJOS sensor framework
* See {@link lejos.robotics.SampleProvider leJOS conventions for
* SampleProviders}
*
*
*
*
* @author fussel_dlx
*
*/
public class MindSensorsPressureSensor extends I2CSensor {
/*
* Code contributed and tested by fussel_dlx on the forums:
* http://lejos.sourceforge.net/forum/viewtopic.php?f=6&t=4329
*
* Comment: the sensor can pressure in various units. However, using those
* units results in a loss of precision. And furthermore, the conversion to PSI or
* whatever can be done in Java. The obvious advantage is, that float can be used.
*/
private static final int ADDRESS = 0x18;
private final byte[] buf = new byte[4];
public MindSensorsPressureSensor(I2CPort port) {
// also works with high speed mode
super(port, ADDRESS);
init();
}
public MindSensorsPressureSensor(Port port) {
// also works with high speed mode
super(port, ADDRESS);
init();
}
protected void init() {
setModes(new SensorMode[]{ new PressureMode() });
}
/**
* Return a ample provider for pressure mode. Pressure is expressed in Pascal.
*/
public SensorMode getPressureMode() {
return getMode(0);
}
private class PressureMode implements SensorMode {
@Override
public int sampleSize() {
return 1;
}
@Override
public void fetchSample(float[] sample, int offset) {
getData(0x53, buf, 0, 4);
sample[offset] = EndianTools.decodeIntLE(buf, 0);
}
@Override
public String getName() {
return "Pressure";
}
}
}