Package lejos.hardware.sensor
Class UARTSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.UARTSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorMode,SensorModes,SampleProvider
- Direct Known Subclasses:
CodeTemplate,EV3ColorSensor,EV3GyroSensor,EV3IRSensor,EV3UltrasonicSensor
public class UARTSensor extends BaseSensor
Base class for EV3 UART based sensors. UART sensor drivers should extend this class- Author:
- andy
-
-
Field Summary
Fields Modifier and Type Field Description protected intcurrentModeprotected UARTPortport-
Fields inherited from class lejos.hardware.sensor.BaseSensor
modes
-
-
Constructor Summary
Constructors Constructor Description UARTSensor(Port port)Standard constructor for a UARTSensor initialises things and places the device into mode 0.UARTSensor(Port port, int mode)Create the sensor object and switch to the selected modeUARTSensor(UARTPort port)Standard constructor for a UARTSensor initialises things and places the device into mode 0.UARTSensor(UARTPort port, int mode)Create the sensor object and switch to the selected mode
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidswitchMode(int newMode, long switchDelay)Switch to the selected mode (if not already in that mode) and delay for the specified period to allow the sensor to settle in the new mode.-
Methods inherited from class lejos.hardware.sensor.BaseSensor
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
Field Detail
-
port
protected UARTPort port
-
currentMode
protected int currentMode
-
-
Constructor Detail
-
UARTSensor
public UARTSensor(UARTPort port)
Standard constructor for a UARTSensor initialises things and places the device into mode 0.- Parameters:
port- The port the sensor is attached to.
-
UARTSensor
public UARTSensor(Port port)
Standard constructor for a UARTSensor initialises things and places the device into mode 0.- Parameters:
port- The port the sensor is attached to.
-
UARTSensor
public UARTSensor(UARTPort port, int mode)
Create the sensor object and switch to the selected mode- Parameters:
port- The port the sensor is attached to.mode- Operating mode for the sensor.
-
UARTSensor
public UARTSensor(Port port, int mode)
Create the sensor object and switch to the selected mode- Parameters:
port- The port the sensor is attached to.mode- Operating mode for the sensor.
-
-
Method Detail
-
switchMode
protected void switchMode(int newMode, long switchDelay)Switch to the selected mode (if not already in that mode) and delay for the specified period to allow the sensor to settle in the new mode.
A mode of -1 resets the sensor. TODO: There really should be a better way to work out when the switch is complete, if you don't wait though you end up reading data from the previous mode.- Parameters:
newMode- The mode to switch to.switchDelay- Time in mS to delay after the switch.
-
-