Device Access API
Proposal for Java ME 8

Package com.oracle.deviceaccess.dac

Interfaces and classes for writing analog outputs using a Digital to Analog Converter (DAC).

See: Description

Package com.oracle.deviceaccess.dac Description

Interfaces and classes for writing analog outputs using a Digital to Analog Converter (DAC).

One DAC converter can have several channels. Each channel can generate an analog output from numerical values that are converted to output voltages.

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

Using its ID
 DACChannel channel = (DACChannel) PeripheralManager.open(5);
 
Using its name and interface
 DACChannel channel = (DACChannel) PeripheralManager.open("LED", DACChannel.class, null);
 
Once the peripheral opened, an application can write output values to a DAC channel using methods of the DACChannel interface such as the generate method.
 channel.generate(brightness);
 
When done, the application should call the DACChannel.close method to close the DAC channel.
 channel.close();
 
The following sample codes give examples of using the DAC API:
 class VaryingDimmer implements GenerationRoundListener {
 
     private DACChannel channel = null;
 
     public void start(int channelID) throws IOException, NonAvailablePeripheralException, PeripheralNotFoundException {
         if (channel != null) {
             throw new InvalidStateException();
         }
         channel = (DACChannel) PeripheralManager.open(channelID);
         channel.setSamplingInterval(1000); // every 1000 milliseconds
         // Creates a series of samples varying from min value to max value
         int[] values = new int[10];
         int min = channel.getMinValue();
         int max = channel.getMaxValue();
         IntBuffer values = IntBuffer.wrap(new int[10]);
         createSamples(values, channel.getMinValue(), channel.getMaxValue(), 10);
         channel.startGeneration(values, this);
     }
 
     public void outputRoundCompleted(RoundCompletionEvent<DACChannel, IntBuffer> event) {
         try {
             // Replay the same sample series
             createSamples(event.getBuffer(), event.getPeripheral().getMinValue(), event.getPeripheral().getMaxValue(),
                     10);
         } catch (IOException ioe) {
             // Ignored
         }
     }
 
     // Creates a series of samples varying from min value to max value
     private void createSamples(IntBuffer buffer, int min, int max, int count) {
         for (int i = 0; i < count; i++) {
             buffer.put(min + (((max - min) / (count - 1)) * i));
         }
         buffer.flip();
     }
 
     public void stop() throws IOException {
         if (channel != null) {
             channel.stopGeneration();
             channel.close();
         }
     }
 
     public void failed(Throwable exception, DACChannel source) {
          // Ignored
     }
 }
 
Because of performance issue, procedures handling analog outputs, 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


ing HTML relocated from here