Class MCP23S17.PinView
java.lang.Object
ch.ladestation.connectncharge.pui.MCP23S17.PinView
- Enclosing class:
- MCP23S17
An abstraction of each physical GPIO pin on a MCP23S17 IO expander chip.
- Author:
- Robert Russell
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(MCP23S17.InterruptListener listener) Add an interrupt listener for this pin.void
clear()
Clears the pin (sets it low).void
Disable the pin's interrupts.void
Disables pull-up resistors for this pin.void
Enable the pin's interrupts.void
Enables pull-up resistors for this pin.boolean
get()
Get the state of the pin.boolean
Get the default comparison value for comparison interrupt mode for this pin.boolean
getPin()
Get thePin
which thisPinView
represents.void
Set the pin's input to be inverted.boolean
isInput()
Get whether or not this pin is input.boolean
Get whether or not this pin's input is inverted.boolean
Get whether or not this pin is in interrupt change mode (as opposed to comparison mode).boolean
Get whether or not this pin is in interrupt comparison mode (as opposed to change mode).boolean
Get whether or not this pin's interrupt is enabled.boolean
isOutput()
Get whether or not this pin is output.boolean
Get whether or not this pin has a pull-up resistor enabled.void
removeListener
(MCP23S17.InterruptListener listener) Remove an interrupt listener from this pin.void
set()
Sets the pin high.void
set
(boolean value) Set the pin to the given state.void
Set the pin to be input.void
Set the pin to be output.void
setDefaultComparisonValue
(boolean value) Set the default comparison value for comparison interrupt mode for this pin.void
setDirection
(boolean input) Set the pin to the given direction.void
setInterruptEnabled
(boolean interruptEnabled) Set whether or not the pin's interrupt is enabled.void
setInterruptMode
(boolean comparison) Set the interrupt mode for this pin.void
setInverted
(boolean inverted) Set whether or not the pin's input is inverted.void
setPulledUp
(boolean pulledUp) Set whether or not this pin has a pull-up resistor enabled.void
Set the interrupt mode to change mode.void
Set the interrupt mode to comparison mode.void
Set the pin's input to not be inverted.
-
Method Details
-
getPin
Get thePin
which thisPinView
represents.- Returns:
- the
Pin
which thisPinView
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
- 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
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 isnull
.- Implementation Requirements:
- This is synchronized on the collection of listeners, so it is thread safe.
-
removeListener
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 isnull
.- Implementation Requirements:
- This is synchronized on the collection of listeners, so it is thread safe.
-