BlackLib::BlackADC Class Reference

Interacts with end user, to use ADC. More...

#include <BlackADC.h>

Inheritance diagram for BlackLib::BlackADC:

Public Types

enum  flags {
  cpmgrErr = 0,
  ocpErr = 1,
  helperErr = 2,
  dtErr = 3,
  readErr = 4
}
 

Public Member Functions

 BlackADC (adcName adc)
 Constructor of BlackADC class. More...
 
virtual ~BlackADC ()
 Destructor of BlackADC class. More...
 
std::string getValue ()
 Reads analog input DC value(mV). More...
 
int getNumericValue ()
 Reads analog input DC value(mV). More...
 
float getConvertedValue (digitAfterPoint dap)
 Reads converted analog input DC value(Volt). More...
 
adcName getName ()
 Exports analog input pin name. More...
 
bool fail ()
 Is used for general debugging. More...
 
bool fail (BlackADC::flags f)
 Is used for specific debugging. More...
 
BlackADCoperator>> (std::string &readToThis)
 Reads analog input DC value(mV) with ">>" operator. More...
 
BlackADCoperator>> (int &readToThis)
 Reads analog input DC value(mV) with ">>" operator. More...
 
BlackADCoperator>> (float &readToThis)
 Reads converted analog input DC value(volt) with ">>" operator. More...
 

Private Attributes

errorADCadcErrors
 is used to hold the errors of BlackADC class More...
 
std::string ainPath
 is used to hold the AINx file path More...
 
adcName ainName
 is used to hold the selected adc name More...
 

Additional Inherited Members

- Private Member Functions inherited from BlackLib::BlackCoreADC
 BlackCoreADC ()
 Constructor of BlackCoreADC class. More...
 
virtual ~BlackCoreADC ()
 Destructor of BlackCoreADC class. More...
 
std::string getHelperPath ()
 Exports helper path to derived class. More...
 
errorCoreADCgetErrorsFromCoreADC ()
 Exports errorCoreADC struct pointer to derived class. More...
 

Detailed Description

Interacts with end user, to use ADC.

This class is end node to use analog inputs. End users interact with analog inputs from this class. It includes public functions for reading analog values.

Example
EXAMPLE PROJECT FILE TREE:

   myAdcProject
   |-> src
       |-> BlackLib
           |-> BlackDirectory
               |-> BlackDirectory.cpp
               |-> BlackDirectory.h
           |-> BlackThread
               |-> BlackThread.cpp
               |-> BlackThread.h
           |-> BlackMutex
               |-> BlackMutex.cpp
               |-> BlackMutex.h
           |-> BlackTime
               |-> BlackTime.cpp
               |-> BlackTime.h
           |-> BlackADC
               |-> BlackADC.cpp
               |-> BlackADC.h
           |-> BlackGPIO
               |-> BlackGPIO.cpp
               |-> BlackGPIO.h
           |-> BlackI2C
               |-> BlackI2C.cpp
               |-> BlackI2C.h
           |-> BlackPWM
               |-> BlackPWM.cpp
               |-> BlackPWM.h
           |-> BlackSPI
               |-> BlackSPI.cpp
               |-> BlackSPI.h
           |-> BlackUART
               |-> BlackUART.cpp
               |-> BlackUART.h
           |-> BlackCore.cpp
           |-> BlackCore.h
           |-> BlackDef.h
           |-> BlackErr.h
           |-> BlackLib.h
       |-> myAdcProject.cpp


If BlackLib source files are located in your project like above example project file tree, you have to include BlackADC.h or another source files with adding this line to your project file (myAdcProject.cpp at the example):
#include "BlackLib/BlackADC/BlackADC.h"


If BlackLib source files are located at same level with your project file (myAdcProject.cpp at the example), you have to include BlackADC.h or another source files with adding this line to your project file:

// Filename: myAdcProject.cpp
// Author: Yiğit Yüce - ygtyce@gmail.com
#include <iostream>
#include "BlackLib/BlackADC/BlackADC.h"
int main()
{
std::cout << myAdc.getValue();
return 0;
}


You can use "using namespace BlackLib" also. You can get rid of writing "BlackLib::", with using this method.
// Filename: myAdcProject.cpp
// Author: Yiğit Yüce - ygtyce@gmail.com
#include <iostream>
#include "BlackLib/BlackADC/BlackADC.h"
using namespace BlackLib;
int main()
{
BlackADC myAdc(AIN0);
std::cout << myAdc.getValue();
return 0;
}

Member Enumeration Documentation

This enum is used to define ADC debugging flags.

Enumerator
cpmgrErr 

enumeration for errorCore::capeMgrError status

ocpErr 

enumeration for errorCore::ocpError status

helperErr 

enumeration for errorCoreADC::helperError status

dtErr 

enumeration for errorCoreADC::dtError status

readErr 

enumeration for errorADC::readError status

Constructor & Destructor Documentation

BlackLib::BlackADC::BlackADC ( adcName  adc)

Constructor of BlackADC class.

This function initializes errorADC struct and sets value path for reading analog values.

Parameters
[in]adcname of adc (enum),(AINx)
Example
std::cout << myAdc.getValue() << std::endl;
std::cout << myAdcPtr->getValue();
See also
getHelperPath()
adcName
BlackLib::BlackADC::~BlackADC ( )
virtual

Destructor of BlackADC class.

This function deletes errorADC struct pointer.

Member Function Documentation

bool BlackLib::BlackADC::fail ( )

Is used for general debugging.

Returns
True if any error occured, else false.
Example
myAdc.getNumericValue();
if( myAdc.fail() )
{
std::cout << "ERROR OCCURED" << std::endl;
}
else
{
std::cout << "EVERYTHING IS OK" << std::endl;
}
// Possible Output:
// EVERYTHING IS OK
See also
errorADC
bool BlackLib::BlackADC::fail ( BlackADC::flags  f)

Is used for specific debugging.

You can use this function, after call BlackADC member functions in your code. The input parameter is used for finding out status of selected error.

Parameters
[in]fspecific error type (enum)
Returns
Value of selected error.
Example
{
std::cout << "BlackADC INITIALIZATION FAILED" << std::endl;
}
else
{
std::cout << "BlackADC INITIALIZATION IS OK" << std::endl;
}
myAdc.getValue();
if( myAdc.fail(BlackLib::BlackADC::readErr) )
{
std::cout << "READING ERROR OCCURED" << std::endl;
}
else
{
std::cout << "READING IS OK" << std::endl;
}
// Possible Output:
// BlackADC INITIALIZATION IS OK
// READING IS OK
See also
errorADC
float BlackLib::BlackADC::getConvertedValue ( digitAfterPoint  dap)

Reads converted analog input DC value(Volt).

This function reads specified file from path, where defined at BlackADC::ainPath variable. This file holds analog input voltage at milivolt level. Then converts this value to volt level, according to input parameter.

Parameters
[in]dapconvertion level (enum),(dapX) Expansion: digit after point
Returns
converted analog input value as float. If file opening fails, it returns BlackLib::FILE_COULD_NOT_OPEN_FLOAT.
Example
float converted_dap1 = myAdc.getConvertedValue(BlackLib::dap1);
std::cout << "Analog Volt Value (in a.b form): " << converted_dap1 << " Volt" << std::endl;
usleep(1000); // give some time to device
float converted_dap3 = myAdc.getConvertedValue(BlackLib::dap3);
std::cout << "Analog Volt Value (in a.bcd form): " << converted_dap3 << " Volt" << std::endl;
// Possible Output:
// Analog Volt Value (in a.b form): 1.1 Volt
// Analog Volt Value (in a.bcd form): 1.085 Volt
See also
digitAfterPoint
adcName BlackLib::BlackADC::getName ( )

Exports analog input pin name.

Returns
BlackADC::adcName variable.
Example
std::cout << "My adc name: AIN" << static_cast<int>(myAdc.getName()) << std::endl;
std::cout << "My adc name: AIN" << (int)myAdc.getName() << std::endl;
std::cout << "My adc name: AIN" << myAdc.getName() << std::endl;
// Possible Output:
// My adc name: AIN0
// My adc name: AIN0
// My adc name: AIN0
int BlackLib::BlackADC::getNumericValue ( )

Reads analog input DC value(mV).

This function reads specified file from path, where defined at BlackADC::ainPath variable. This file holds analog input voltage at milivolt level.

Returns
integer type analog input value. If file opening fails, it returns BlackLib::FILE_COULD_NOT_OPEN_INT.
Example
int val = myAdc.getNumericValue();
std::cout << "Analog mV Value: " << val << " mV";
// Possible Output:
// Analog mV Value: 1085 mV
std::string BlackLib::BlackADC::getValue ( )
virtual

Reads analog input DC value(mV).

This function reads specified file from path, where defined at BlackADC::ainPath variable. This file holds analog input voltage at milivolt level.

Returns
String type analog input value. If file opening fails, it returns BlackLib::FILE_COULD_NOT_OPEN_STRING.
Example
std::string val = myAdc.getValue();
std::cout << "Analog mV Value: " << val << " mV";
// Possible Output:
// Analog mV Value: 1085 mV

Implements BlackLib::BlackCoreADC.

BlackADC & BlackLib::BlackADC::operator>> ( std::string &  readToThis)

Reads analog input DC value(mV) with ">>" operator.

This function reads specified file from path, where defined at BlackADC::ainPath variable, with ">>" operator. This file holds analog input voltage at milivolt level.

Parameters
[in]&readToThisread value and save this value to this variable. If file opening fails, this functions sets BlackLib::FILE_COULD_NOT_OPEN_STRING to variable.
Example
std::string val;
myAdc >> val;
std::cout << "Analog mV Value: " << val << " mV";
// Possible Output:
// Analog mV Value: 1085 mV
BlackADC & BlackLib::BlackADC::operator>> ( int &  readToThis)

Reads analog input DC value(mV) with ">>" operator.

This function reads specified file from path, where defined at BlackADC::ainPath variable, with ">>" operator. This file holds analog input voltage at milivolt level.

Parameters
[in]&readToThisread value and save this value to this variable. If file opening fails, this functions sets BlackLib::FILE_COULD_NOT_OPEN_INT to variable.
Example
int val;
myAdc >> val;
std::cout << "Analog mV Value: " << val << " mV";
// Possible Output:
// Analog mV Value: 1085 mV
BlackADC & BlackLib::BlackADC::operator>> ( float &  readToThis)

Reads converted analog input DC value(volt) with ">>" operator.

This function reads specified file from path, where defined at BlackADC::ainPath variable, with ">>" operator. This file holds analog input voltage at milivolt level. Then converts this value to volt level at BlackLib::dap3 mode.

Parameters
[in]&readToThisread value and save this value to this variable. If file opening fails, this functions sets BlackLib::FILE_COULD_NOT_OPEN_FLOAT to variable.
Example
float val;
myAdc >> val;
std::cout << "Analog Volt Value (in a.bcd form): " << val << " Volt" << std::endl;
// Possible Output:
// Analog Volt Value (in a.bcd form): 1.085 Volt
See also
getConvertedValue()

Member Data Documentation

errorADC* BlackLib::BlackADC::adcErrors
private

is used to hold the errors of BlackADC class

adcName BlackLib::BlackADC::ainName
private

is used to hold the selected adc name

std::string BlackLib::BlackADC::ainPath
private

is used to hold the AINx file path


The documentation for this class was generated from the following files: