Class SensorHubSerialConnection


public class SensorHubSerialConnection extends SerialConnection
Connects to the serial port of the sensor hub.
  • Field Details

    • THIS_DEVICE_ADDRESS

      public static final int THIS_DEVICE_ADDRESS
      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...)
      See Also:
    • HIGH

      public static final byte[] HIGH
      The value of "HIGH" in the Arduino.
    • LOW

      public static final byte[] LOW
      The value of "LOW" in the Arduino.
  • Constructor Details

    • SensorHubSerialConnection

      public SensorHubSerialConnection(int baudRate, String commPort)
      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

      public static SensorHubSerialConnection getOrCreateConnection(int baudRate, String commPort)
      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 class SerialConnection
      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

      public void subscribeSensor(Sensor sensor, int... pins)
      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 class SerialConnection
      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.