Class MCP23S17.PinView

java.lang.Object
ch.ladestation.connectncharge.pui.MCP23S17.PinView
Enclosing class:
MCP23S17

public final class MCP23S17.PinView extends Object
An abstraction of each physical GPIO pin on a MCP23S17 IO expander chip.
Author:
Robert Russell
See Also:
  • Method Details

    • getPin

      public MCP23S17.Pin getPin()
      Get the Pin which this PinView represents.
      Returns:
      the Pin which this PinView represents.
    • get

      public boolean get()
      Get the state of the pin. If the pin is output, then the corresponding bit in the corresponding OLATx byte is returned (note: not the actual value in the MCP23S17's OLATx register). If the pin in input, then the actual value at the pin is read and returned.
      Returns:
      the state of the pin.
    • getFromRead

      public boolean getFromRead() throws IOException
      Throws:
      IOException
    • set

      public void set(boolean value)
      Set the pin to the given state. More specifically, this sets the corresponding bit in the corresponding OLATx byte (note: not the actual value in the MCP23S17's OLATx register) to the given state.
      Parameters:
      value - the value to set on the pin.
    • set

      public void set()
      Sets the pin high. More specifically, this sets the corresponding bit in the corresponding OLATx byte (note: not the actual value in the MCP23S17's OLATx register).
    • clear

      public void clear()
      Clears the pin (sets it low). More specifically, this clears the corresponding bit in the corresponding OLATx byte (note: not the actual value in the MCP23S17's OLATx register).
    • isInput

      public boolean isInput()
      Get whether or not this pin is input. More specifically, this returns the corresponding bit in the corresponding IODIRx byte (note: not the actual value in the MCP23S17's IODIRx register).
      Returns:
      whether or not this pin is input.
    • isOutput

      public boolean isOutput()
      Get whether or not this pin is output. More specifically, this returns the inverse of the corresponding bit in the corresponding IODIRx byte (note: not the actual value in the MCP23S17's IODIRx register).
      Returns:
      whether or not this pin is output.
    • setDirection

      public void setDirection(boolean input)
      Set the pin to the given direction. More specifically, this sets the corresponding bit in the corresponding IODIRx byte (note: not the actual value in the MCP23S17's IODIRx register) if the pin direction is input, and clears it if the pin direction is output.
      Parameters:
      input - true for input; false for output.
    • setAsInput

      public void setAsInput()
      Set the pin to be input. More specifically, this sets the corresponding bit in the corresponding IODIRx byte (note: not the actual value in the MCP23S17's IODIRx register).
    • setAsOutput

      public void setAsOutput()
      Set the pin to be output. More specifically, this clears the corresponding bit in the corresponding IODIRx byte (note: not the actual value in the MCP23S17's IODIRx register).
    • isInputInverted

      public boolean isInputInverted()
      Get whether or not this pin's input is inverted. More specifically, this returns the corresponding bit in the corresponding IPOLx byte (note: not the actual value in the MCP23S17's IPOLx register).
      Returns:
      whether or not this pin's input os inverted.
    • setInverted

      public void setInverted(boolean inverted)
      Set whether or not the pin's input is inverted. More specifically, this sets the corresponding bit in the corresponding IPOLx byte (note: not the actual value in the MCP23S17's IPOLx register) if the pin's input is to be inverted, and clears it if the pin's input is to not be inverted.
      Parameters:
      inverted - whether or not the pin's input is to be inverted.
    • invertInput

      public void invertInput()
      Set the pin's input to be inverted. More specifically, this sets the corresponding bit in the corresponding IPOLx byte (note: not the actual value in the MCP23S17's IPOLx register).
    • uninvertInput

      public void uninvertInput()
      Set the pin's input to not be inverted. More specifically, this clears the corresponding bit in the corresponding IPOLx byte (note: not the actual value in the MCP23S17's IPOLx register).
    • isInterruptEnabled

      public boolean isInterruptEnabled()
      Get whether or not this pin's interrupt is enabled. More specifically, this returns the corresponding bit in the corresponding GPINTENx byte (note: not the actual value in the MCP23S17's GPINTENx register).
      Returns:
      whether or not this pin's interrupt is enabled.
    • setInterruptEnabled

      public void setInterruptEnabled(boolean interruptEnabled)
      Set whether or not the pin's interrupt is enabled. More specifically, this sets the corresponding bit in the corresponding GPINTENx byte (note: not the actual value in the MCP23S17's GPINTENx register) if interrupts are enabled, and clears it if interrupts are disabled.
      Parameters:
      interruptEnabled - whether or not to enable interrupts.
    • enableInterrupt

      public void enableInterrupt()
      Enable the pin's interrupts. More specifically, this sets the corresponding bit in the corresponding GPINTENx byte (note: not the actual value in the MCP23S17's GPINTENx register).
    • disableInterrupt

      public void disableInterrupt()
      Disable the pin's interrupts. More specifically, this clears the corresponding bit in the corresponding GPINTENx byte (note: not the actual value in the MCP23S17's GPINTENx register).
    • getDefaultComparisonValue

      public boolean getDefaultComparisonValue()
      Get the default comparison value for comparison interrupt mode for this pin. More specifically, this returns the corresponding bit in the corresponding DEFVALx byte (note: not the actual value in the MCP23S17's DEFVALx register).
      Returns:
      the default comparison value for comparison interrupt mode for this pin.
    • setDefaultComparisonValue

      public void setDefaultComparisonValue(boolean value)
      Set the default comparison value for comparison interrupt mode for this pin. More specifically, this sets the corresponding bit in the corresponding DEFVALx byte (note: not the actual value in the MCP23S17's DEFVALx register) to the given value.
      Parameters:
      value - the default comparison value for comparison interrupt mode for this pin.
    • isInterruptComparisonMode

      public boolean isInterruptComparisonMode()
      Get whether or not this pin is in interrupt comparison mode (as opposed to change mode). More specifically, this returns the corresponding bit in the corresponding INTCONx byte (note: not the actual value in the MCP23S17's INTCONx register).
      Returns:
      whether or not this pin is in interrupt comparison mode.
    • isInterruptChangeMode

      public boolean isInterruptChangeMode()
      Get whether or not this pin is in interrupt change mode (as opposed to comparison mode). More specifically, this returns the inverse of the corresponding bit in the corresponding INTCONx byte (note: not the actual value in the MCP23S17's INTCONx register).
      Returns:
      whether or not this pin is in interrupt change mode.
    • setInterruptMode

      public void setInterruptMode(boolean comparison)
      Set the interrupt mode for this pin. More specifically, this sets the corresponding bit in the corresponding INTCONx byte (note: not the actual value in the MCP23S17's INTCONx register) if transitioning to comparison mode, and clears it if transitioning to change mode.
      Parameters:
      comparison - true for comparison mode; false for change mode.
    • toInterruptComparisonMode

      public void toInterruptComparisonMode()
      Set the interrupt mode to comparison mode. More specifically, this sets the corresponding bit in the corresponding INTCONx byte (note: not the actual value in the MCP23S17's INTCONx register).
    • toInterruptChangeMode

      public void toInterruptChangeMode()
      Set the interrupt mode to change mode. More specifically, this clears the corresponding bit in the corresponding INTCONx byte (note: not the actual value in the MCP23S17's INTCONx register).
    • isPulledUp

      public boolean isPulledUp()
      Get whether or not this pin has a pull-up resistor enabled. More specifically, this returns the corresponding bit in the corresponding GPPUx byte (note: not the actual value in the MCP23S17's GPPUx register).
      Returns:
      whether or not this pin has a pull-up resistor enabled.
    • setPulledUp

      public void setPulledUp(boolean pulledUp)
      Set whether or not this pin has a pull-up resistor enabled. More specifically, this sets the corresponding bit in the corresponding GPPUx byte (note: not the actual value in the MCP23S17's GPPUx register) if pull-up resistors are being enabled, and clears it if pull-up resistors are being disabled.
      Parameters:
      pulledUp - whether or not to enable pull-up resistors.
    • enablePullUp

      public void enablePullUp()
      Enables pull-up resistors for this pin. More specifically, this sets the corresponding bit in the corresponding GPPUx byte (note: not the actual value in the MCP23S17's GPPUx register).
    • disablePullUp

      public void disablePullUp()
      Disables pull-up resistors for this pin. More specifically, this clears the corresponding bit in the corresponding GPPUx byte (note: not the actual value in the MCP23S17's GPPUx register).
    • addListener

      public void addListener(MCP23S17.InterruptListener listener)

      Add an interrupt listener for this pin.

      This does no error checking with respect to whether or not interrupts are enabled for this pin or whether or not they even could be effectively enabled.

      Parameters:
      listener - the listener to add.
      Throws:
      IllegalArgumentException - if the given listener is already registered.
      NullPointerException - if the given listener is null.
      Implementation Requirements:
      This is synchronized on the collection of listeners, so it is thread safe.
    • removeListener

      public void removeListener(MCP23S17.InterruptListener listener)
      Remove an interrupt listener from this pin.
      Parameters:
      listener - the listener to remove.
      Throws:
      IllegalArgumentException - if the given listener was not previously registered.
      NullPointerException - if the given listener is null.
      Implementation Requirements:
      This is synchronized on the collection of listeners, so it is thread safe.