|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface AnalogInput
A pin used for analog input.
An analog input pin can be used to measure voltage. AnalogInput instances are obtained by calling
IOIO.openAnalogInput(int).
Floating-point values scaled from 0 to 1 can be obtained by calling read(). Absolute
voltage levels can be obtained by calling getVoltage().
The instance is alive since its creation. The first read() call block for a few
milliseconds until the initial value is updated. If the connection with the IOIO drops at any
point, the instance transitions to a disconnected state, in which every attempt to use the pin
(except Closeable.close()) will throw a ConnectionLostException. Whenever Closeable.close()
is invoked the instance may no longer be used. Any resources associated with it are freed and can
be reused.
Typical usage:
AnalogInput potentiometer = ioio.openAnalogInput(40);
float value = potentiometer.read();
...
potentiometer.close(); // pin 40 can now be used for something else.
An alternate usage allows reading periodically sampled data without missing samples. The
setBuffer(int) method must first be called, for setting up an internal buffer for
queuing samples. Then, samples can be obtained by calling readBuffered() or
getVoltageBuffered(). These methods will block until a sample is available. If this is
undesirable, the available() method can be called first to check how many samples are
ready in the buffer. In case the buffer overflows, as result of the client not reading fast
enough, old samples will be dropped, and the client can check getOverflowCount() to
determine how many samples have been lost. The sample rate used for capturing samples can be
obtained by calling getSampleRate().
The non-buffered versions of the read methods will still behave normally when buffering is
enabled. The read() and getVoltage() methods will always return the most recent
value, regardless of the buffer state.
Typical usage:
AnalogInput potentiometer = ioio.openAnalogInput(40);
potentiometer.setBuffer(256);
for (int i = 0; i < 1024; ++i) {
// next line will block until at least one sample is available
float sample = potentiometer.readBuffered();
...
}
...
potentiometer.close(); // pin 40 can now be used for something else.
IOIO.openAnalogInput(int)| Method Summary | |
|---|---|
int |
available()
Gets the number of samples currently in the buffer. |
int |
getOverflowCount()
Gets the number of samples that have been dropped as result of overflow, since setBuffer(int) has been called. |
float |
getReference()
Gets the maximum value against which read() values are scaled. |
float |
getSampleRate()
Gets the sample rate used for obtaining buffered samples. |
float |
getVoltage()
Gets the analog input reading, as an absolute voltage in Volt units. |
float |
getVoltageBuffered()
Read a sample from the internal buffer. |
float |
getVoltageSync()
This is very similar to getVoltage(), but will wait for a new sample to arrive
before returning. |
float |
read()
Gets the analog input reading, as a scaled real value between 0 and 1. |
float |
readBuffered()
Read a sample from the internal buffer. |
float |
readSync()
This is very similar to read(), but will wait for a new sample to arrive before
returning. |
void |
setBuffer(int capacity)
Initializes or destroys an internal buffer, used for queuing sampled data. |
| Methods inherited from interface ioio.lib.api.Closeable |
|---|
close |
| Method Detail |
|---|
float getVoltage()
throws java.lang.InterruptedException,
ConnectionLostException
It typically takes a few milliseconds between when the instance is created and until the first value can be read. In this case, the method may block shortly. If this is a problem, the calling thread can be interrupted.
If a scaled value is desired, consider using read().
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.read()
float getVoltageSync()
throws java.lang.InterruptedException,
ConnectionLostException
getVoltage(), but will wait for a new sample to arrive
before returning. This is useful in conjunction with IOIO.sync(), in cases when we
want to guarantee the we are looking at a sample that has been captured strictly after
certain other commands have been executed.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.getVoltage(),
readSync()float getReference()
read() values are scaled.
float read()
throws java.lang.InterruptedException,
ConnectionLostException
It typically takes a few milliseconds between when the instance is created and until the first value can be read. In this case, the method may block shortly. If this is a problem, the calling thread can be interrupted.
If an absolute value is desired, consider using getVoltage().
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.getVoltage()
float readSync()
throws java.lang.InterruptedException,
ConnectionLostException
read(), but will wait for a new sample to arrive before
returning. This is useful in conjunction with IOIO.sync(), in cases when we want to
guarantee the we are looking at a sample that has been captured strictly after certain other
commands have been executed.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.read(),
getVoltageSync()
void setBuffer(int capacity)
throws ConnectionLostException
readBuffered() or getVoltageBuffered() for obtaining
buffered samples.
When called with argument of 0, the internal buffer is destroyed.
capacity - The maximum number of unread samples that can be buffered before overflow occurs.
ConnectionLostException - The connection with the IOIO is lost.
int getOverflowCount()
throws ConnectionLostException
setBuffer(int) has been called.
ConnectionLostException - The connection with the IOIO is lost.
int available()
throws ConnectionLostException
ConnectionLostException - The connection with the IOIO is lost.
float readBuffered()
throws java.lang.InterruptedException,
ConnectionLostException
Closeable.close()), the thread is interrupted (via
Thread.interrupt() or connection is lost. setBuffer(int) must be called
prior to this method for setting up an internal buffer for storing samples.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.getVoltageBuffered()
float getVoltageBuffered()
throws java.lang.InterruptedException,
ConnectionLostException
Closeable.close()), the thread is interrupted (via
Thread.interrupt() or connection is lost. setBuffer(int) must be called
prior to this method for setting up an internal buffer for storing samples.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.readBuffered()
float getSampleRate()
throws ConnectionLostException
ConnectionLostException - The connection with the IOIO is lost.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||