Device Access API
Proposal for Java ME 8

Package com.oracle.deviceaccess.adc

Interfaces and classes for reading analog inputs using an Analog to Digital Converter (ADC).

See: Description

Package com.oracle.deviceaccess.adc Description

Interfaces and classes for reading analog inputs using an Analog to Digital Converter (ADC).

One ADC converter can have several channels. Each channel can sample a continuous input voltage and convert it to a numerical value.

In order to access and control a specific ADC channel, an application should first open and obtain an ADCChannel instance for the ADC channel the application wants to access and control, using its numerical ID, name, type (interface) and/or properties:

Using its ID
 ADCChannel channel = PeripheralManager.open(8);
 
Using its name and interface
 ADCChannel channel = PeripheralManager.open("TEMPERATURE", ADCChannel.class, null);
 
Once the peripheral opened, the application can read or monitor sampled input values using methods of the ADCChannel interface such as the acquire method.
 int temp = channel.acquire();
 
When done, the application should call the ADCChannel.close() method to close ADC channel.
 channel.close();
 
The following sample codes give examples of using the ADC API:
 class ADCAcquisition implements AcquisitionRoundListener {
 
     private ADCChannel channel = null;
 
     public void start(int channelID) throws IOException, NonAvailablePeripheralException, PeripheralNotFoundException {
         channel = (ADCChannel) PeripheralManager.open(channelID);
         channel.setSamplingInterval(100); // every 100 milliseconds
         int[] values = new int[10];
         channel.startAcquisition(IntBuffer.wrap(values), this);
     }
 
     public void inputRoundCompleted(RoundCompletionEvent<ADCChannel, IntBuffer> event) {
         IntBuffer buffer = event.getBuffer();
         while (buffer.hasRemaining()) {
             int value = buffer.get();
             // Handle value...
         }
     }
 
     public void stop() throws IOException {
         if (channel != null) {
             channel.stopAcquisition();
             channel.close();
         }
     }
 }
 
 class ADCThreshold implements MonitoringListener {
 
     private ADCChannel channel = null;
 
     public void start(int channelID, int low, int high) throws IOException, NonAvailablePeripheralException,
             PeripheralNotFoundException {
         channel = (ADCChannel) PeripheralManager.open(channelID);
         channel.setSamplingInterval(100); // every 100 milliseconds
         channel.startMonitoring(low, high, this);
     }
 
     public void thresholdReached(MonitoringEvent event) {
         if (event.getType() == MonitoringEvent.OUT_OF_RANGE) {
             int value = event.acquire();
             // Handle condition...
         }
     }
 
     public void stop() throws IOException {
         if (channel != null) {
             channel.stopMonitoring();
             channel.close();
         }
     }
 }
 
Because of performance issue, procedures handling analog inputs, and especially event listeners, should be implemented to be as fast as possible.

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Device Access API
Proposal for Java ME 8