BA2D

Derived from: none

Declared in: be/device/A2D.h

Library: libdevice.so

[method summary]

The BA2D class lets you create objects that can read the GeekPort's a/d channels. Each BA2D object can read a single channel at a time; if you want to read all four channels simultaneously, you have to create four separate objects.

To retrieve a value from one of the a/d channels, you create a new BA2D object, open it on the channel you want, and then (repeatedly) invoke the object's Read() function. When you're through reading, you call Close() so some other object can open the channel.

Reading is a one-shot deal: For each Read() invocation, you get a single uint16 that stores the 12-bit ADC value in its least significant 12 bits. To get a series of successive values, you have to put the Read() call in a loop. Keep in mind that there's no sampling rate or other automatic time tethering. For example, if you want to read the ADC every tenth of a second, you have to impose the waiting period yourself (by snoozing between reads, for example).

The outline of a typical a/d-reading setup is shown below:

   #include <A2D.h>
   
   void ReadA2D1()
   {
      uint16 val;
      BA2D a2d;
   
      if (a2d.Open("A2D1") <= 0)
         return;
   
      while ( /* whatever */ ) {
   
         /* Read() returns the number of bytes that were
          * read; a successful read returns 2.
          */
         if (a2d.Read(&val) != 2) 
            break;
         ...
         snooze(1000);
      }
      a2d.Close();
   }


Constructor and Destructor


BA2D()

      BA2D(void)

Creates a new object that can open an ADC channel. The particular channel is specified in a subsequent Open() call. Constructing a new BA2D object doesn't affect the state of the ADC.


~BA2D()

      virtual ~BA2D()

Closes the channel that the object holds open (if any) and then destroys the object.


Member Functions


Open(), IsOpen(), Close()

      status_t Open(const char *name)
      bool IsOpen(void)

Open() opens the named ADC channel. The channel names are:

BA2D Channels
"A2D1"
"A2D2"
"A2D3"
"A2D4"

See the The ADC and DAC for an illustration that shows the correspondences between the channel names and the GeekPort connector pins.

Each channel can only be held open by one object at a time; you should close the channel as soon as you're finished with it. Furthermore, each BA2D object can only hold one channel open at a time. When you invoke Open(), the channel that the object currently has open is automatically closed--even if the channel that you're attempting to open is the channel that the object already has open. Opening an ADC channel doesn't affect the data in the channel itself.

IsOpen() returns true if the object holds an ADC channel open. Otherwise, it returns false.

Close() closes the object's connection to the channel without affecting the state of the hardware.

RETURN CODES

Open() returns a positive integer if the channel is successfully opened; otherwise, it returns B_ERROR.


Read()

      ssize_t Read(uint16 *adc_12_bit)

Causes the ADC to sample and convert (within a 12-bit range) the voltage level on the GeekPort pin that corresponds to the object's ADC channel. The 12-bit unsigned value is returned by reference in the adc_12_bit argument.

The object must Open() an ADC channel before calling Read().

RETURN CODES

Read() return B_ERROR if a channel isn't open, or if, for any other reason, the read failed. Otherwise it returns 2 (the number of bytes that were read).






The Be Book, in lovely HTML, for BeOS Release 4.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified November 10, 1998.