public class BaseSensor extends EV3DevSensorDevice
Modifier and Type | Field and Description |
---|---|
protected int |
currentMode |
private java.util.ArrayList<java.lang.String> |
modeList |
protected SensorMode[] |
modes |
static int |
SWITCH_DELAY |
LEGO_ANALOG_SENSOR, LEGO_I2C, LEGO_UART_SENSOR, SENSOR_MODE, SENSOR_MODES
ADDRESS, CURRENT_PLATFORM, DEVICE, ev3DevProperties, LEGO_PORT, LEGO_SENSOR, MODE, PATH_DEVICE
Constructor and Description |
---|
BaseSensor(Port sensorPort,
java.lang.String mode) |
BaseSensor(Port sensorPort,
java.lang.String mode,
java.lang.String device) |
Modifier and Type | Method and Description |
---|---|
void |
fetchSample(float[] sample,
int offset)
Set the current SensorMode index.
|
java.util.ArrayList<java.lang.String> |
getAvailableModes() |
int |
getCurrentMode() |
private int |
getIndex(java.lang.String modeName) |
SensorMode |
getMode(int mode)
Get a SensorMode associated with a mode index.
|
SensorMode |
getMode(java.lang.String modeName)
Get a SensorMode associated with a mode name.
|
int |
getModeCount() |
java.lang.String |
getName() |
protected java.lang.String |
getSystemMode()
Read current sensor mode from the kernel.
|
private boolean |
modeInvalid(int mode) |
int |
sampleSize() |
void |
setCurrentMode(int mode)
Set the current SensorMode index.
|
void |
setCurrentMode(java.lang.String modeName)
Set the current SensorMode name.
|
protected void |
setModes(SensorMode[] m)
Define the set of modes to be made available for this sensors.
|
private void |
setSystemMode(java.lang.String mode)
Write requested sensor mode to the kernel.
|
void |
switchMode(java.lang.String newMode,
long switchDelay)
Switch the sensor to the specified mode, if necessary.
|
detect, getIntegerAttribute, getStringAttribute, setIntegerAttribute, setStringAttribute
public static final int SWITCH_DELAY
private java.util.ArrayList<java.lang.String> modeList
protected int currentMode
protected SensorMode[] modes
public BaseSensor(Port sensorPort, java.lang.String mode, java.lang.String device)
public BaseSensor(Port sensorPort, java.lang.String mode)
protected void setModes(SensorMode[] m)
m
- An array containing a list of modespublic java.util.ArrayList<java.lang.String> getAvailableModes()
public SensorMode getMode(int mode)
WARNING: This function does not
switch the sensor to the correct mode. Unless the sensor is
switched to the correct mode, the reads from this SensorMode
will be invalid.
See GenericMode.fetchSample(float[], int)
public SensorMode getMode(java.lang.String modeName)
WARNING: This function does not
switch the sensor to the correct mode. Unless the sensor is
switched to the correct mode, the reads from this SensorMode
will be invalid.
See GenericMode.fetchSample(float[], int)
private boolean modeInvalid(int mode)
private int getIndex(java.lang.String modeName)
public java.lang.String getName()
public int sampleSize()
public void fetchSample(float[] sample, int offset)
WARNING: this function works properly only when
the sensor is already in the appropriate mode. This means
that the returned reading will be valid only when
you previously activated the "current mode" via a call
to get*Mode() or switchMode().
See GenericMode.fetchSample(float[], int)
sample
- The array to store the sample in.offset
- The elements of the sample are stored in the array starting at the offset position.public void setCurrentMode(int mode)
WARNING: This function does not
switch the sensor to the correct mode. Unless the sensor is
switched to the correct mode, the reads from the"current" SensorMode
will be invalid.
See GenericMode.fetchSample(float[], int)
public int getCurrentMode()
public void setCurrentMode(java.lang.String modeName)
WARNING: This function does not
switch the sensor to the correct mode. Unless the sensor is
switched to the correct mode, the reads from the"current" SensorMode
will be invalid.
See GenericMode.fetchSample(float[], int)
public int getModeCount()
protected java.lang.String getSystemMode()
private void setSystemMode(java.lang.String mode)
mode
- Sensor mode identifier.public void switchMode(java.lang.String newMode, long switchDelay)
Note: the mode switch will make future reads from
SensorModes for other modes invalid. On the other hand, it will
make reads valid for the SensorMode associated with the mode the
sensor is switching to.
See GenericMode.fetchSample(float[], int)
newMode
- Identifier of the sensor mode (not its name).switchDelay
- Delay until the sensor starts sending new data.