See: Description
Interface | Description |
---|---|
GenericBufferIODevice |
The
GenericBufferIODevice interface defines generic methods for accessing and controlling peripheral devices
using read and write operations. |
GenericDevice |
The
GenericDevice interface defines methods for setting and getting peripheral device-specific configuration
and access (I/O) controls as well as registering event listeners. |
GenericEventListener |
The
GenericEventListener interface defines methods for getting notified of events fired by peripheral devices
that implement the GenericDevice interface. |
Class | Description |
---|---|
GenericDeviceConfig |
The
GenericDeviceConfig class encapsulates the hardware addressing information of generic device. |
GenericDeviceControl<T> |
The class
GenericDeviceControl encapsulates a generic peripheral device's configuration and access (I/O)
controls. |
GenericEvent |
The
GenericEvent class encapsulates events fired by peripherals that implement the GenericDevice
interface. |
GenericPermission |
The
GenericPermission class defines permissions for g device access. |
I2CDevice
, SPIDevice
,
GPIOPin
or GPIOPort
...
This API offers 2 main interfaces:
GenericDevice
GenericBufferIODevice
GenericBufferIODevice
and byte buffer read and write operations.GenericDevice
instance for the device using its numerical ID, name, type
(interface) and/or properties:
GenericDevice device = (GenericDevice) PeripheralManager.open(17);
GeneriBufferIODevice device = PeripheralManager.open("STORAGE", GeneriBufferIODevice.class, null);
GenericDevice
or
GenericBufferIODevice
interfaces. When done, the application should call thedevice.read(buffer, 0, buffer.length);
GenericDevice.close()
method to close the Generic
device. The following sample codes give examples of using the Generic API to communicate Real Time Clock device:device.close();
Note that the preceding example is using a try-with-resources statement and that thepublic static final int EVT_ALARM = 0; public static final GenericDeviceControl<Byte> SECONDS = new GenericDeviceControl<>(0, Byte.class); public static final GenericDeviceControl<Byte> SEC_ALARM = new GenericDeviceControl<>(1, Byte.class); public static final GenericDeviceControl<Byte> MINUTES = new GenericDeviceControl<>(2, Byte.class); public static final GenericDeviceControl<Byte> MIN_ALARM = new GenericDeviceControl<>(3, Byte.class); public static final GenericDeviceControl<Byte> HR_ALARM = new GenericDeviceControl<>(4, Byte.class); public static final GenericDeviceControl<Byte> HOURS = new GenericDeviceControl<>(5, Byte.class); public static final GenericDeviceControl<Boolean> ALARM_ENABLED = new GenericDeviceControl<>(6, Boolean.class); // Sets the daily alarm for after some delay public void setAlarm(byte delaySeconds, byte delayMinutes, byte delayHours) throws IOException, PeripheralException { try (GenericDevice rtc = PeripheralManager.open("RTC", GenericDevice.class, (String) null)) { byte currentSeconds = rtc.getControl(SECONDS); byte currentMinutes = rtc.getControl(MINUTES); byte currentHours = rtc.getControl(HOURS); byte i = (byte) ((currentSeconds + delaySeconds) % 60); byte j = (byte) ((currentSeconds + delaySeconds) / 60); rtc.setControl(SEC_ALARM, i); i = (byte) ((currentMinutes + delayMinutes + j) % 60); j = (byte) ((currentMinutes + delayMinutes + j) / 60); rtc.setControl(MIN_ALARM, i); i = (byte) ((currentHours + delayHours + j) % 24); rtc.setControl(HR_ALARM, i); rtc.setEventListener(EVT_ALARM, new GenericEventListener() { public void eventDispatched(GenericEvent event) { GenericDevice rtc = event.getPeripheral(); // Notify application of alarm } }); // Enable alarm. rtc.setControl(ALARM_ENABLED, true); } }
GenericDevice.close()
method is automatically invoked
by the platform at the end of the statement. Unless otherwise noted, passing apublic static final int EVT_VOLUME_CHANGED = 0; public static final GenericDeviceControl<Float> MIC_VOLUME = new GenericDeviceControl<>(0, Float.class); public static final GenericDeviceControl<Float> MIC_SAMPLE_RATE = new GenericDeviceControl<>(1, Float.class); public static final GenericDeviceControl<Boolean> MIC_AUTOMATIC_GAIN = new GenericDeviceControl<>(2, Boolean.class); public static final GenericDeviceControl<Boolean> MIC_MUTE = new GenericDeviceControl<>(3, Boolean.class); public void audioCapture(ByteBuffer buffer, float sampleRate, boolean agc) throws IOException, PeripheralException { try (GenericBufferIODevice mic = PeripheralManager.open("MICROPHONE", GenericBufferIODevice.class, (String) null)) { mic.setControl(MIC_SAMPLE_RATE, sampleRate); mic.setControl(MIC_AUTOMATIC_GAIN, agc); mic.setControl(MIC_MUTE, false); mic.setEventListener(EVT_VOLUME_CHANGED, new GenericEventListener() { public void eventDispatched(GenericEvent event) { GenericDevice mic = event.getPeripheral(); try { float currentVolume = mic.getControl(MIC_VOLUME); // ... } catch (ClosedPeripheralException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); mic.read(buffer); } }
null
argument to a constructor or method in any class
or interface in this package will cause a NullPointerException
to be thrown.Copyright © 2012, 2013, Oracle and/or its affiliates. All rights reserved.
Legal Notices