12 #include <boost/exception/errinfo_file_name.hpp> 18 namespace duds {
namespace hardware {
namespace interface {
namespace linux {
20 static const char *
prefix =
"/sys/class/pwm/pwmchip";
24 std::ostringstream fname;
25 fname << prefix << chip <<
"/pwm" << channel <<
"/enable";
29 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
34 if (
en.fail() || (val > 1)) {
36 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
41 fname.seekp(-6, std::ios_base::cur);
43 per.open(fname.str());
46 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
52 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
55 periodNs = std::chrono::nanoseconds(val);
57 fname.seekp(-6, std::ios_base::cur);
58 fname <<
"duty_cycle";
62 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
68 SysPwmChannel(channel) << boost::errinfo_file_name(fname.str())
71 dutyNs = std::chrono::nanoseconds(val);
96 dc << ns.count() << std::endl;
111 per << ns.count() << std::endl;
120 std::chrono::nanoseconds t((std::chrono::nanoseconds::rep)(
128 std::chrono::nanoseconds((std::chrono::nanoseconds::rep)(
129 (1.0 / (
double)hz) * (
double)(std::nano::den))
135 return 1.0 / (double)
periodNs.count();
std::chrono::nanoseconds dutyPeriod() const
boost::error_info< struct Info_SysPwmPeriodNs, long > SysPwmPeriodNs
unsigned int frequency() const
boost::error_info< struct Info_SysPwmChannel, int > SysPwmChannel
void enable(bool state=true)
boost::error_info< struct Info_SysPwmChip, int > SysPwmChip
boost::error_info< struct Info_SysPwmDutyNs, long > SysPwmDutyNs
std::chrono::nanoseconds dutyNs
SysPwm(int chip, int channel)
static const char * prefix
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
std::chrono::nanoseconds periodNs
std::chrono::nanoseconds period() const