default PwmOutputDeviceInterface provisionPwmOutputDevice(int pwmOrGpioNum, int pwmFrequency, float initialValue) throws RuntimeIOException { // Lookup by PWM number first, if not found or doesn't support // PWM_OUTPUT, lookup by GPIO number PinInfo pin_info = getBoardPinInfo().getByPwmNumber(pwmOrGpioNum); if (pin_info == null || !pin_info.isSupported(DeviceMode.PWM_OUTPUT)) { pin_info = getBoardPinInfo().getByGpioNumber(pwmOrGpioNum); } if (pin_info != null && (pin_info.isSupported(DeviceMode.PWM_OUTPUT) || pin_info.isSupported(DeviceMode.DIGITAL_OUTPUT))) { // Ok } else { throw new InvalidModeException("Invalid mode (PWM output) for GPIO " + pwmOrGpioNum); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } PwmOutputDeviceInterface device = createPwmOutputDevice(key, pin_info, pwmFrequency, initialValue); deviceOpened(device); return device; }
@Override public AnalogInputDeviceInterface provisionAnalogInputDevice(int gpio) throws RuntimeIOException { // Special case - PiconZero can switch between digital and analog input hence use of gpio rather than adc PinInfo pin_info = boardPinInfo.getByGpioNumber(gpio); if (pin_info == null || ! pin_info.isSupported(DeviceMode.ANALOG_INPUT)) { throw new IllegalArgumentException("Invalid mode (analog input) for GPIO " + gpio); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } AnalogInputDeviceInterface device = createAnalogInputDevice(key, pin_info); deviceOpened(device); return device; }
default AnalogOutputDeviceInterface provisionAnalogOutputDevice(int dacNumber) throws RuntimeIOException { PinInfo pin_info = getBoardPinInfo().getByDacNumber(dacNumber); if (pin_info == null || ! pin_info.isSupported(DeviceMode.ANALOG_OUTPUT)) { throw new InvalidModeException("Invalid mode (analog output) for DAC " + dacNumber); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } AnalogOutputDeviceInterface device = createAnalogOutputDevice(key, pin_info); deviceOpened(device); return device; }
default AnalogInputDeviceInterface provisionAnalogInputDevice(int adcNumber) throws RuntimeIOException { PinInfo pin_info = getBoardPinInfo().getByAdcNumber(adcNumber); if (pin_info == null || ! pin_info.isSupported(DeviceMode.ANALOG_INPUT)) { throw new InvalidModeException("Invalid mode (analog input) for adc " + adcNumber); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } AnalogInputDeviceInterface device = createAnalogInputDevice(key, pin_info); deviceOpened(device); return device; }
default GpioDigitalInputDeviceInterface provisionDigitalInputDevice(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException { PinInfo pin_info = getBoardPinInfo().getByGpioNumber(gpio); if (pin_info == null || !pin_info.isSupported(DeviceMode.DIGITAL_INPUT)) { throw new InvalidModeException("Invalid mode (digital input) for GPIO " + gpio); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } GpioDigitalInputDeviceInterface device = createDigitalInputDevice(key, pin_info, pud, trigger); deviceOpened(device); return device; }
default GpioDigitalOutputDeviceInterface provisionDigitalOutputDevice(int gpio, boolean initialValue) throws RuntimeIOException { PinInfo pin_info = getBoardPinInfo().getByGpioNumber(gpio); if (pin_info == null || ! pin_info.isSupported(DeviceMode.DIGITAL_OUTPUT)) { throw new InvalidModeException("Invalid mode (digital output) for GPIO " + gpio); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } GpioDigitalOutputDeviceInterface device = createDigitalOutputDevice(key, pin_info, initialValue); deviceOpened(device); return device; }
@Override public AnalogInputDeviceInterface provisionAnalogInputDevice(int gpio) { // Special case - The Arduino can switch between digital and analog input hence use of gpio rather than adc PinInfo pin_info = getBoardPinInfo().getByGpioNumber(gpio); if (pin_info == null || ! pin_info.isSupported(DeviceMode.ANALOG_INPUT)) { throw new InvalidModeException("Invalid mode (analog input) for GPIO " + gpio); } String key = createPinKey(pin_info); // Check if this pin is already provisioned if (isDeviceOpened(key)) { throw new DeviceAlreadyOpenedException("Device " + key + " is already in use"); } AnalogInputDeviceInterface device = createAnalogInputDevice(key, pin_info); deviceOpened(device); return device; }