Package lejos.hardware.sensor
Class BaseSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorMode,SensorModes,SampleProvider
- Direct Known Subclasses:
AnalogSensor,DexterIMUSensor,I2CSensor,UARTSensor
public class BaseSensor extends Device implements SensorModes
-
-
Field Summary
Fields Modifier and Type Field Description protected intcurrentModeprotected SensorMode[]modes
-
Constructor Summary
Constructors Constructor Description BaseSensor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfetchSample(float[] sample, int offset)Fetches a sample from a sensor or filter.java.util.ArrayList<java.lang.String>getAvailableModes()Return a list of string descriptions for the sensors available modes.intgetCurrentMode()Gets the index number of the current mode.SensorModegetMode(int mode)Return the sample provider interface for the requested modeSensorModegetMode(java.lang.String modeName)Return the sample provider for the request modeintgetModeCount()Gets the number of supported modesjava.lang.StringgetName()return a string description of this sensor modeintsampleSize()Returns the number of elements in a sample.
The number of elements does not change during runtime.voidsetCurrentMode(int mode)Sets the current mode for fetching samplesvoidsetCurrentMode(java.lang.String modeName)Sets the current mode for fetching samplesprotected voidsetModes(SensorMode[] m)Define the set of modes to be made available for this sensor.-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
Field Detail
-
currentMode
protected int currentMode
-
modes
protected SensorMode[] modes
-
-
Method Detail
-
setModes
protected void setModes(SensorMode[] m)
Define the set of modes to be made available for this sensor.- Parameters:
m- An array containing a list of modes
-
getAvailableModes
public java.util.ArrayList<java.lang.String> getAvailableModes()
Description copied from interface:SensorModesReturn a list of string descriptions for the sensors available modes.- Specified by:
getAvailableModesin interfaceSensorModes- Returns:
- list of string descriptions
-
getMode
public SensorMode getMode(int mode)
Description copied from interface:SensorModesReturn the sample provider interface for the requested mode- Specified by:
getModein interfaceSensorModes- Parameters:
mode- the mode number- Returns:
- the sample provider for this mode
-
getMode
public SensorMode getMode(java.lang.String modeName)
Description copied from interface:SensorModesReturn the sample provider for the request mode- Specified by:
getModein interfaceSensorModes- Parameters:
modeName- the name/description of the mode- Returns:
- the sample provider for the requested mode.
-
getName
public java.lang.String getName()
Description copied from interface:SensorModereturn a string description of this sensor mode- Specified by:
getNamein interfaceSensorMode- Returns:
- The description/name of this mode
-
sampleSize
public int sampleSize()
Description copied from interface:SampleProviderReturns the number of elements in a sample.
The number of elements does not change during runtime.- Specified by:
sampleSizein interfaceSampleProvider- Returns:
- the number of elements in a sample
-
fetchSample
public void fetchSample(float[] sample, int offset)Description copied from interface:SampleProviderFetches a sample from a sensor or filter.- Specified by:
fetchSamplein interfaceSampleProvider- Parameters:
sample- The array to store the sample in.offset- The elements of the sample are stored in the array starting at the offset position.
-
setCurrentMode
public void setCurrentMode(int mode)
Description copied from interface:SensorModesSets the current mode for fetching samples- Specified by:
setCurrentModein interfaceSensorModes- Parameters:
mode- the index number of the mode. Index number corresponds with the item order of the list from getAvailableModes().
-
setCurrentMode
public void setCurrentMode(java.lang.String modeName)
Description copied from interface:SensorModesSets the current mode for fetching samples- Specified by:
setCurrentModein interfaceSensorModes- Parameters:
modeName- the name of the mode. name corresponds with the item value of the list from getAvailableModes().
-
getCurrentMode
public int getCurrentMode()
Description copied from interface:SensorModesGets the index number of the current mode.- Specified by:
getCurrentModein interfaceSensorModes- Returns:
- the index number of the mode. Index number corresponds with the item order of the list from getAvailableModes().
-
getModeCount
public int getModeCount()
Description copied from interface:SensorModesGets the number of supported modes- Specified by:
getModeCountin interfaceSensorModes- Returns:
- the number of supported modes
-
-