com.google.android.things.pio.PeripheralManager Java Examples

The following examples show how to use com.google.android.things.pio.PeripheralManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LedControl.java    From blefun-androidthings with Apache License 2.0 6 votes vote down vote up
public LedControl(String spiGpio) throws IOException {
    PeripheralManager manager = PeripheralManager.getInstance();
    spiDevice = manager.openSpiDevice(spiGpio);
    spiDevice.setMode(SpiDevice.MODE0);
    spiDevice.setFrequency(1000000); // 1MHz
    spiDevice.setBitsPerWord(8); // 8 BPW
    spiDevice.setBitJustification(SpiDevice.BIT_JUSTIFICATION_MSB_FIRST); // MSB first

    spiTransfer(OP_DECODEMODE, 0); // decodingļ¼š BCD
    setScanLimit(7); // scanlimit: 8 LEDs
    spiTransfer(OP_DISPLAYTEST, 0);

    shutdown(false);
    setIntensity(3);
    clearDisplay();
}
 
Example #2
Source File: I2cBitBangDevice.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
public I2cBitBangDevice(int i2cAddress, String pinData, String pinClock) throws IOException {
    mAddress = i2cAddress;
    PeripheralManager pioService = PeripheralManager.getInstance();
    try {
        mData = pioService.openGpio(pinData);
        mData.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        mClock = pioService.openGpio(pinClock);
        mClock.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #3
Source File: Apa102.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new Apa102 driver.
 *
 * @param spiBusPort Name of the SPI bus
 * @param ledMode The {@link Mode} indicating the red/green/blue byte ordering for the device.
 * @param direction The {@link Direction} or the led strip.
 * @param spiMode the SPI device mode for the bus. Default is MODE2
 */
public Apa102(String spiBusPort, Mode ledMode, Direction direction, int spiMode)
        throws IOException {
    mLedMode = ledMode;
    mDirection = direction;
    PeripheralManager pioService = PeripheralManager.getInstance();
    mDevice = pioService.openSpiDevice(spiBusPort);
    try {
        configure(mDevice, spiMode);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #4
Source File: MatrixKeypad.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
public MatrixKeypad(String[] rowPins, String[] colPins, int[] keyCodes,
        Handler handler) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    mGpioRows = new Gpio[rowPins.length];
    mGpioCols = new Gpio[colPins.length];
    mKeyCodes = keyCodes;
    mMatrix = new MatrixKey[rowPins.length][colPins.length];

    // Initialize Gpio and keys
    for (int r = 0; r < rowPins.length; r++) {
        mGpioRows[r] = pioService.openGpio(rowPins[r]);
        mGpioRows[r].setDirection(Gpio.DIRECTION_IN);
        for (int c = 0; c < colPins.length; c++) {
            if (mGpioCols[c] == null) {
                mGpioCols[c] = pioService.openGpio(colPins[c]);
                mGpioCols[c].setDirection(Gpio.DIRECTION_IN);
            }
            mMatrix[r][c] = new MatrixKey(keyCodes[r * colPins.length + c]);
        }
    }

    initKeyScanHandler(handler);
}
 
Example #5
Source File: Cap1xxx.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new Cap1xxx controller.
 *
 * @param i2cName I2C port name where the controller is attached. Cannot be null.
 * @param i2cAddress 7-bit I2C address for the attached controller.
 * @param alertName optional GPIO pin name connected to the controller's
 *                  alert interrupt signal. Can be null.
 * @param chip identifier for the connected controller device chip.
 * @param handler optional {@link Handler} for software polling and callback events.
 * @throws IOException
 */

public Cap1xxx(String i2cName, int i2cAddress, String alertName, Configuration chip, Handler handler)
        throws IOException {
    mChipConfiguration = chip;
    try {
        PeripheralManager manager = PeripheralManager.getInstance();
        I2cDevice device = manager.openI2cDevice(i2cName, i2cAddress);
        Gpio alertPin = null;
        if (alertName != null) {
            alertPin = manager.openGpio(alertName);
        }
        init(device, alertPin, chip, handler);
    } catch (IOException|RuntimeException e) {
        // Close the peripherals if an init error occurs
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #6
Source File: ImageClassifierActivity.java    From sample-tensorflow-imageclassifier with Apache License 2.0 6 votes vote down vote up
/**
 * This method should only be called when running on an Android Things device.
 */
private void initPIO() {
    PeripheralManager pioManager = PeripheralManager.getInstance();
    try {
        mReadyLED = pioManager.openGpio(BoardDefaults.getGPIOForLED());
        mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        mButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                SHUTTER_KEYCODE);
        mButtonDriver.register();
    } catch (IOException e) {
        mButtonDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
Example #7
Source File: UartLowpanModule.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new UartLowpanModule.
 *
 * @param lowpanDriverCallback @see {@link LowpanDriverCallback}
 * @param uartName UART port name where the module is attached. Cannot be null.
 * @param baudRate Baud rate used for the module UART.
 * @param hardwareFlowControl hardware flow control setting for uart device
 *        {@link UartDevice#HW_FLOW_CONTROL_NONE},
 *        {@link UartDevice#HW_FLOW_CONTROL_AUTO_RTSCTS}
 *        @see UartDevice#HW_FLOW_CONTROL_NONE}
 *        @see UartDevice#HW_FLOW_CONTROL_AUTO_RTSCTS}
 * @param handler optional {@link Handler} for UartDevice.
 */
public UartLowpanModule(@NonNull LowpanDriverCallback lowpanDriverCallback, String uartName,
                        int baudRate, int hardwareFlowControl,
                        UnexpectedCloseListener unexpectedCloseListener,
                        @NonNull Handler handler) throws IOException {
    mLowpanDriverCallback = lowpanDriverCallback;
    mUartName = uartName;
    mHardwareFlowControl = hardwareFlowControl;
    mHandler = handler;
    mBaudRate = baudRate;
    mUnexpectedCloseListener = unexpectedCloseListener;

    final PeripheralManager manager = PeripheralManager.getInstance();

    resetFrameState();

    mDevice = manager.openUartDevice(mUartName);
    mDevice.setBaudrate(mBaudRate);
    mDevice.setDataSize(8);
    mDevice.setHardwareFlowControl(mHardwareFlowControl);
    mDevice.registerUartDeviceCallback(mHandler, mUartDeviceCallback);
}
 
Example #8
Source File: Epd.java    From androidthings-drivers with Apache License 2.0 6 votes vote down vote up
public Epd(String spiBusPort, String resetPin, String dataCommandPin, String busyPin) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    mSpiDevice = pioService.openSpiDevice(spiBusPort);
    mResetPin = pioService.openGpio(resetPin);
    mDataCommandPin = pioService.openGpio(dataCommandPin);
    mBusyPin = pioService.openGpio(busyPin);
    try {
        configure();
    } catch (IOException | RuntimeException e) {
        try {
            close();
        } catch (IOException | RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #9
Source File: BlinkActivity.java    From sample-simplepio with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting BlinkActivity");

    try {
        String pinName = BoardDefaults.getGPIOForLED();
        mLedGpio = PeripheralManager.getInstance().openGpio(pinName);
        mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        Log.i(TAG, "Start blinking LED GPIO pin");
        // Post a Runnable that continuously switch the state of the GPIO, blinking the
        // corresponding LED
        mHandler.post(mBlinkRunnable);
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    }
}
 
Example #10
Source File: ButtonActivity.java    From sample-simplepio with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting ButtonActivity");

    try {
        String pinName = BoardDefaults.getGPIOForButton();
        mButtonGpio = PeripheralManager.getInstance().openGpio(pinName);
        mButtonGpio.setDirection(Gpio.DIRECTION_IN);
        mButtonGpio.setEdgeTriggerType(Gpio.EDGE_FALLING);
        mButtonGpio.registerGpioCallback(new GpioCallback() {
            @Override
            public boolean onGpioEdge(Gpio gpio) {
                Log.i(TAG, "GPIO changed, button pressed");
                // Return true to continue listening to events
                return true;
            }
        });
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    }
}
 
Example #11
Source File: BoardDefaults.java    From edison-candle with Apache License 2.0 6 votes vote down vote up
private static String getBoardVariant() {
    if (!sBoardVariant.isEmpty()) {
        return sBoardVariant;
    }
    sBoardVariant = Build.DEVICE;
    // For the edison check the pin prefix
    // to always return Edison Breakout pin name when applicable.
    if (sBoardVariant.equals(DEVICE_EDISON)) {
        List<String> gpioList = PeripheralManager.getInstance().getGpioList();
        if (gpioList.size() != 0) {
            String pin = gpioList.get(0);
            if (pin.startsWith("IO")) {
                sBoardVariant = DEVICE_EDISON_ARDUINO;
            }
        }
    }
    return sBoardVariant;
}
 
Example #12
Source File: PwmActivity.java    From sample-simplepio with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting PwmActivity");

    try {
        String pinName = BoardDefaults.getPWMPort();
        mActivePulseDuration = MIN_ACTIVE_PULSE_DURATION_MS;

        mPwm = PeripheralManager.getInstance().openPwm(pinName);

        // Always set frequency and initial duty cycle before enabling PWM
        mPwm.setPwmFrequencyHz(1000 / PULSE_PERIOD_MS);
        mPwm.setPwmDutyCycle(mActivePulseDuration);
        mPwm.setEnabled(true);

        // Post a Runnable that continuously change PWM pulse width, effectively changing the
        // servo position
        Log.d(TAG, "Start changing PWM pulse");
        mHandler.post(mChangePWMRunnable);
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    }
}
 
Example #13
Source File: Max98357A.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an interface to the chip.
 *
 * @param notSdMode The name for the NOT_SD_MODE pin
 * @param gainSlot The name for the GAIN_SLOT pin
 */
public Max98357A(String notSdMode, String gainSlot) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    if (notSdMode != null) {
        mNotSdModeGpio = pioService.openGpio(notSdMode);
        mNotSdModeGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    }
    if (gainSlot != null) {
        mGainSlotGpio = pioService.openGpio(gainSlot);
        mGainSlotGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    }
}
 
Example #14
Source File: VoiceHat.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Opens the LED using a specified pin.
 *
 * @return LED on the VoiceHat
 */
public static Gpio openLed(String ledGpioPin) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    Gpio led = pioService.openGpio(ledGpioPin);
    led.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    return led;
}
 
Example #15
Source File: Lcd1602.java    From 1602A-androidthings with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * When the display powers up, it is configured as follows:
 * 1. Display clear
 * 2. Function set:
 *   DL = 1; 8-bit interface data
 *   N = 0; 1-line display
 *   F = 0; 5x8 dot character font
 * 3. Display on/off control:
 *   D = 0; Display off
 *   C = 0; Cursor off
 *   B = 0; Blinking off
 * 4. Entry mode set:
 *   I/D = 1; Increment by 1
 *   S = 0; No shift
 *
 * Note, however, that resetting the Arduino doesn't reset the LCD, so we
 * can't assume that it's in that state when a sketch starts (and the
 * Lcd1602a constructor is called).
 * </pre>
 */
public Lcd1602(boolean fourbitmode, String rs, String rw, String enable, String d0, String d1, String d2, String d3, String d4, String d5, String d6, String d7) throws IOException {
    PeripheralManager manager = PeripheralManager.getInstance();

    rsGpio = manager.openGpio(rs);
    rsGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);

    // we can save 1 pin by not using RW. Indicate by passing null instead of pin#
    if (rw != null) {
        rwGpio = manager.openGpio(rw);
        rwGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    }

    enableGpio = manager.openGpio(enable);
    enableGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);

    String[] dataPins = new String[]{d0, d1, d2, d3, d4, d5, d6, d7};
    for (int i = 0; i < (fourbitmode ? 4 : 8); i++) {
        dataGpios[i] = manager.openGpio(dataPins[i]);
        dataGpios[i].setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    }

    if (fourbitmode) {
        displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
    } else {
        displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
    }

    begin(16, 1);
}
 
Example #16
Source File: Ws2812b.java    From androidthings-cameraCar with Apache License 2.0 5 votes vote down vote up
private Ws2812b(String spiBusPort, @NonNull ColorToBitPatternConverter colorToBitPatternConverter) throws IOException {
    mColorToBitPatternConverter = colorToBitPatternConverter;
    mDevice = PeripheralManager.getInstance().openSpiDevice(spiBusPort);
    try {
        initSpiDevice(mDevice);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #17
Source File: NmeaGpsModule.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new NmeaGpsModule.
 *
 * @param uartName UART port name where the module is attached. Cannot be null.
 * @param baudRate Baud rate used for the module UART.
 * @param accuracy specified accuracy, in meters CEP.
 * @param handler optional {@link Handler} for software polling and callback events.
 */
public NmeaGpsModule(String uartName, int baudRate, float accuracy, Handler handler) throws IOException {
    try {
        PeripheralManager manager = PeripheralManager.getInstance();
        UartDevice device = manager.openUartDevice(uartName);
        init(device, baudRate, accuracy, handler);
    } catch (IOException | RuntimeException e) {
        close();
        throw e;
    }
}
 
Example #18
Source File: Servo.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new Servo that connects to the named pin and uses the specified frequency
 *
 * @param pin the PWM pin name
 * @param frequencyHz the frequency in Hertz
 * @throws IOException
 */
public Servo(String pin, double frequencyHz) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    Pwm device = pioService.openPwm(pin);
    try {
        connect(device, frequencyHz);
    } catch (IOException | RuntimeException e) {
        try {
            close();
        } catch (IOException | RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #19
Source File: Button.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new Button driver for the given GPIO pin name.
 * @param pin GPIO pin where the button is attached.
 * @param logicLevel Logic level when the button is considered pressed.
 * @throws IOException
 */
public Button(String pin, LogicState logicLevel) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    Gpio buttonGpio = pioService.openGpio(pin);
    try {
        connect(buttonGpio, logicLevel);
    } catch (IOException|RuntimeException e) {
        close();
        throw e;
    }
}
 
Example #20
Source File: Bmx280.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new BMP/BME280 sensor driver connected on the given bus and address.
 * @param bus I2C bus the sensor is connected to.
 * @param address I2C address of the sensor.
 * @throws IOException
 */
public Bmx280(String bus, int address) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    I2cDevice device = pioService.openI2cDevice(bus, address);
    try {
        connect(device);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #21
Source File: MotorHat.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
public MotorHat(String i2cBusName, int i2cAddress) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    I2cDevice device = pioService.openI2cDevice(i2cBusName, i2cAddress);
    try {
        initialize(device);
    } catch (IOException | RuntimeException e) {
        try {
            close();
        } catch (IOException | RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #22
Source File: Speaker.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Speaker connected to the given PWM pin name
 */
public Speaker(String pin) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    Pwm device = pioService.openPwm(pin);
    try {
        connect(device);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #23
Source File: Mma7660Fc.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new MMA7660FC driver connected to the given I2C bus.
 * @param bus
 * @throws IOException
 */
public Mma7660Fc(String bus) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    I2cDevice device = pioService.openI2cDevice(bus, I2C_ADDRESS);
    try {
        connect(device);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #24
Source File: FaBoThingsDeviceControl.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void initialize() {
    if (DEBUG) {
        Log.i(TAG, "FaBoThingsDeviceControl::initialize");
    }

    mManagerService = PeripheralManager.getInstance();

    initGpio();
}
 
Example #25
Source File: MainActivity.java    From androidthings-cameraCar with Apache License 2.0 5 votes vote down vote up
private void openUart(PeripheralManager service, String name, int baudRate) throws IOException {
    echoDevice = service.openUartDevice(name);
    // Configure the UART
    echoDevice.setBaudrate(baudRate);
    echoDevice.setDataSize(8);
    echoDevice.setParity(UartDevice.PARITY_NONE);
    echoDevice.setStopBits(1);

    Log.i(TAG, "Open UART device");

    echoDevice.registerUartDeviceCallback(mInputHandler, mCallback);
}
 
Example #26
Source File: Vcnl4200.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new VCNL4200 sensor driver connected to the given I2C bus.
 * @param bus I2C bus the sensor is connected to.
 * @param configuration Initial configuration of the sensor.
 * @throws IOException
 */
public Vcnl4200(String bus, Configuration configuration) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    I2cDevice device = pioService.openI2cDevice(bus, I2C_ADDRESS);
    try {
        connect(device, configuration);
    } catch (IOException|RuntimeException e) {
        try {
            close();
        } catch (IOException|RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #27
Source File: HomeActivity.java    From edison-candle with Apache License 2.0 5 votes vote down vote up
/**
 * Open a new LED connection to the provided port name
 * @throws IOException
 */
private Pwm openLed(String name) throws IOException {
    Pwm led = PeripheralManager.getInstance().openPwm(name);
    led.setPwmFrequencyHz(60.0f);
    led.setPwmDutyCycle(BRIGHTNESS_START);
    led.setEnabled(true);

    return led;
}
 
Example #28
Source File: CsnA2.java    From contrib-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes a new CsnA2 with a given baud rate and specific heating configurations.
 *
 * @param uartBus The UART bus to send data through
 * @param baudRate The symbol rate to send data
 * @param configuration A configuration object specifying heating parameters for all print tasks
 */
/* package */ CsnA2(String uartBus, int baudRate, Configuration configuration) throws IOException {
    UartDevice serial = PeripheralManager.getInstance().openUartDevice(uartBus);
    serial.setBaudrate(baudRate);
    serial.setDataSize(8);
    serial.setParity(UartDevice.PARITY_NONE);
    serial.setStopBits(1);
    mUartDevice = serial;

    begin(configuration);
}
 
Example #29
Source File: Tsl256x.java    From androidthings-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new TSL2561 driver connected to the given I2C bus.
 *
 * @param i2cName    I2C bus name the display is connected to
 * @param i2cAddress I2C address of the display
 * @throws IOException
 */
public Tsl256x(String i2cName, int i2cAddress) throws IOException {
    PeripheralManager pioService = PeripheralManager.getInstance();
    I2cDevice device = pioService.openI2cDevice(i2cName, i2cAddress);
    try {
        connect(device);
    } catch (IOException | RuntimeException e) {
        try {
            close();
        } catch (IOException | RuntimeException ignored) {
        }
        throw e;
    }
}
 
Example #30
Source File: Hd44780.java    From androidthings-drivers with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new Hd44780 driver connected to the named I2C bus and address
 * with the given geometry.
 *
 * @param i2cName     I2C bus name the display is connected to
 * @param i2cAddress  I2C address of the display
 * @param geometry    geometry of the LCD. See {@link Geometry}.
 * @param use5x10Dots True to use a 10 pixel high font, false for the 8 pixel (default). It only works
 *                    for some 1 line displays.
 * @throws IOException
 */
public Hd44780(String i2cName, int i2cAddress, @Geometry int geometry, boolean use5x10Dots) throws IOException {
    mLcdGeometry = GEOMETRIES[geometry];
    I2cDevice device = PeripheralManager.getInstance().openI2cDevice(i2cName, i2cAddress);
    try {
        init(device, use5x10Dots);
    } catch (IOException | RuntimeException e) {
        try {
            close();
        } catch (IOException | RuntimeException ignored) {
        }
        throw e;
    }
}