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

lejos.hardware.sensor.MindSensorsPressureSensor Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
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 nameDescriptionunit(s)Getter
PressureMeasures the absolute pressurePascal {@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"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy