Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class 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
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()getMaxBacklightBrightness
public int getMaxBacklightBrightness()The highest backlight brightness value, or
-1 when not supported.setBacklightBrightness
public void setBacklightBrightness(int value)
throws HardwareExceptionSets 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 HardwareExceptionClaims a GPIO line and returns its handle.
Throws
gpioRead
protected boolean gpioRead(int handle)
throws HardwareExceptionReads a GPIO line:
true for high.Throws
gpioWrite
protected void gpioWrite(int handle, boolean high)
throws HardwareExceptionDrives an output GPIO line.
Throws
gpioWaitEdge
protected int gpioWaitEdge(int handle, int timeoutMs, long[] timestampOut)
throws HardwareExceptionWaits 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.Throws
i2cOpen
protected int i2cOpen(int bus, int address)
throws HardwareExceptionOpens an I2C device and returns its handle.
Throws
i2cTransfer
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. Either length may be zero.Throws
spiOpen
protected int spiOpen(int bus, int chipSelect, int mode, int speedHz, int bitsPerWord)
throws HardwareExceptionOpens and configures an SPI device and returns its handle.
Throws
spiTransfer
protected void spiTransfer(int handle, byte[] tx, byte[] rx, int len)
throws HardwareExceptionPerforms one full-duplex SPI transfer of
len bytes. rx may be the
same array as tx.Throws
serialOpen
protected int serialOpen(String device, int baud, int dataBits, int parity, int stopBits)
throws HardwareExceptionOpens and configures a serial port and returns its handle.
Throws
serialRead
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. Returns the count read, 0 on timeout.Throws
serialWrite
protected void serialWrite(int handle, byte[] buf, int off, int len)
throws HardwareExceptionWrites all
len bytes.Throws
pwmOpen
protected int pwmOpen(int chip, int channel)
throws HardwareExceptionOpens a PWM channel and returns its handle.
Throws
pwmConfigure
protected void pwmConfigure(int handle, long periodNanos, long dutyNanos, boolean enabled)
throws HardwareExceptionConfigures a PWM channel. Duty may not exceed the period.
Throws
canOpen
protected int canOpen(String iface)
throws HardwareExceptionOpens a CAN interface and returns its handle.
Throws
canSend
protected void canSend(int handle, int id, boolean extended, byte[] data, int len)
throws HardwareExceptionSends one CAN frame.
Throws
canReceive
protected int canReceive(int handle, int[] idOut, byte[] data, int timeoutMs)
throws HardwareExceptionWaits 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.Throws
watchdogOpen
protected int watchdogOpen(int timeoutSeconds)
throws HardwareExceptionOpens the watchdog with a timeout and returns its handle.
Throws
watchdogKick
protected void watchdogKick(int handle)
throws HardwareExceptionResets the watchdog timer.
Throws
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.