Skip to content

Commit

Permalink
Remove unused return values, add exceptions where suitable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Sommer committed Apr 17, 2013
1 parent c975b6b commit ed9d6a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
64 changes: 31 additions & 33 deletions cPWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// Simple C++ class wrapper for beaglebone PWM eHRPWM interface

#include "cPWM.h"
#include <iostream>
#include <stdexcept>
#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -98,11 +98,13 @@ cPWM::cPWM(int id)
* @param[in] nanoseconds: duty cycle time in nanoseconds for A channel
*
*/
int cPWM::DutyA_ns(unsigned int nanoseconds)
void cPWM::DutyA_ns(unsigned int nanoseconds)
{
cPWM::DutyA_ns = nanoseconds;
sysfsfid_dutyA_ns << nanoseconds << std::endl;
return 1;
if(nanoseconds > cPWM::Period_ns)
throw std::out_of_range("DutyA_ns: ");

cPWM::DutyA_ns = nanoseconds;
sysfsfid_dutyA_ns << nanoseconds << std::endl;
}

/**
Expand All @@ -111,11 +113,13 @@ int cPWM::DutyA_ns(unsigned int nanoseconds)
* @param[in] percent: duty cycle time in percent for A channel
*
*/
int cPWM::DutyA_percent(unsigned int percent)
void cPWM::DutyA_percent(unsigned int percent)
{
if(percent > 100)
throw std::out_of_range("DutyA_percent: ");

cPWM::DutyA_percent = percent;
sysfsfid_dutyA_percent << percent << std::endl;
return 1;
}

/**
Expand All @@ -124,11 +128,13 @@ int cPWM::DutyA_percent(unsigned int percent)
* @param[in] nanoseconds: duty cycle time in nanoseconds for B channel
*
*/
int cPWM::DutyB_ns(unsigned int nanoseconds)
void cPWM::DutyB_ns(unsigned int nanoseconds)
{
cPWM::dutyB_ns = nanoseconds;
sysfsfid_dutyB_ns << nanoseconds << std::endl;
return 1;
if(nanoseconds > cPWM::Period_ns)
throw std::out_of_range("DutyB_ns: ");

cPWM::dutyB_ns = nanoseconds;
sysfsfid_dutyB_ns << nanoseconds << std::endl;
}


Expand All @@ -138,11 +144,13 @@ int cPWM::DutyB_ns(unsigned int nanoseconds)
* @param[in] percent: duty cycle time in percent for B channel
*
*/
int cPWM::DutyB_percent(unsigned int percent)
void cPWM::DutyB_percent(unsigned int percent)
{
cPWM::DutyB_percent = percent;
sysfsfid_dutyB_percent << percent << std::endl;
return 1;
if(percent > 100)
throw std::out_of_range("DutyB_percent: ");

cPWM::DutyB_percent = percent;
sysfsfid_dutyB_percent << percent << std::endl;
}


Expand All @@ -152,11 +160,10 @@ int cPWM::DutyB_percent(unsigned int percent)
* @param[in] nanoseconds: period time in nanoseconds
*
*/
int cPWM::Period_ns(unsigned int nanoseconds)
void cPWM::Period_ns(unsigned int nanoseconds)
{
cPWM::Period_ns = nanoseconds;
sysfsfid_period_ns << nanoseconds << std::endl;
return 1;
}

/**
Expand All @@ -165,11 +172,10 @@ int cPWM::Period_ns(unsigned int nanoseconds)
* @param[in] freq_Hz: PWM frequency in Hz
*
*/
int cPWM::Period_freq(unsigned int freq_Hz)
void cPWM::Period_freq(unsigned int freq_Hz)
{
cPWM::Period_freq = freq_Hz;
sysfsfid_period_freq << freq_Hz<< std::endl;
return 1;
}

/**
Expand All @@ -178,7 +184,7 @@ int cPWM::Period_freq(unsigned int freq_Hz)
* @param[in] polarity polarity
*
*/
int cPWM::PolarityA(Polarity polarity)
void cPWM::PolarityA(Polarity polarity)
{
switch (polarity)
{
Expand All @@ -188,32 +194,28 @@ int cPWM::PolarityA(Polarity polarity)
break;
}
cPWM::polarityA = polarity;

return 1;
}

/**
* Set the A channel to run status
*
*
*/
int cPWM::RunA()
void cPWM::RunA()
{
sysfsfid_runA << "1" << std::endl;
cPWM::runA = 1;
return 1;
}

/**
* Stop the A channel
*
*
*/
int cPWM::StopA()
void cPWM::StopA()
{
sysfsfid_runA << "0" << std::endl;
cPWM::runA = 0;
return 1;
}

/**
Expand All @@ -222,7 +224,7 @@ int cPWM::StopA()
* @param[in] polarity polarity
*
*/
int cPWM::PolarityB(Polarity polarity)
void cPWM::PolarityB(Polarity polarity)
{
switch (polarity)
{
Expand All @@ -232,31 +234,27 @@ int cPWM::PolarityB(Polarity polarity)
break;
}
cPWM::polarityB = polarity;

return 1;
}

/**
* Set the B channel to run
*
*/

int cPWM::RunB()
void cPWM::RunB()
{
cPWM::runB = 1;
sysfsfid_runB << "1" << std::endl;
return 1;
}

/**
* Stop the B channel
*
*/
int cPWM::StopB()
void cPWM::StopB()
{
cPWM::runB = 0;
sysfsfid_runB << "0" << std::endl;
return 1;
}

/**
Expand Down
24 changes: 12 additions & 12 deletions cPWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ Define files to match sysfs tree:
cPWM(int id);
virtual ~cPWM();

int DutyA_ns(unsigned int nanoseconds);
int DutyA_percent(unsigned int percent); //TODO: check if floats are possible
void DutyA_ns(unsigned int nanoseconds);
void DutyA_percent(unsigned int percent); //TODO: check if floats are possible

int DutyB_ns(unsigned int nanoseconds);
int DutyB_percent(unsigned int percent); //TODO: check if floats are possible
void DutyB_ns(unsigned int nanoseconds);
void DutyB_percent(unsigned int percent); //TODO: check if floats are possible

int Period_ns(unsigned int nanoseconds);
int Period_freq(unsigned int freq_Hz);
void Period_ns(unsigned int nanoseconds);
void Period_freq(unsigned int freq_Hz);

int PolarityA(cPWM::Polarity polarity);
int RunA();
int StopA();
int PolarityB(cPWM::Polarity polarity);
int RunB();
int StopB();
void PolarityA(cPWM::Polarity polarity);
void RunA();
void StopA();
void PolarityB(cPWM::Polarity polarity);
void RunB();
void StopB();
};

} /* namespace cPWM */
Expand Down

0 comments on commit ed9d6a8

Please sign in to comment.