int xbee_hasanalog(xbee_pkt *pkt,int sample, int input);
double xbee_getanalog(xbee_pkt *pkt,int sample, int input, double Vref);
The xbee_getanalog() function will read the packet and return the sample value for the specified analog input.
They both take 3 arguments, with the same purposes.
The argument pkt points to a packet that was previously retrieved with xbee_getpacket()
The argument sample selects the sample within the packet to use.
The argument input specifies which input you are interested in testing.
xbee_getanalog() also takes a fourth argument that allows you to provide a Vref value. This allows the function to convert the raw ADC value into a voltage for you.
The 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 -1 will be returned if the packet does not contain sample data.
#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,xbee_getanalog(pkt,0,0,Vref)); } else { printf("No A0 data); } free(pkt); }