analog_in.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <iostream>
00025 #include "claraty/analog_in.h"
00026
00027 namespace claraty {
00028
00029
00030
00031
00032
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
00043
00044 if (gain == 0.0) {
00045 set_gain_for_V();
00046 set_offset_for_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
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 }