Package me.autobot.lib.hardware.serial
Class SensorHubSerialConnection
java.lang.Object
me.autobot.lib.hardware.Connection
me.autobot.lib.hardware.serial.SerialConnection
me.autobot.lib.hardware.serial.SensorHubSerialConnection
Connects to the serial port of the sensor hub.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]
The value of "HIGH" in the Arduino.static final byte[]
The value of "LOW" in the Arduino.static final int
The address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...)Fields inherited from class me.autobot.lib.hardware.serial.SerialConnection
serialVerboseLevel
-
Constructor Summary
ConstructorsConstructorDescriptionSensorHubSerialConnection
(int baudRate, String commPort) Creates a new serial connection with the given baud rate and comm port. -
Method Summary
Modifier and TypeMethodDescriptionadj()
Temporary fix for the distance sensor.static SensorHubSerialConnection
getOrCreateConnection
(int baudRate, String commPort) Gets or creates a connection to the serial device with the given ID, bus, and device.protected void
onSerialData
(byte[] data) Called when serial data is received.void
ping()
Pings the serial device.void
subscribeSensor
(Sensor sensor, int... pins) Subscribes the given sensor to the given sensor pins.void
subscribeToPin
(int pin) Sends a request to subscribe to a specific pin.void
write
(byte[] data) Writes the given data to the serial port.void
writeToPin
(int index, byte[] value) Writes a byte list to a specific pin.void
writeToPin
(int index, float value) Writes a value to a specific pin.Methods inherited from class me.autobot.lib.hardware.serial.SerialConnection
disableConnections, getBaudRate, getCommPort, open, write
-
Field Details
-
THIS_DEVICE_ADDRESS
public static final int THIS_DEVICE_ADDRESSThe address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...)- See Also:
-
HIGH
public static final byte[] HIGHThe value of "HIGH" in the Arduino. -
LOW
public static final byte[] LOWThe value of "LOW" in the Arduino.
-
-
Constructor Details
-
SensorHubSerialConnection
Creates a new serial connection with the given baud rate and comm port.- Parameters:
baudRate
- The baud rate of the serial connection.commPort
- The comm port of the serial connection.
-
-
Method Details
-
getOrCreateConnection
Gets or creates a connection to the serial device with the given ID, bus, and device.- Parameters:
baudRate
- The baud rate of the serial connection.commPort
- The serial port of the device.- Returns:
- The serial connection to the device.
-
write
public void write(byte[] data) Writes the given data to the serial port.- Overrides:
write
in classSerialConnection
- Parameters:
data
- The data to write to the serial port.
-
ping
public void ping()Pings the serial device. Won't return anything, but will let the device know that the Pi is still connected. -
subscribeToPin
public void subscribeToPin(int pin) Sends a request to subscribe to a specific pin.- Parameters:
pin
- The pin to subscribe to.
-
subscribeSensor
Subscribes the given sensor to the given sensor pins.- Parameters:
sensor
- The sensor to subscribe.pins
- The pins to subscribe the sensor to.
-
adj
Temporary fix for the distance sensor. Will be removed later.- Returns:
- This object.
-
onSerialData
protected void onSerialData(byte[] data) Called when serial data is received.- Overrides:
onSerialData
in classSerialConnection
- Parameters:
data
- The data that was received.
-
writeToPin
public void writeToPin(int index, float value) Writes a value to a specific pin. The value is a float.- Parameters:
index
- The index of the pin to write to.value
- The value to write to the pin.- See Also:
-
writeToPin
public void writeToPin(int index, byte[] value) Writes a byte list to a specific pin. Should be 4 bytes long (a float!)- Parameters:
index
- The index of the pin to write to.value
- The byte list (length=4) to write to the pin.
-