Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class BoardHardware

  1. Object
  2. Hardware
  3. BoardHardware
The headless backend’s Hardware: the same kernel interfaces as the Linux port, through the same C (cn1_hardware_impl.h, wrapped in cn1_backend_hardware.c). A gateway or sensor hub serves its REST API and drives its buses from one binary. Listener callbacks run on the pin’s own watcher thread, since a server has no event dispatch thread. Built for a host other than Linux every primitive answers -ENOSYS.

Methods

public static void install()Makes this the instance Hardware.getInstance() returns.
protected String rawList(int kind)kind: 0 GPIO chips, 1 I2C buses, 2 SPI devices, 3 serial ports, 4 CAN interfaces.
protected int rawBacklight(int op, int value)op: 0 read, 1 maximum, 2 write value.
protected int rawGpioOpen(String chip, int line, boolean output, boolean high, int bias, int edges)
protected int rawGpioRead(int handle)
protected int rawGpioWrite(int handle, boolean high)
protected int rawGpioWaitEdge(int handle, int timeoutMs, long[] timestampOut)
protected int rawI2cOpen(int bus, int address)
protected int rawI2cTransfer(int handle, byte[] write, int writeLen, byte[] read, int readLen)
protected int rawSpiOpen(int bus, int chipSelect, int mode, int speedHz, int bitsPerWord)
protected int rawSpiTransfer(int handle, byte[] tx, byte[] rx, int len)
protected int rawSerialOpen(String device, int baud, int dataBits, int parity, int stopBits)
protected int rawSerialRead(int handle, byte[] buf, int off, int len, int timeoutMs)
protected int rawSerialWrite(int handle, byte[] buf, int off, int len)
protected int rawPwmOpen(int chip, int channel)
protected int rawPwmConfigure(int handle, long periodNanos, long dutyNanos, boolean enabled)
protected int rawCanOpen(String iface)
protected int rawCanSend(int handle, int id, boolean extended, byte[] data, int len)
protected int rawCanReceive(int handle, int[] idOut, byte[] data, int timeoutMs)
protected int rawWatchdogOpen(int timeoutSeconds)
protected int rawWatchdogKick(int handle)
protected void rawClose(int handle, boolean disarm)
protected int getSupportedFeatures()Bit mask of the FEATURE_ constants this port implements.
public String[] listGpioChips()Names of the GPIO controllers on this device, for example gpiochip0.
public int[] listI2cBuses()Numbers of the I2C buses on this device (/dev/i2c-N on Linux).
public String[] listSpiDevices()SPI devices as bus.chipSelect strings, for example 0.1.
public String[] listSerialPorts()Device paths of the serial ports on this device, for example /dev/ttyAMA0 or /dev/ttyUSB0.
public String[] listCanInterfaces()Names of the CAN network interfaces, for example can0.
public int getBacklightBrightness()The current backlight brightness, from 0 to getMaxBacklightBrightness(), or -1 when not supported.
public int getMaxBacklightBrightness()The highest backlight brightness value, or -1 when not supported.
public void setBacklightBrightness(int value) throws HardwareExceptionSets the backlight brightness, clamped to the valid range.
protected int gpioOpen(String chip, int line, boolean output, boolean initialHigh, int bias, int edges) throws HardwareExceptionClaims a GPIO line and returns its handle.
protected boolean gpioRead(int handle) throws HardwareExceptionReads a GPIO line: true for high.
protected void gpioWrite(int handle, boolean high) throws HardwareExceptionDrives an output GPIO line.
protected int gpioWaitEdge(int handle, int timeoutMs, long[] timestampOut) throws HardwareExceptionWaits up to timeoutMs for an edge on an input line.
protected int i2cOpen(int bus, int address) throws HardwareExceptionOpens an I2C device and returns its handle.
protected void i2cTransfer(int handle, byte[] write, int writeLen, byte[] read, int readLen) throws HardwareExceptionPerforms one combined I2C transaction: writes writeLen bytes from write, then, with a repeated start and no stop between, reads readLen bytes into read.
protected int spiOpen(int bus, int chipSelect, int mode, int speedHz, int bitsPerWord) throws HardwareExceptionOpens and configures an SPI device and returns its handle.
protected void spiTransfer(int handle, byte[] tx, byte[] rx, int len) throws HardwareExceptionPerforms one full-duplex SPI transfer of len bytes.
protected int serialOpen(String device, int baud, int dataBits, int parity, int stopBits) throws HardwareExceptionOpens and configures a serial port and returns its handle.
protected int serialRead(int handle, byte[] buf, int off, int len, int timeoutMs) throws HardwareExceptionReads up to len bytes, waiting at most timeoutMs (negative waits forever) for the first one.
protected void serialWrite(int handle, byte[] buf, int off, int len) throws HardwareExceptionWrites all len bytes.
protected int pwmOpen(int chip, int channel) throws HardwareExceptionOpens a PWM channel and returns its handle.
protected void pwmConfigure(int handle, long periodNanos, long dutyNanos, boolean enabled) throws HardwareExceptionConfigures a PWM channel.
protected int canOpen(String iface) throws HardwareExceptionOpens a CAN interface and returns its handle.
protected void canSend(int handle, int id, boolean extended, byte[] data, int len) throws HardwareExceptionSends one CAN frame.
protected int canReceive(int handle, int[] idOut, byte[] data, int timeoutMs) throws HardwareExceptionWaits up to timeoutMs for a CAN frame.
protected int watchdogOpen(int timeoutSeconds) throws HardwareExceptionOpens the watchdog with a timeout and returns its handle.
protected void watchdogKick(int handle) throws HardwareExceptionResets the watchdog timer.
protected void close(int handle, boolean disarm)Closes any handle.

Inherited fields

Inherited methods

Method details

install

public static void install()
Makes this the instance Hardware.getInstance() returns. The server calls it as it starts; calling it again does nothing.

rawList

protected String rawList(int kind)
kind: 0 GPIO chips, 1 I2C buses, 2 SPI devices, 3 serial ports, 4 CAN interfaces. Names separated by newlines.

rawBacklight

protected int rawBacklight(int op, int value)
op: 0 read, 1 maximum, 2 write value.

rawGpioOpen

protected int rawGpioOpen(String chip, int line, boolean output, boolean high, int bias, int edges)

rawGpioRead

protected int rawGpioRead(int handle)

rawGpioWrite

protected int rawGpioWrite(int handle, boolean high)

rawGpioWaitEdge

protected int rawGpioWaitEdge(int handle, int timeoutMs, long[] timestampOut)

rawI2cOpen

protected int rawI2cOpen(int bus, int address)

rawI2cTransfer

protected int rawI2cTransfer(int handle, byte[] write, int writeLen, byte[] read, int readLen)

rawSpiOpen

protected int rawSpiOpen(int bus, int chipSelect, int mode, int speedHz, int bitsPerWord)

rawSpiTransfer

protected int rawSpiTransfer(int handle, byte[] tx, byte[] rx, int len)

rawSerialOpen

protected int rawSerialOpen(String device, int baud, int dataBits, int parity, int stopBits)

rawSerialRead

protected int rawSerialRead(int handle, byte[] buf, int off, int len, int timeoutMs)

rawSerialWrite

protected int rawSerialWrite(int handle, byte[] buf, int off, int len)

rawPwmOpen

protected int rawPwmOpen(int chip, int channel)

rawPwmConfigure

protected int rawPwmConfigure(int handle, long periodNanos, long dutyNanos, boolean enabled)

rawCanOpen

protected int rawCanOpen(String iface)

rawCanSend

protected int rawCanSend(int handle, int id, boolean extended, byte[] data, int len)

rawCanReceive

protected int rawCanReceive(int handle, int[] idOut, byte[] data, int timeoutMs)

rawWatchdogOpen

protected int rawWatchdogOpen(int timeoutSeconds)

rawWatchdogKick

protected int rawWatchdogKick(int handle)

rawClose

protected void rawClose(int handle, boolean disarm)

getSupportedFeatures

protected int getSupportedFeatures()
Bit mask of the FEATURE_ constants this port implements. Ports override this; the default supports nothing.

listGpioChips

public String[] listGpioChips()
Names of the GPIO controllers on this device, for example gpiochip0. Empty when there are none or GPIO is unsupported.

listI2cBuses

public int[] listI2cBuses()
Numbers of the I2C buses on this device (/dev/i2c-N on Linux).

listSpiDevices

public String[] listSpiDevices()
SPI devices as bus.chipSelect strings, for example 0.1.

listSerialPorts

public String[] listSerialPorts()
Device paths of the serial ports on this device, for example /dev/ttyAMA0 or /dev/ttyUSB0.

listCanInterfaces

public String[] listCanInterfaces()
Names of the CAN network interfaces, for example can0.

getBacklightBrightness

public int getBacklightBrightness()
The current backlight brightness, from 0 to getMaxBacklightBrightness(), or -1 when not supported.

getMaxBacklightBrightness

public int getMaxBacklightBrightness()
The highest backlight brightness value, or -1 when not supported.

setBacklightBrightness

public void setBacklightBrightness(int value) throws HardwareException
Sets the backlight brightness, clamped to the valid range.

Throws

HardwareException
when not supported or not permitted

gpioOpen

protected int gpioOpen(String chip, int line, boolean output, boolean initialHigh, int bias, int edges) throws HardwareException
Claims a GPIO line and returns its handle.

gpioRead

protected boolean gpioRead(int handle) throws HardwareException
Reads a GPIO line: true for high.

gpioWrite

protected void gpioWrite(int handle, boolean high) throws HardwareException
Drives an output GPIO line.

gpioWaitEdge

protected int gpioWaitEdge(int handle, int timeoutMs, long[] timestampOut) throws HardwareException
Waits up to timeoutMs for an edge on an input line. Returns one of EDGE_TIMEOUT, EDGE_RESULT_FALLING or EDGE_RESULT_RISING and stores the edge’s timestamp in nanoseconds in timestampOut[0]. Called from a background thread, never the event dispatch thread.

i2cOpen

protected int i2cOpen(int bus, int address) throws HardwareException
Opens an I2C device and returns its handle.

i2cTransfer

protected void i2cTransfer(int handle, byte[] write, int writeLen, byte[] read, int readLen) throws HardwareException
Performs one combined I2C transaction: writes writeLen bytes from write, then, with a repeated start and no stop between, reads readLen bytes into read. Either length may be zero.

spiOpen

protected int spiOpen(int bus, int chipSelect, int mode, int speedHz, int bitsPerWord) throws HardwareException
Opens and configures an SPI device and returns its handle.

spiTransfer

protected void spiTransfer(int handle, byte[] tx, byte[] rx, int len) throws HardwareException
Performs one full-duplex SPI transfer of len bytes. rx may be the same array as tx.

serialOpen

protected int serialOpen(String device, int baud, int dataBits, int parity, int stopBits) throws HardwareException
Opens and configures a serial port and returns its handle.

serialRead

protected int serialRead(int handle, byte[] buf, int off, int len, int timeoutMs) throws HardwareException
Reads up to len bytes, waiting at most timeoutMs (negative waits forever) for the first one. Returns the count read, 0 on timeout.

serialWrite

protected void serialWrite(int handle, byte[] buf, int off, int len) throws HardwareException
Writes all len bytes.

pwmOpen

protected int pwmOpen(int chip, int channel) throws HardwareException
Opens a PWM channel and returns its handle.

pwmConfigure

protected void pwmConfigure(int handle, long periodNanos, long dutyNanos, boolean enabled) throws HardwareException
Configures a PWM channel. Duty may not exceed the period.

canOpen

protected int canOpen(String iface) throws HardwareException
Opens a CAN interface and returns its handle.

canSend

protected void canSend(int handle, int id, boolean extended, byte[] data, int len) throws HardwareException
Sends one CAN frame.

canReceive

protected int canReceive(int handle, int[] idOut, byte[] data, int timeoutMs) throws HardwareException
Waits up to timeoutMs for a CAN frame. Returns the payload length, or -1 on timeout; the identifier goes into idOut[0] and idOut[1] is 1 for an extended identifier.

watchdogOpen

protected int watchdogOpen(int timeoutSeconds) throws HardwareException
Opens the watchdog with a timeout and returns its handle.

watchdogKick

protected void watchdogKick(int handle) throws HardwareException
Resets the watchdog timer.

close

protected void close(int handle, boolean disarm)
Closes any handle. disarm applies to a watchdog only: true stops it where the driver allows, false leaves it running so the device resets.