Package com.diozero.devices
Class PiconZero
java.lang.Object
com.diozero.internal.spi.AbstractDeviceFactory
com.diozero.devices.PiconZero
- All Implemented Interfaces:
DeviceInterface
,AnalogInputDeviceFactoryInterface
,AnalogOutputDeviceFactoryInterface
,DeviceFactoryInterface
,GpioDeviceFactoryInterface
,PwmOutputDeviceFactoryInterface
,AutoCloseable
public class PiconZero extends AbstractDeviceFactory implements GpioDeviceFactoryInterface, PwmOutputDeviceFactoryInterface, AnalogInputDeviceFactoryInterface, AnalogOutputDeviceFactoryInterface, DeviceInterface
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PiconZero.InputConfig
static class
PiconZero.OutputConfig
static class
PiconZero.PiconZeroAnalogInputDevice
static class
PiconZero.PiconZeroAnalogOutputDevice
static class
PiconZero.PiconZeroBoardPinInfo
static class
PiconZero.PiconZeroDigitalInputDevice
static class
PiconZero.PiconZeroDigitalOutputDevice
static class
PiconZero.PiconZeroPwmOutputDevice
-
Field Summary
Fields Modifier and Type Field Description static int
ALL_PIXELS
static float
MAX_ANALOG_INPUT_VALUE
static int
MAX_MOTOR_VALUE
static int
MAX_OUTPUT_VALUE
static int
MIN_MOTOR_VALUE
static int
NUM_INPUT_CHANNELS
static int
NUM_MOTORS
static int
NUM_OUTPUT_CHANNELS
static int
SERVO_CENTRE
Fields inherited from class com.diozero.internal.spi.AbstractDeviceFactory
closed, deviceStates
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
close()
Close this device factory including all devices that have been provisioned by it.void
closeChannel(int channel)
AnalogInputDeviceInterface
createAnalogInputDevice(String key, PinInfo pinInfo)
AnalogOutputDeviceInterface
createAnalogOutputDevice(String key, PinInfo pinInfo, float initialValue)
GpioDigitalInputDeviceInterface
createDigitalInputDevice(String key, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger)
GpioDigitalInputOutputDeviceInterface
createDigitalInputOutputDevice(String key, PinInfo pinInfo, DeviceMode mode)
GpioDigitalOutputDeviceInterface
createDigitalOutputDevice(String key, PinInfo pinInfo, boolean initialValue)
PwmOutputDeviceInterface
createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
BoardPinInfo
getBoardPinInfo()
Get information about pins that can be provisioned by this device factory.int
getBoardPwmFrequency()
int
getInputValue(int channel)
Read input value in PiconZero rangefloat
getMotor(int motor)
Get motor output value (normalised to range -1..1)int
getMotorValue(int motor)
Get the current motor speed (PiconZero range -128..127)String
getName()
Get the name of this device factorybyte[]
getRevision()
Get the board revision detailsfloat
getValue(int channel)
Read input value in normalised range (0..1)float
getVRef()
AnalogInputDeviceInterface
provisionAnalogInputDevice(PinInfo pinInfo)
void
reset()
Reset the board.void
setAllPixels(int red, int green, int blue, boolean update)
Sets all pixels with the selected red, green and blue values (0 to 255) [Available from firmware revision 07]void
setBoardPwmFrequency(int pwmFrequency)
void
setBrightness(int brightness)
void
setInputConfig(int channel, PiconZero.InputConfig config)
Set configuration of selected input channelvoid
setMotor(int motor, float speed)
Set motor output value (normalised to range -1..1)void
setMotorValue(int motor, int speed)
Set motor output value (PiconZero range -128..127)void
setOutputConfig(int channel, PiconZero.OutputConfig config)
Set configuration of selected outputvoid
setOutputValue(int channel, int value)
Set output data for selected output channel in PiconZero range.void
setPixel(int pixel, int red, int green, int blue, boolean update)
Set the colour of an individual pixel (always output channel 5)void
setValue(int channel, boolean value)
void
setValue(int channel, float value)
Set output value for the specified channel (normalised).void
updatePixels()
Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createSerialKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.internal.spi.AnalogOutputDeviceFactoryInterface
provisionAnalogOutputDevice
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
createI2CKey, createPinKey, createSerialKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen, start
Methods inherited from interface com.diozero.internal.spi.GpioDeviceFactoryInterface
provisionDigitalInputDevice, provisionDigitalInputOutputDevice, provisionDigitalOutputDevice
Methods inherited from interface com.diozero.internal.spi.PwmOutputDeviceFactoryInterface
provisionPwmOutputDevice
-
Field Details
-
ALL_PIXELS
public static final int ALL_PIXELS- See Also:
- Constant Field Values
-
MAX_OUTPUT_VALUE
public static final int MAX_OUTPUT_VALUE- See Also:
- Constant Field Values
-
NUM_MOTORS
public static final int NUM_MOTORS- See Also:
- Constant Field Values
-
NUM_INPUT_CHANNELS
public static final int NUM_INPUT_CHANNELS- See Also:
- Constant Field Values
-
NUM_OUTPUT_CHANNELS
public static final int NUM_OUTPUT_CHANNELS- See Also:
- Constant Field Values
-
MAX_ANALOG_INPUT_VALUE
public static final float MAX_ANALOG_INPUT_VALUE -
MAX_MOTOR_VALUE
public static final int MAX_MOTOR_VALUE- See Also:
- Constant Field Values
-
MIN_MOTOR_VALUE
public static final int MIN_MOTOR_VALUE- See Also:
- Constant Field Values
-
SERVO_CENTRE
public static final int SERVO_CENTRE- See Also:
- Constant Field Values
-
-
Constructor Details
-
PiconZero
public PiconZero() -
PiconZero
public PiconZero(int controller, int address)
-
-
Method Details
-
getVRef
public float getVRef()- Specified by:
getVRef
in interfaceAnalogInputDeviceFactoryInterface
-
reset
public void reset()Reset the board. -
getRevision
public byte[] getRevision()Get the board revision details- Returns:
- revision[0]: Board type (2 == PiconZero); revision[1]: Firmware version
-
setInputConfig
Set configuration of selected input channel- Parameters:
channel
- Input channel (0..3)config
- Input configuration (0: Digital, 1: Analog, 2: DS18B20)
-
setOutputConfig
Set configuration of selected output- Parameters:
channel
- Output channel (0..5)config
- Output configuration (0: Digital, 1: PWM, 2: Servo, 3: Neopixel WS2812B)
-
setMotor
public void setMotor(int motor, float speed)Set motor output value (normalised to range -1..1)- Parameters:
motor
- Motor number (0 or 1)speed
- Must be in range -1..1
-
getMotor
public float getMotor(int motor)Get motor output value (normalised to range -1..1)- Parameters:
motor
- Motor number (0 or 1)- Returns:
- Current motor speed in range -1..1
-
setMotorValue
public void setMotorValue(int motor, int speed)Set motor output value (PiconZero range -128..127)- Parameters:
motor
- Motor number (0 or 1)speed
- Must be in range -128..127
-
getMotorValue
public int getMotorValue(int motor)Get the current motor speed (PiconZero range -128..127)- Parameters:
motor
- Motor number (0 or 1)- Returns:
- Motor speed in range -128..127
-
getValue
public float getValue(int channel)Read input value in normalised range (0..1)- Parameters:
channel
- Input to read- Returns:
- Normalised value (0..1)
-
setValue
public void setValue(int channel, float value)Set output value for the specified channel (normalised).
* Don't use this method if the output mode is WS2812B.
- Parameters:
channel
- 0..5value
- Normalised output value:Mode Name Type Values 0 On/Off Byte 0 is OFF, 1 is ON 1 PWM Byte 0 to 1 percentage of ON time 2 Servo Byte -1 to + 1 Position in degrees (0 is centre) 3* WS2812B 4 Bytes 0:Pixel ID, 1:Red, 2:Green, 3:Blue
-
setValue
public void setValue(int channel, boolean value) -
getInputValue
public int getInputValue(int channel)Read input value in PiconZero range- Parameters:
channel
- Input to read- Returns:
- Value in PiconZero range
-
setOutputValue
public void setOutputValue(int channel, int value)Set output data for selected output channel in PiconZero range.- Parameters:
channel
- 0..5value
- output value:Mode Name Type Values 0 On/Off Byte 0 is OFF, 1 is ON 1 PWM Byte 0 to 100 percentage of ON time 2 Servo Byte Position in degrees with 90 as the mid point 3* WS2812B 4 Bytes 0:Pixel ID, 1:Red, 2:Green, 3:Blue
* Don't use this method if the output mode is WS2812B.
-
setPixel
public void setPixel(int pixel, int red, int green, int blue, boolean update)Set the colour of an individual pixel (always output channel 5)- Parameters:
pixel
- 0..63red
- 0..255green
- 0..255blue
- 0..255update
- update the pixel now if true
-
setAllPixels
public void setAllPixels(int red, int green, int blue, boolean update)Sets all pixels with the selected red, green and blue values (0 to 255) [Available from firmware revision 07]- Parameters:
red
- 0..255green
- 0..255blue
- 0..255update
- update the pixel now if true
-
updatePixels
public void updatePixels() -
setBrightness
public void setBrightness(int brightness) -
getName
Description copied from interface:DeviceFactoryInterface
Get the name of this device factory- Specified by:
getName
in interfaceDeviceFactoryInterface
- Returns:
- the name of this device factory
-
getBoardPwmFrequency
public int getBoardPwmFrequency()- Specified by:
getBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
setBoardPwmFrequency
public void setBoardPwmFrequency(int pwmFrequency)- Specified by:
setBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
getBoardPinInfo
Description copied from interface:DeviceFactoryInterface
Get information about pins that can be provisioned by this device factory.- Specified by:
getBoardPinInfo
in interfaceDeviceFactoryInterface
- Returns:
-
createDigitalInputDevice
public GpioDigitalInputDeviceInterface createDigitalInputDevice(String key, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException- Specified by:
createDigitalInputDevice
in interfaceGpioDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createDigitalOutputDevice
public GpioDigitalOutputDeviceInterface createDigitalOutputDevice(String key, PinInfo pinInfo, boolean initialValue) throws RuntimeIOException- Specified by:
createDigitalOutputDevice
in interfaceGpioDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createDigitalInputOutputDevice
public GpioDigitalInputOutputDeviceInterface createDigitalInputOutputDevice(String key, PinInfo pinInfo, DeviceMode mode) throws RuntimeIOException- Specified by:
createDigitalInputOutputDevice
in interfaceGpioDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createPwmOutputDevice
public PwmOutputDeviceInterface createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue) throws RuntimeIOException- Specified by:
createPwmOutputDevice
in interfacePwmOutputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createAnalogInputDevice
- Specified by:
createAnalogInputDevice
in interfaceAnalogInputDeviceFactoryInterface
-
createAnalogOutputDevice
public AnalogOutputDeviceInterface createAnalogOutputDevice(String key, PinInfo pinInfo, float initialValue) throws RuntimeIOException- Specified by:
createAnalogOutputDevice
in interfaceAnalogOutputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
provisionAnalogInputDevice
public AnalogInputDeviceInterface provisionAnalogInputDevice(PinInfo pinInfo) throws RuntimeIOException- Specified by:
provisionAnalogInputDevice
in interfaceAnalogInputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
closeChannel
public void closeChannel(int channel) -
close
Description copied from interface:DeviceFactoryInterface
Close this device factory including all devices that have been provisioned by it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
- Specified by:
close
in interfaceDeviceInterface
- Overrides:
close
in classAbstractDeviceFactory
- Throws:
RuntimeIOException
-