xbee_getanalog.3 2.81 KB
Newer Older
Franz's avatar
Franz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
.\" libxbee - a C library to aid the use of Digi's Series 1 XBee modules
.\"           running in API mode (AP=2).
.\" 
.\" Copyright (C) 2009  Attie Grande (attie@attie.co.uk)
.\" 
.\" This program is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\" 
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\" 
.\" You should have received a copy of the GNU General Public License
.\" along with this program.  If not, see <http://www.gnu.org/licenses/>.
.TH XBEE_GETPACKET 3  2009-11-01 "GNU" "Linux Programmer's Manual"
.SH NAME
xbee_hasanalog, xbee_getanalog
.SH SYNOPSIS
.B #include <xbee.h>
.sp
.BI "int xbee_hasanalog(xbee_pkt *" pkt ", int " sample ", int " input ");"
.sp
.BI "double xbee_getanalog(xbee_pkt *" pkt ", int " sample ", int " input ", double " Vref ");"
.ad b
.SH DESCRIPTION
The
.BR xbee_hasanalog ()
function will check the packet for the presence of an analog sample on the specified input.
.sp
The
.BR xbee_getanalog ()
function will read the packet and return the sample value for the specified analog input.
.sp
They both take 3 arguments, with the same purposes.
.sp
The argument
.I pkt
points to a packet that was previously retrieved with 
.BR xbee_getpacket ()
.sp
The argument
.I sample
selects the sample within the packet to use.
.sp
The argument
.I input
specifies which input you are interested in testing.
.sp
.BR xbee_getanalog ()
also takes a fourth argument that allows you to provide a
.I Vref
value. This allows the function to convert the raw ADC value into a voltage for you.
.SH "RETURN VALUE"
The
.BR xbee_hasanalog ()
function will return
.B 1
if the provided packet has sample data for the specified input, otherwise
.BR 0 .
.sp
The
.BR xbee_getanalog ()
function will return the raw ADC value (0 - 1023) if the provided packet has sample data for the specified input and Vref was given as zero.
If Vref was non-zero, then the return value will be the voltage read.
A
.B -1
will be returned if the packet does not contain sample data.
.sp
.SH EXAMPLE
To read sample data from previously made connection:
.in +4n
.nf
#include <xbee.h>
xbee_pkt *pkt;
double Vref = 3.3;
if ((pkt = xbee_getpacket(con)) != NULL) {
  if (xbee_hasanalog(pkt,0,0)) {
    printf("A0 read %fv\\n",xbee_getanalog(pkt,0,0,Vref));
  } else {
    printf("No A0 data\\n");
  }
  free(pkt);
}
.fi
.in
.SH AUTHOR
Attie Grande <attie@attie.co.uk> 
.SH "SEE ALSO"
.BR libxbee (3),
.BR xbee_pkt (3),
.BR xbee_getpacket (3),
.BR xbee_hasdigital (3),
.BR xbee_getdigital (3)