DUDS
Distributed Update of Data from Something
SysPwm.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 //#include <duds/hardware/interface/Pwm.hpp>
11 #include <fstream>
12 #include <chrono>
13 #include <boost/exception/info.hpp>
14 
15 // !@?!#?!#?
16 #undef linux
17 
18 namespace duds { namespace hardware { namespace interface { namespace linux {
19 
20 struct PwmError : virtual std::exception, virtual boost::exception { };
21 
22 typedef boost::error_info<struct Info_SysPwmChip, int> SysPwmChip;
23 typedef boost::error_info<struct Info_SysPwmChannel, int> SysPwmChannel;
24 typedef boost::error_info<struct Info_SysPwmPeriodNs, long>
26 typedef boost::error_info<struct Info_SysPwmDutyNs, long>
28 
35 class SysPwm /* : public Pwm */ {
36  std::fstream en;
37  std::fstream dc;
38  std::fstream per;
39  std::chrono::nanoseconds dutyNs;
40  std::chrono::nanoseconds periodNs;
41  bool running;
42 public:
43  SysPwm(int chip, int channel);
44  ~SysPwm();
45  void enable(bool state = true);
46  void disable() {
47  enable(false);
48  }
49  bool enabled() const {
50  return running;
51  }
52  std::chrono::nanoseconds dutyPeriod() const {
53  return dutyNs;
54  }
55  void dutyPeriod(const std::chrono::nanoseconds &ns);
56  void dutyZero() {
57  dutyPeriod(std::chrono::nanoseconds(0));
58  }
59  void dutyFull() {
60  dutyPeriod(periodNs);
61  }
62  double dutyCycle() const;
63  void dutyCycle(double ratio);
64  std::chrono::nanoseconds period() const {
65  return periodNs;
66  }
67  void period(const std::chrono::nanoseconds &ns);
68  void frequency(unsigned int hz);
69  unsigned int frequency() const;
70 };
71 
72 } } } }
std::chrono::nanoseconds dutyPeriod() const
Definition: SysPwm.hpp:52
boost::error_info< struct Info_SysPwmPeriodNs, long > SysPwmPeriodNs
Definition: SysPwm.hpp:25
boost::error_info< struct Info_SysPwmChannel, int > SysPwmChannel
Definition: SysPwm.hpp:23
This is a Linux-only PWM driver that I need for my eclipse project.
Definition: SysPwm.hpp:35
boost::error_info< struct Info_SysPwmChip, int > SysPwmChip
Definition: SysPwm.hpp:22
boost::error_info< struct Info_SysPwmDutyNs, long > SysPwmDutyNs
Definition: SysPwm.hpp:27
std::chrono::nanoseconds dutyNs
Definition: SysPwm.hpp:39
std::chrono::nanoseconds periodNs
Definition: SysPwm.hpp:40
std::chrono::nanoseconds period() const
Definition: SysPwm.hpp:64