Follow this link to skip to the main content

analog_in.cc

Go to the documentation of this file.
00001 // -*-c++-*- 
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /** 
00004  * @file  analog_in.cc
00005  *
00006  * Analog I/O functions.
00007  *
00008  * <br>@b Designer(s):  Issa Nesnas,
00009  *                      Won Kim
00010  * <br>@b Author(s):    Won Kim,
00011  *                      Issa Nesnas
00012  * <br>@b Date:         August 16, 2002
00013  *
00014  * <b>Software License:</b><br>
00015  * <code>  http://claraty.jpl.nasa.gov/license/open_src/  or
00016  *         file: license/open_src.txt  </code>
00017  *
00018  * &copy; 2006, Jet Propulsion Laboratory, California Institute of Technology<br>
00019  *
00020  * $Revision: 1.3 $
00021  */ 
00022 //-----------------------------------------------------------------------------
00023 
00024 #include <iostream>
00025 #include "claraty/analog_in.h"
00026 
00027 namespace claraty {
00028 
00029 // #define VERBOSE              // for debugging
00030 
00031 //-------------------------------------------------------------------------
00032 //------------------------<< analog_in Functions >>---------------------------
00033 //-------------------------------------------------------------------------
00034 
00035 AI::AI (AI_impl& ai_impl, int channel, float gain, float offset) :
00036   _ai_impl (ai_impl),
00037   _channel (channel),
00038   _gain (gain),
00039   _offset (offset)
00040 {
00041   /*
00042    *    if gain is 0 (default), assume conversion to Volt
00043    */
00044   if (gain == 0.0) {
00045     set_gain_for_V();           // unit in V
00046     set_offset_for_V();         // unit in V
00047   }
00048 
00049 #ifdef VERBOSE
00050   cout << "AI: channel = " << channel << "; gain = " << dec << _gain << "; offset = " << _offset << endl;
00051 #endif
00052 }
00053 
00054 float AI::input()
00055 {
00056   float data = (float) _ai_impl.input(_channel);
00057 
00058   // return ( data * _gain + _offset);
00059 
00060   float data2 = data * _gain + _offset;
00061 
00062 #ifdef VERBOSE
00063   cout << "AI::input()" << endl;
00064   cout << " _ai_impl.input(" << dec << _channel <<"): " << endl;
00065   cout << " raw data = " << hex << data << endl;
00066   cout << " gain = " << dec << _gain << "; offset = " << _offset << endl;
00067   cout << " converted data = " << dec << data2 << endl;
00068 #endif
00069 
00070   return data2;
00071 }
00072 //-------------------------------------------------------------------------
00073 
00074 void AI::set_gain_for_V()
00075 {
00076   _gain = _ai_impl.get_gain_for_V(_channel);
00077 }
00078 //-------------------------------------------------------------------------
00079 
00080 void AI::set_offset_for_V()
00081 {
00082   _offset = _ai_impl.get_offset_for_V(_channel);
00083 }
00084 //-------------------------------------------------------------------------
00085 
00086 } // namespace claraty