public class GpioCycler extends Object
Modifier and Type | Field and Description |
---|---|
private boolean |
allPinsProvisioned
supervisor class flag to save re-provisioning.
|
static short |
BOARD_TYPE_2
Class constant for a PI board type Pi2.
|
static short |
BOARD_TYPE_A
Class constant for a PI board type A.
|
static short |
BOARD_TYPE_APLUS
Class constant for a PI board type A+.
|
static short |
BOARD_TYPE_B
Class constant for a PI board type B.
|
static short |
BOARD_TYPE_B2
Class constant for a PI board type B2.
|
static short |
BOARD_TYPE_BPLUS
Class constant for a PI board type B+.
|
private short |
boardType
Class var specifying the active board type - it starts as the DEFAULT_BOARD_TYPE.
|
private short |
cycleTime
The duty cycle time in ms that the GPIO will cycle ON.
|
static short |
DEFAULT_BOARD_TYPE
Class constant for its DEFAULT PI board type = BOARD_TYPE_2.
|
static short |
DEFAULT_CYCLE_TIME_MS
The DEFAULT time in milliSeconds the GPIO will go HIGH.
|
static boolean[] |
DEFAULT_ENABLED_PINS
The default set of pins that will be used / enabled [0-11 are enabled].
|
static short |
DEFAULT_END_PIN
The default pin to end the cycle from.
|
static int |
DEFAULT_LOOP_TIME_MS
The DEFAULT time in milliSeconds the cycle loop should run.
|
static short |
DEFAULT_OVERLAP_TIME_MS
The DEFAULT time in milliSeconds the next GPIO pin will come on before the previous
one goes LOW.
|
static short[] |
DEFAULT_PI2_PINS
The default set of pins for a Raspberry Pi 2 Model B board that will be controlled.
|
static short[] |
DEFAULT_PIAB_PINS
The default set of pins for a Raspberry Pi Model A or B board that will be controlled.
|
static short[] |
DEFAULT_PIBPLUS_PINS
The default set of pins for a Raspberry Pi Model B Plus board that will be controlled.
|
static short[] |
DEFAULT_PINS |
static PinState |
DEFAULT_PINSTATE
Default pin state is LOW.
|
static short |
DEFAULT_START_PIN
The default pin to start the cycle from.
|
private boolean[] |
enabledPins
The pins that are enabled.
|
private short |
endPin
The gpioPin number associated with the last enabled GPIO pin that is LAST used in the cycle - zero based.
|
private GpioController |
gpio
gpio controller used by all methods in this class.
|
private GpioPinDigitalOutput[] |
gpioPins
The usable GPIO pins that will be used by this class - it does NOT get init until provisionPins is called.
|
private int |
loopTime
The time that the whole thing should run/looping back and forth - use -1 to go forever
|
private short |
overlapTime
The time in ms that the next GPIO will come ON before the previous one is OFF -
it can be a negative number to specify a delAY.
|
private short[] |
pins
pins represents the GPIO pin numbers on the board.
|
private short |
startPin
The gpioPin number associated with the first enabled GPIO pin that is 1st used in the cycle - zero based.
|
Constructor and Description |
---|
GpioCycler()
constructor
|
Modifier and Type | Method and Description |
---|---|
void |
cycle()
Run the Cycling of te GPIO pins that have been defined, for the Class set loopTime (which defaults to DEFAULT_LOOP_TIME_MS if not set).
|
void |
cycle(int loopTime)
Run the Cycling of te GPIO pins that have been defined.
|
void |
delayCycle()
This is the method that actually cyles the GPIO states - used when overlapTime is negative - there is a gap between the LEDs,
for the Class set loopTime (which defaults to DEFAULT_LOOP_TIME_MS if not set).
|
void |
delayCycle(int loopTime)
This is the method that actually cyles the GPIO states - used when overlapTime is negative - there is a gap between the LEDs.
|
void |
disablePin(short pin)
Mark a pin as DISABLED - it sets the class var that keeps track of which GPIO pins are enabled; 'enabledPins' to false.
|
void |
enableAllPin()
Mark all available pins for the active boardType as ENABLED - it sets the class var that keeps track of
which GPIO pins are enabled; 'enabledPins' to true.
|
void |
enablePin(short pin)
Mark a pin as ENABLED - it sets the class var that keeps track of which GPIO pins are enabled; 'enabledPins' to true.
|
private int |
firstEnabledPinRef()
figures out, sets the class Var startPin, and returns the array ref for the FIRST ENABLED GPIO pin.
|
void |
flashAllPins()
Cycles ALL gpio pins on / off 2 times for 500ms each.
|
void |
flashAllPins(short numFlashes,
short flashTimeMS)
Cycles ALL gpio pins on / off numFlashes times with a duty time of flashTimeMS .
|
short |
getBoardType()
Get Method for class field 'boardType'.
|
short |
getCycleTime()
Get Method for class field 'cycleTime'.
|
private short |
getEnabledPinCount() |
short |
getEndPin()
Get Method for class field 'endPin'.
|
short |
getOverlapTime()
Get Method for class field 'overlapTime'.
|
short[] |
getPins()
Get Method for class field '[]'.
|
private Pin |
getRaspiPin(short pin)
RaspiPINS have names of the form 'GPIO 4' or 'GPIO 12'.
|
short |
getStartPin()
Get Method for class field 'startPin'.
|
private int |
lastEnabledPinRef()
figures out, sets the class Var endPin, and returns the array ref for the last ENABLED GPIO pin.
|
static void |
main(String[] args)
The main entrance to this class.
|
void |
overlapCycle()
This is the method that actually cyles the GPIO states - when overlapTime is positive - the LEDs overlap their ON,
for the Class set loopTime (which defaults to DEFAULT_LOOP_TIME_MS if not set).
|
void |
overlapCycle(int loopTime)
This is the method that actually cyles the GPIO states - when overlapTime is positive - the LEDs overlap their ON.
|
protected void |
parseCommandlineParms(String[] args)
Sets the 3 timing paramets based on optional commandline parameters - passed to this method in args[].
|
private GpioPinDigitalOutput |
provisionOutputPin(short pin)
provisions and returns a Gpio Outpout Pin with the DEFAULT state.
|
private GpioPinDigitalOutput |
provisionOutputPin(short pin,
PinState pinState)
provisions and returns a Gpio Outpout Pin.
|
private GpioPinDigitalOutput[] |
provisionPins()
provisions ALL enabled pins and puts them in the class var gpioPins.
|
private GpioPinDigitalOutput[] |
provisionPins(boolean doAll)
provisions (according to passed flag) pins and puts them in the class var gpioPins.
|
short |
setBoardType(short boardType)
Set the boardType to use, must be one of the Class constants BOARD_TYPE_*.
|
void |
setCycleTime(short cycleTime)
Set Method for class field 'cycleTime'.
|
void |
setEndPin(short pin)
Set Method for class field 'endPin'.
|
void |
setOverlapTime(short overlapTime)
Set Method for class field 'overlapTime'.
|
void |
setPins(short[] pins)
Set Method for class field 'pins' that represents the GPIO pin numbers on the board.
|
void |
setStartPin(short pin)
Set Method for class field 'startPin'.
|
void |
shutdown()
Stop all GPIO activity/threads by shutting down the GPIO controller.
|
static boolean |
sleep(long waitTime)
A method to simply abstract the Try/Catch required to put the current
thread to sleep for the specified time in ms.
|
public static final short BOARD_TYPE_A
public static final short BOARD_TYPE_APLUS
public static final short BOARD_TYPE_B
public static final short BOARD_TYPE_B2
public static final short BOARD_TYPE_BPLUS
public static final short BOARD_TYPE_2
public static final short DEFAULT_BOARD_TYPE
public static final int DEFAULT_LOOP_TIME_MS
public static final short DEFAULT_CYCLE_TIME_MS
public static final short DEFAULT_OVERLAP_TIME_MS
public static final short[] DEFAULT_PIAB_PINS
public static final short[] DEFAULT_PIBPLUS_PINS
public static final short[] DEFAULT_PI2_PINS
public static final short[] DEFAULT_PINS
public static final boolean[] DEFAULT_ENABLED_PINS
public static final short DEFAULT_START_PIN
public static final short DEFAULT_END_PIN
public static final PinState DEFAULT_PINSTATE
private short boardType
private int loopTime
private short cycleTime
private short overlapTime
private short[] pins
private boolean[] enabledPins
private short startPin
private short endPin
private GpioPinDigitalOutput[] gpioPins
private boolean allPinsProvisioned
private final GpioController gpio
public GpioCycler()
public void shutdown()
protected void parseCommandlineParms(String[] args)
args
- is the commandline args arraypublic void flashAllPins()
public void flashAllPins(short numFlashes, short flashTimeMS)
private int lastEnabledPinRef()
private int firstEnabledPinRef()
public void cycle()
public void cycle(int loopTime)
loopTime
- is the length of time in ms to run the loop.public void overlapCycle()
public void overlapCycle(int loopTime)
loopTime
- is the length of time in ms to run the loop.public void delayCycle()
public void delayCycle(int loopTime)
loopTime
- is the length of time in ms to run the loop.public void disablePin(short pin)
pin
- is the GPIO pin number to disablepublic void enablePin(short pin)
pin
- is the GPIO pin number to enablepublic void enableAllPin()
public short setBoardType(short boardType)
boardType
- is the value to set this class field to.public short getBoardType()
public void setStartPin(short pin)
pin
- is the value to set this class field to.public short getStartPin()
public void setEndPin(short pin)
pin
- is the value to set this class field to.public short getEndPin()
public void setCycleTime(short cycleTime)
cycleTime
- is the value to set this class field to.public short getCycleTime()
public void setOverlapTime(short overlapTime)
overlapTime
- is the value to set this class field to.public short getOverlapTime()
public void setPins(short[] pins)
short[]
- is the value to set this class field pinsto.public short[] getPins()
private short getEnabledPinCount()
private Pin getRaspiPin(short pin)
pin
- is the Pi4j (wiringPI) pin number.private GpioPinDigitalOutput provisionOutputPin(short pin)
private GpioPinDigitalOutput provisionOutputPin(short pin, PinState pinState)
private GpioPinDigitalOutput[] provisionPins()
private GpioPinDigitalOutput[] provisionPins(boolean doAll)
boolean
- controls if all pins are provisioned for only those that are enabled in enabledPins class var.public static void main(String[] args) throws InterruptedException
-------------------------------------------------------------------------------- Java Raspberry PI - GpioCycler Copyright (C) 2015 - Tom B. Gutwin -------------------------------------------------------------------------------- Syntax: java ca.bc.webarts.raspberry.GpioCycler [loopTime [dutyCycleTime [overlapTime]]] where the 3 OPTIONAL parameters are: loopTime time in milliSeconds to run the looping (default=DEFAULT_LOOP_TIME_MS ms) (default=DEFAULT_LOOP_TIME_MS ms) dutyCycleTime time in milliSeconds the GPIOs stays in the 'ON' state (default=DEFAULT_CYCLE_TIME_MS ms) overlapTime time in milliSeconds the next/following GPIO will turn 'ON' before the previous GPIO turns 'OFF' (default=DEFAULT_OVERLAP_TIME_MS ms)
InterruptedException
public static boolean sleep(long waitTime)
waitTime
- the sleep time in milli seconds (ms).WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses