QuadroCopter  0.1.4
pwmDevice.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2017 Michael Brookes
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef BEAGLEBONE_PWM_PWMDEVICE_H
19 #define BEAGLEBONE_PWM_PWMDEVICE_H
20 
21 #include <fstream>
22 #include <string>
23 #include <exception>
24 #include "../interfaces/IDevice.h"
25 #include "../overlays/pinOverlay.h"
26 #include "./overlays/pwmOverlay.h"
27 
28 namespace quadro {
29 
30  using namespace overlays;
31 
32  namespace pwm {
33 
38  class pwmDevice : public IDevice, pwmOverlay {
39 
40  public:
41 
46  pwmDevice() { };
47 
55  pwmDevice( pinBlocks _block, PWMPins _pin ) throw( pwmSetupException& );
56 
60  enum valType {
61  Run,
62  Duty,
67  Power_RunTime_Suspended
68  };
69 
72 
73  string powerControlStr;
74 
81  long get( valType _vt );
82 
89  void set( valType _vt, long _val );
90 
96  void setPinNum( PWMPins _pin );
97 
103  void setBlockNum( pinBlocks _block );
104 
105  private:
106 
107  valType VT;
108 
114  void readDevice( valType _vt );
115 
122  short readDevice( size_t _bufferSize );
123 
129  void initDevice() throw( pwmSetupException& );
130 
135  int connectToDevice() { return 1; }
136 
144  int writeToDevice( size_t _bufferSize ) throw( pwmSetupException& );
145 
153  void writeToDevice( valType _vt, long _val ) throw( pwmSetupException& );
154 
161  int openDevice() throw( pwmSetupException& );
162 
167  long getCurrentReading( valType _vt );
168 
174  char* getFilePath();
175 
181  void setValType( valType _vt );
182 
188  void setWriteVal( long _val );
189 
193  void setFilePaths();
194 
195  long val2Write;
196 
197  ifstream PWMFile;
198 
199  string currentReading;
200 
201  overlays::pinOverlay* _pinOverlay;
202 
203  char dutyPath[50];
204 
205  char periodPath[50];
206 
207  char runPath[50];
208 
209  char polarityPath[50];
210 
211  char powerControlPath[100];
212 
213  char powerRunTime_ActivePath[100];
214 
215  char powerRunTime_SuspendedPath[100];
216 
217  };
218 
219  }
220 
221 }
222 
223 #endif //BEAGLEBONE_PWM_PWMDEVICE_H
pwmDevice()
Definition: pwmDevice.h:46
pinBlocks
Definition: overlayBase.h:43
Power_Control Value Type.
Definition: pwmDevice.h:65
Polarity Value Type.
Definition: pwmDevice.h:64
Definition: pinOverlay.h:32
Power_RunTime_Active Value Type.
Definition: pwmDevice.h:66
valType
Definition: pwmDevice.h:60
Definition: pwmOverlay.h:31
Run Value Type.
Definition: pwmDevice.h:61
Period Value Type.
Definition: pwmDevice.h:63
PWMPins pinNum
stores the PWM device pin num
Definition: pwmDevice.h:71
Definition: pwmDevice.h:38
Definition: aeronautics.h:23
string powerControlStr
stores the current power setting string
Definition: pwmDevice.h:73
Definition: pwmSetupException.h:17
Definition: IDevice.h:27
pinBlocks blockNum
stores the PWM device block num
Definition: pwmDevice.h:70
Duty Value Type.
Definition: pwmDevice.h:62
PWMPins
PinNum refers to a exposed PWM Pin on your BBB, this enum can be expanded to include more if required...
Definition: overlayBase.h:51