Package com.pi4j.util

Class CommandArgumentParser


  • public class CommandArgumentParser
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Pin getPin​(Class<? extends PinProvider> pinProviderClass, Pin defaultPin, String... args)
      This utility method searches for "--pin (#)" or "-p (#)" in the command arguments array and returns a Pin instance based on the pin address/number specified.
      static PinPullResistance getPinPullResistance​(PinPullResistance defaultPull, String... args)
      This utility method searches for "--pull (up|down|off)", "--l (up|down|off)", "--up", or "--down" in the command arguments array and returns a PinPullResistance instance based on the option value provided.
      static SerialConfig getSerialConfig​(SerialConfig defaultConfig, String... args)
      This utility method searches for the following options: "--device (device-path)" [DEFAULT: /dev/ttyAMA0] "--baud (baud-rate)" [DEFAULT: 38400] "--data-bits (5|6|7|8)" [DEFAULT: 8] "--parity (none|odd|even)" [DEFAULT: none] "--stop-bits (1|2)" [DEFAULT: 1] "--flow-control (none|hardware|software)" [DEFAULT: none] in the arguments array and returns a SerialConfig instance based on the option values detected.
    • Constructor Detail

      • CommandArgumentParser

        public CommandArgumentParser()
    • Method Detail

      • getPin

        public static Pin getPin​(Class<? extends PinProvider> pinProviderClass,
                                 Pin defaultPin,
                                 String... args)
        This utility method searches for "--pin (#)" or "-p (#)" in the command arguments array and returns a Pin instance based on the pin address/number specified.
        Parameters:
        pinProviderClass - pin provider class to get pin instance from
        defaultPin - default pin instance to use if no --pin argument is found
        args - the argument array to search in
        Returns:
        GPIO pin instance
      • getPinPullResistance

        public static PinPullResistance getPinPullResistance​(PinPullResistance defaultPull,
                                                             String... args)
        This utility method searches for "--pull (up|down|off)", "--l (up|down|off)", "--up", or "--down" in the command arguments array and returns a PinPullResistance instance based on the option value provided.
        Parameters:
        defaultPull - default pin pull resistance to apply if no option/argument is found
        args - the argument array to search in
        Returns:
        pill pull resistance enum
      • getSerialConfig

        public static SerialConfig getSerialConfig​(SerialConfig defaultConfig,
                                                   String... args)
        This utility method searches for the following options: "--device (device-path)" [DEFAULT: /dev/ttyAMA0] "--baud (baud-rate)" [DEFAULT: 38400] "--data-bits (5|6|7|8)" [DEFAULT: 8] "--parity (none|odd|even)" [DEFAULT: none] "--stop-bits (1|2)" [DEFAULT: 1] "--flow-control (none|hardware|software)" [DEFAULT: none] in the arguments array and returns a SerialConfig instance based on the option values detected.
        Parameters:
        defaultConfig - default serial configuration to apply if no option/arguments are found
        args - the argument array to search in
        Returns:
        serial config object