BlackPWM.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 
31 #ifndef BLACKPWM_H_
32 #define BLACKPWM_H_
33 
34 #include "../BlackCore.h"
35 
36 #include <iostream>
37 #include <fstream>
38 #include <cmath>
39 
40 
41 
42 
43 namespace BlackLib
44 {
45 
49  enum pwmName { P8_13 = 0,
50  P8_19 = 1,
51  P9_14 = 2,
52  P9_16 = 3,
53  P9_21 = 4,
54  P9_22 = 5,
55  P9_42 = 6,
56 
64  };
65 
69  const std::string pwmNameMap[7] = { "P8_13",
70  "P8_19",
71  "P9_14",
72  "P9_16",
73  "P9_21",
74  "P9_22",
75  "P9_42",
76  };
77 
81  enum polarityType { straight = 0,
82  reverse = 1
83  };
84 
85 
86 
87 
88  // ######################################### BLACKCOREPWM DECLARATION STARTS ########################################## //
89 
96  class BlackCorePWM : virtual private BlackCore
97  {
98  private:
100  std::string pwmTestPath;
110  bool loadDeviceTree();
111 
119  std::string findPwmTestName(pwmName pwm);
120 
121 
122  protected:
127  std::string getPeriodFilePath();
128 
133  std::string getDutyFilePath();
134 
139  std::string getRunFilePath();
140 
145  std::string getPolarityFilePath();
146 
152 
153  public:
154 
164  BlackCorePWM(pwmName pwm);
165 
170  virtual ~BlackCorePWM();
171 
174  virtual std::string getValue() = 0;
175  };
176  // ########################################## BLACKCOREPWM DECLARATION ENDS ########################################### //
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187  // ########################################### BLACKPWM DECLARATION STARTS ############################################ //
188 
300  class BlackPWM : virtual private BlackCorePWM
301  {
302  private:
304  std::string periodPath;
305  std::string dutyPath;
306  std::string runPath;
307  std::string polarityPath;
310  public:
314  enum flags { periodFileErr = 0,
319  dtErr = 5,
322  cpmgrErr = 9,
323  ocpErr = 10
324  };
325 
344  BlackPWM(pwmName pwm);
345 
350  virtual ~BlackPWM();
351 
375  std::string getValue();
376 
400  std::string getPeriodValue();
401 
426  std::string getDutyValue();
427 
453  std::string getRunValue();
454 
480  std::string getPolarityValue();
481 
505  float getNumericValue();
506 
531  int64_t getNumericPeriodValue();
532 
560  int64_t getNumericDutyValue();
561 
562 
596  bool setDutyPercent(float percentage);
597 
637  bool setPeriodTime(uint64_t period, timeType tType = nanosecond);
638 
672  bool setSpaceRatioTime(uint64_t space, timeType tType = nanosecond);
673 
708  bool setLoadRatioTime(uint64_t load, timeType tType = nanosecond);
709 
737  bool setPolarity(polarityType polarity);
738 
766  bool setRunState(runValue state);
767 
792  void toggleRunState();
793 
818  void tooglePolarity();
819 
844  bool isRunning();
845 
870  bool isPolarityStraight();
871 
896  bool isPolarityReverse();
897 
924  bool fail();
925 
979  bool fail(BlackPWM::flags f);
980  };
981  // ########################################### BLACKPWM DECLARATION STARTS ############################################ //
982 
983 
984 
985 } /* namespace BlackLib */
986 
987 #endif /* BLACKPWM_H_ */
Definition: BlackPWM.h:81
void toggleRunState()
Toggles run state of pwm signal.
Definition: BlackPWM.cpp:536
Definition: BlackPWM.h:61
int64_t getNumericDutyValue()
Reads numeric duty value of pwm signal.
Definition: BlackPWM.cpp:338
Definition: BlackPWM.h:52
Definition: BlackPWM.h:50
Definition: BlackPWM.h:59
runValue
Definition: BlackDef.h:53
Definition: BlackPWM.h:49
virtual std::string getValue()=0
First declaration of this function.
bool setDutyPercent(float percentage)
Sets percentage value of duty cycle.
Definition: BlackPWM.cpp:360
errorCorePWM * pwmCoreErrors
is used to hold the errors of BlackCorePWM class
Definition: BlackPWM.h:99
std::string getPolarityFilePath()
Exports pwm polarity file name to derived class.
Definition: BlackPWM.cpp:174
std::string getPeriodValue()
Reads period value of pwm signal.
Definition: BlackPWM.cpp:220
bool setPeriodTime(uint64_t period, timeType tType=nanosecond)
Sets period value of pwm signal.
Definition: BlackPWM.cpp:390
int64_t getNumericPeriodValue()
Reads numeric period value of pwm signal.
Definition: BlackPWM.cpp:316
pwmName
Definition: BlackPWM.h:49
std::string getValue()
Reads percentage value of duty cycle.
Definition: BlackPWM.cpp:212
float getNumericValue()
Reads numeric percentage value of duty cycle.
Definition: BlackPWM.cpp:308
Definition: BlackPWM.h:316
errorCorePWM * getErrorsFromCorePWM()
Exports errorCorePWM struct to derived class.
Definition: BlackPWM.cpp:179
bool isPolarityStraight()
Checks polarity of pwm signal.
Definition: BlackPWM.cpp:524
bool setSpaceRatioTime(uint64_t space, timeType tType=nanosecond)
Sets space time value of pwm signal.
Definition: BlackPWM.cpp:421
Holds BlackCorePWM errors.
Definition: BlackErr.h:220
flags
Definition: BlackPWM.h:314
std::string runPath
is used to hold the run file path
Definition: BlackPWM.h:306
Definition: BlackDef.h:62
BlackPWM(pwmName pwm)
Constructor of BlackPWM class.
Definition: BlackPWM.cpp:197
Definition: BlackPWM.h:53
Definition: BlackPWM.h:54
bool isRunning()
Checks run state of pwm signal.
Definition: BlackPWM.cpp:519
std::string getRunValue()
Reads run value of pwm signal.
Definition: BlackPWM.cpp:264
std::string pwmTestPath
is used to hold the pwm_test (pwm device driver) path
Definition: BlackPWM.h:100
Definition: BlackPWM.h:314
Definition: BlackPWM.h:322
std::string getPeriodFilePath()
Exports pwm period file name to derived class.
Definition: BlackPWM.cpp:159
Definition: BlackPWM.h:317
Interacts with end user, to use PWM.
Definition: BlackPWM.h:300
virtual ~BlackCorePWM()
Destructor of BlackCorePWM class.
Definition: BlackPWM.cpp:53
bool setRunState(runValue state)
Sets run value of pwm signal.
Definition: BlackPWM.cpp:498
BlackCorePWM(pwmName pwm)
Constructor of BlackCorePWM class.
Definition: BlackPWM.cpp:42
std::string polarityPath
is used to hold the polarity file path
Definition: BlackPWM.h:307
bool setPolarity(polarityType polarity)
Sets polarity of pwm signal.
Definition: BlackPWM.cpp:479
std::string findPwmTestName(pwmName pwm)
Finds full name of pwm_test.
Definition: BlackPWM.cpp:96
Definition: BlackPWM.h:323
Definition: BlackPWM.h:60
bool loadDeviceTree()
Loads PWM overlays to device tree.
Definition: BlackPWM.cpp:59
Definition: BlackPWM.h:318
errorPWM * pwmErrors
is used to hold the errors of BlackPWM class
Definition: BlackPWM.h:303
polarityType
Definition: BlackPWM.h:81
Definition: BlackPWM.h:58
std::string getRunFilePath()
Exports pwm run file name to derived class.
Definition: BlackPWM.cpp:169
virtual ~BlackPWM()
Destructor of BlackPWM class.
Definition: BlackPWM.cpp:207
bool setLoadRatioTime(uint64_t load, timeType tType=nanosecond)
Sets load time value of pwm signal.
Definition: BlackPWM.cpp:450
Preparation phase of Beaglebone Black, to use PWM.
Definition: BlackPWM.h:96
const std::string pwmNameMap[7]
Definition: BlackPWM.h:69
Definition: BlackPWM.h:55
Definition: BlackPWM.h:321
Holds BlackPWM errors.
Definition: BlackErr.h:303
std::string dutyPath
is used to hold the duty file path
Definition: BlackPWM.h:305
Definition: BlackPWM.h:319
Definition: BlackPWM.h:63
Definition: BlackPWM.h:51
Definition: BlackPWM.h:82
bool fail()
Is used for general debugging.
Definition: BlackPWM.cpp:560
std::string getDutyFilePath()
Exports pwm duty file name to derived class.
Definition: BlackPWM.cpp:164
Definition: BlackPWM.h:57
Definition: BlackADC.cpp:36
std::string getDutyValue()
Reads duty value of pwm signal.
Definition: BlackPWM.cpp:242
pwmName pwmPinName
is used to hold the selected pwm pin name
Definition: BlackPWM.h:101
std::string getPolarityValue()
Reads polarity value of pwm signal.
Definition: BlackPWM.cpp:286
Definition: BlackPWM.h:315
Definition: BlackPWM.h:320
bool isPolarityReverse()
Checks polarity of pwm signal.
Definition: BlackPWM.cpp:529
std::string periodPath
is used to hold the period file path
Definition: BlackPWM.h:304
Definition: BlackPWM.h:62
void tooglePolarity()
Toggles polarity type of pwm signal.
Definition: BlackPWM.cpp:548
Base class of the other classes.
Definition: BlackCore.h:80
timeType
Definition: BlackDef.h:61