BlackADC.h
Go to the documentation of this file.
1  /*
2 
3  ####################################################################################
4  # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5  # Copyright (C) 2013-2015 by Yigit YUCE #
6  ####################################################################################
7  # #
8  # This file is part of BlackLib library. #
9  # #
10  # BlackLib library is free software: you can redistribute it and/or modify #
11  # it under the terms of the GNU Lesser General Public License as published by #
12  # the Free Software Foundation, either version 3 of the License, or #
13  # (at your option) any later version. #
14  # #
15  # BlackLib library is distributed in the hope that it will be useful, #
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18  # GNU Lesser General Public License for more details. #
19  # #
20  # You should have received a copy of the GNU Lesser General Public License #
21  # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22  # #
23  # For any comment or suggestion please contact the creator of BlackLib Library #
24  # at ygtyce@gmail.com #
25  # #
26  ####################################################################################
27 
28  */
29 
30 #ifndef BLACKADC_H_
31 #define BLACKADC_H_
32 
33 #include "../BlackCore.h"
34 
35 #include <cmath> // need for round() function in BlackADC::getParsedValue()
36 #include <string>
37 #include <fstream>
38 
39 
40 
41 
42 
43 
44 
45 namespace BlackLib
46 {
47 
51  enum adcName { AIN0 = 0,
52  AIN1 = 1,
53  AIN2 = 2,
54  AIN3 = 3,
55  AIN4 = 4,
56  AIN5 = 5,
57  AIN6 = 6
58  };
59 
63  enum digitAfterPoint { dap1 = 1,
64  dap2 = 2,
65  dap3 = 3
66  };
67 
68 
69 
70 
71 
72  // ######################################### BLACKCOREADC DECLARATION STARTS ########################################## //
73 
79  class BlackCoreADC : virtual private BlackCore
80  {
81  private:
83  std::string helperName;
91  bool loadDeviceTree();
92 
100  bool findHelperName();
101 
102 
103 
104  protected:
105 
110  std::string getHelperPath();
111 
117 
118 
119 
120  public:
121 
130  BlackCoreADC();
131 
136  virtual ~BlackCoreADC();
137 
138 
141  virtual std::string getValue() = 0;
142  };
143  // ########################################## BLACKCOREADC DECLARATION ENDS ########################################### //
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155  // ########################################### BLACKADC DECLARATION STARTS ############################################ //
156 
254  class BlackADC : virtual private BlackCoreADC
255  {
256  private:
258  std::string ainPath;
262  public:
263 
267  enum flags { cpmgrErr = 0,
268  ocpErr = 1,
269  helperErr = 2,
270  dtErr = 3,
271  readErr = 4
272  };
273 
292  BlackADC(adcName adc);
293 
298  virtual ~BlackADC();
299 
319  std::string getValue();
320 
340  int getNumericValue();
341 
372 
392  adcName getName();
393 
420  bool fail();
421 
465  bool fail(BlackADC::flags f);
466 
487  BlackADC& operator>>(std::string &readToThis);
488 
509  BlackADC& operator>>(int &readToThis);
510 
534  BlackADC& operator>>(float &readToThis);
535  };
536  // ############################################ BLACKADC DECLARATION ENDS ############################################# //
537 
538 
539 } /* namespace BlackLib */
540 
541 #endif /* BLACKADC_H_ */
int getNumericValue()
Reads analog input DC value(mV).
Definition: BlackADC.cpp:158
errorCoreADC * adcCoreErrors
is used to hold the errors of BlackCoreADC class
Definition: BlackADC.h:82
Preparation phase of Beaglebone Black, to use ADC.
Definition: BlackADC.h:79
std::string getValue()
Reads analog input DC value(mV).
Definition: BlackADC.cpp:129
std::string helperName
is used to hold the helper(analog input device driver) name
Definition: BlackADC.h:83
flags
Definition: BlackADC.h:267
Definition: BlackADC.h:267
virtual std::string getValue()=0
First declaration of this function.
Definition: BlackADC.h:271
std::string getHelperPath()
Exports helper path to derived class.
Definition: BlackADC.cpp:92
bool findHelperName()
Finds full name of helper.
Definition: BlackADC.cpp:74
Definition: BlackADC.h:52
Interacts with end user, to use ADC.
Definition: BlackADC.h:254
Definition: BlackADC.h:269
Definition: BlackADC.h:65
Holds BlackADC errors.
Definition: BlackErr.h:159
BlackADC(adcName adc)
Constructor of BlackADC class.
Definition: BlackADC.cpp:115
adcName ainName
is used to hold the selected adc name
Definition: BlackADC.h:259
Definition: BlackADC.h:55
Definition: BlackADC.h:51
Definition: BlackADC.h:268
digitAfterPoint
Definition: BlackADC.h:63
Definition: BlackADC.h:56
Definition: BlackADC.h:64
bool fail()
Is used for general debugging.
Definition: BlackADC.cpp:226
BlackCoreADC()
Constructor of BlackCoreADC class.
Definition: BlackADC.cpp:40
virtual ~BlackCoreADC()
Destructor of BlackCoreADC class.
Definition: BlackADC.cpp:48
Definition: BlackADC.h:63
float getConvertedValue(digitAfterPoint dap)
Reads converted analog input DC value(Volt).
Definition: BlackADC.cpp:179
Definition: BlackADC.h:270
std::string ainPath
is used to hold the AINx file path
Definition: BlackADC.h:258
adcName getName()
Exports analog input pin name.
Definition: BlackADC.cpp:152
Definition: BlackADC.h:57
Definition: BlackADC.h:53
bool loadDeviceTree()
Loads ADC overlay to device tree.
Definition: BlackADC.cpp:54
errorADC * adcErrors
is used to hold the errors of BlackADC class
Definition: BlackADC.h:257
adcName
Definition: BlackADC.h:51
virtual ~BlackADC()
Destructor of BlackADC class.
Definition: BlackADC.cpp:123
Definition: BlackADC.cpp:36
BlackADC & operator>>(std::string &readToThis)
Reads analog input DC value(mV) with ">>" operator.
Definition: BlackADC.cpp:249
Holds BlackCoreADC errors.
Definition: BlackErr.h:88
Definition: BlackADC.h:54
errorCoreADC * getErrorsFromCoreADC()
Exports errorCoreADC struct pointer to derived class.
Definition: BlackADC.cpp:98
Base class of the other classes.
Definition: BlackCore.h:80