BlackGPIO.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 #ifndef BLACKGPIO_H_
31 #define BLACKGPIO_H_
32 
33 #include "../BlackCore.h"
34 
35 #include <fstream>
36 #include <string>
37 
38 
39 
40 
41 
42 namespace BlackLib
43 {
44 
48  enum digitalValue { low = 0,
49  high = 1
50  };
51 
52 
53 
54 
58  enum gpioName { GPIO_125=125, GPIO_123=123,
59  GPIO_122=122, GPIO_121=121,
60  GPIO_120=120, GPIO_117=117,
61  GPIO_49=49, GPIO_15=15,
62  GPIO_48=48, GPIO_51=51,
63  GPIO_20=20, GPIO_38=38,
64  GPIO_30=30, GPIO_60=60,
65  GPIO_31=31, GPIO_40=40,
66  GPIO_39=39, GPIO_34=34,
67  GPIO_35=35, GPIO_66=66,
68  GPIO_67=67, GPIO_69=69,
69  GPIO_68=68, GPIO_45=45,
70  GPIO_44=44, GPIO_23=23,
71  GPIO_26=26, GPIO_47=47,
72  GPIO_46=46, GPIO_27=27,
73  GPIO_65=65, GPIO_22=22,
74  GPIO_63=63, GPIO_62=62,
75  GPIO_37=37, GPIO_36=36,
76  GPIO_33=33, GPIO_32=32,
77  GPIO_61=61, GPIO_86=86,
78  GPIO_88=88, GPIO_87=87,
79  GPIO_89=89, GPIO_10=10,
80  GPIO_11=11, GPIO_81=81,
81  GPIO_80=80, GPIO_78=78,
82  GPIO_79=79, GPIO_76=76,
83  GPIO_77=77, GPIO_74=74,
84  GPIO_75=75, GPIO_72=72,
85  GPIO_73=73, GPIO_70=70,
86  GPIO_71=71, GPIO_14=14,
87  GPIO_9=9, GPIO_8=8,
88  GPIO_7=7, GPIO_5=5,
89  GPIO_4=4, GPIO_3=3,
91  };
92 
93 
97  enum workingMode { SecureMode = 0,
99  };
100 
101 
102 
103  // ######################################### BLACKCOREGPIO DECLARATION STARTS ######################################### //
104 
111  class BlackCoreGPIO : virtual private BlackCore
112  {
113  private:
117  std::string expPath;
118  std::string directionPath;
119  std::string unExpPath;
128  bool loadDeviceTree();
129 
135  bool doExport();
136 
142  bool setDirection();
143 
149  bool doUnexport();
150 
151  protected:
152 
157  std::string getDirectionFilePath();
158 
163  std::string getValueFilePath();
164 
170 
171  public:
172 
183  BlackCoreGPIO(gpioName pin, direction dir);
184 
185 
190  virtual ~BlackCoreGPIO();
191 
194  virtual std::string getValue() = 0;
195 
196  };
197  // ########################################## BLACKCOREGPIO DECLARATION ENDS ########################################## //
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208  // ########################################### BLACKGPIO DECLARATION STARTS ########################################### //
209 
305  class BlackGPIO : virtual private BlackCoreGPIO
306  {
307  private:
312  std::string valuePath;
320  bool isExported();
321 
328  bool isDirectionSet();
329 
338  bool isReady();
339 
340 
341  public:
342 
346  enum flags { exportFileErr = 0,
347  exportErr = 1,
350  readErr = 4,
351  writeErr = 5,
353  };
354 
385 
390  virtual ~BlackGPIO();
391 
413  std::string getValue();
414 
436  int getNumericValue();
437 
457  gpioName getName();
458 
483 
528  bool setValue(digitalValue v);
529 
560  bool isHigh();
561 
582  void toggleValue();
583 
600  void setWorkingMode(workingMode newWM);
601 
619 
620 
647  bool fail();
648 
729  bool fail(BlackGPIO::flags f);
730 
757  BlackGPIO& operator>>(std::string &readToThis);
758 
785  BlackGPIO& operator>>(int &readToThis);
786 
814  };
815  // ############################################ BLACKGPIO DECLARATION ENDS ############################################ //
816 
817 
818 } /* namespace BlackLib */
819 
820 #endif /* BLACKGPIO_H_ */
digitalValue
Definition: BlackGPIO.h:48
Definition: BlackGPIO.h:83
Definition: BlackGPIO.h:81
BlackGPIO & operator<<(digitalValue value)
Sets value of GPIO pin with "<<" operator.
Definition: BlackGPIO.cpp:496
std::string valuePath
is used to hold the value file path
Definition: BlackGPIO.h:312
workingMode
Definition: BlackGPIO.h:97
Definition: BlackGPIO.h:90
BlackGPIO(gpioName pn, direction pd, workingMode wm=SecureMode)
Constructor of BlackGPIO class.
Definition: BlackGPIO.cpp:169
Definition: BlackGPIO.h:65
Definition: BlackGPIO.h:77
Holds BlackGPIO errors.
Definition: BlackErr.h:528
Definition: BlackGPIO.h:73
Definition: BlackGPIO.h:62
Definition: BlackGPIO.h:86
Definition: BlackGPIO.h:48
flags
Definition: BlackGPIO.h:346
Definition: BlackGPIO.h:75
Definition: BlackGPIO.h:79
Definition: BlackGPIO.h:97
Definition: BlackGPIO.h:64
bool isDirectionSet()
Checks direction of GPIO pin.
Definition: BlackGPIO.cpp:207
Definition: BlackGPIO.h:67
Definition: BlackGPIO.h:350
workingMode workMode
is used to hold the selected working mode
Definition: BlackGPIO.h:311
Definition: BlackGPIO.h:64
Definition: BlackGPIO.h:68
bool isReady()
Checks ready state of GPIO pin.
Definition: BlackGPIO.cpp:184
Definition: BlackGPIO.h:80
Definition: BlackGPIO.h:77
Definition: BlackGPIO.h:80
Holds BlackCoreGPIO errors.
Definition: BlackErr.h:458
Definition: BlackGPIO.h:347
Definition: BlackGPIO.h:348
Definition: BlackGPIO.h:68
bool doExport()
Exports pin.
Definition: BlackGPIO.cpp:71
Definition: BlackGPIO.h:85
direction getDirection()
Exports direction of gpio pin.
Definition: BlackGPIO.cpp:306
Definition: BlackGPIO.h:66
Definition: BlackGPIO.h:74
bool setValue(digitalValue v)
Sets value of GPIO pin.
Definition: BlackGPIO.cpp:311
gpioName getName()
Exports name of gpio pin.
Definition: BlackGPIO.cpp:301
Definition: BlackGPIO.h:351
BlackGPIO & operator>>(std::string &readToThis)
Reads value of gpio pin as string type with ">>" operator.
Definition: BlackGPIO.cpp:426
Definition: BlackGPIO.h:58
bool isExported()
Checks the export state of GPIO pin.
Definition: BlackGPIO.cpp:189
Definition: BlackGPIO.h:88
Definition: BlackGPIO.h:84
Preparation phase of Beaglebone Black, to use GPIO.
Definition: BlackGPIO.h:111
Definition: BlackGPIO.h:67
Definition: BlackGPIO.h:75
Definition: BlackGPIO.h:72
void setWorkingMode(workingMode newWM)
Changes working mode.
Definition: BlackGPIO.cpp:388
workingMode getWorkingMode()
Exports working mode value.
Definition: BlackGPIO.cpp:393
Definition: BlackGPIO.h:61
Definition: BlackGPIO.h:58
std::string expPath
is used to hold the export file path
Definition: BlackGPIO.h:117
Definition: BlackGPIO.h:73
virtual ~BlackGPIO()
Destructor of BlackGPIO class.
Definition: BlackGPIO.cpp:178
Definition: BlackGPIO.h:70
errorGPIO * gpioErrors
is used to hold the errors of BlackGPIO class
Definition: BlackGPIO.h:308
Definition: BlackGPIO.h:69
Definition: BlackGPIO.h:74
Definition: BlackGPIO.h:65
Definition: BlackGPIO.h:76
Definition: BlackGPIO.h:83
Definition: BlackGPIO.h:71
BlackCoreGPIO(gpioName pin, direction dir)
Constructor of BlackCoreGPIO class.
Definition: BlackGPIO.cpp:42
Definition: BlackGPIO.h:82
errorCoreGPIO * getErrorsFromCoreGPIO()
Exports errorCoreGPIO struct to derived class.
Definition: BlackGPIO.cpp:152
Definition: BlackGPIO.h:81
direction pinDirection
is used to hold the selected GPIO pin direction
Definition: BlackGPIO.h:310
Definition: BlackGPIO.h:59
Definition: BlackGPIO.h:89
Definition: BlackGPIO.h:87
std::string unExpPath
is used to hold the unexport file path
Definition: BlackGPIO.h:119
Definition: BlackGPIO.h:61
Definition: BlackGPIO.h:346
Definition: BlackGPIO.h:59
Definition: BlackGPIO.h:78
std::string directionPath
is used to hold the direction file path
Definition: BlackGPIO.h:118
virtual ~BlackCoreGPIO()
Destructor of BlackCoreGPIO class.
Definition: BlackGPIO.cpp:58
Definition: BlackGPIO.h:79
std::string getValue()
Reads value of gpio pin as string type.
Definition: BlackGPIO.cpp:239
direction
Definition: BlackDef.h:44
Definition: BlackGPIO.h:60
gpioName pinName
is used to hold the selected GPIO pin name
Definition: BlackGPIO.h:309
std::string getValueFilePath()
Exports value file path to derived class.
Definition: BlackGPIO.cpp:146
Definition: BlackGPIO.h:60
Definition: BlackGPIO.h:78
Definition: BlackGPIO.h:85
Definition: BlackGPIO.h:87
virtual std::string getValue()=0
First declaration of this function.
Definition: BlackGPIO.h:88
int pinNumericType
is used to hold the selected pin direction
Definition: BlackGPIO.h:116
Definition: BlackGPIO.h:349
Definition: BlackGPIO.h:62
Definition: BlackGPIO.h:86
bool isHigh()
Checks value of GPIO pin.
Definition: BlackGPIO.cpp:362
Definition: BlackGPIO.h:69
bool loadDeviceTree()
Device tree loading is not necessary for using GPIO feature.
Definition: BlackGPIO.cpp:64
Definition: BlackGPIO.h:352
Definition: BlackGPIO.h:63
Definition: BlackGPIO.h:71
Definition: BlackGPIO.h:98
Definition: BlackGPIO.h:84
Definition: BlackGPIO.h:89
Definition: BlackGPIO.h:70
Definition: BlackGPIO.h:63
bool setDirection()
Sets pin direction.
Definition: BlackGPIO.cpp:92
Definition: BlackGPIO.h:66
Definition: BlackADC.cpp:36
bool fail()
Is used for general debugging.
Definition: BlackGPIO.cpp:400
bool doUnexport()
Unexports pin to release it.
Definition: BlackGPIO.cpp:120
std::string getDirectionFilePath()
Exports direction file path to derived class.
Definition: BlackGPIO.cpp:140
int pinNumericName
is used to hold the selected pin number
Definition: BlackGPIO.h:115
int getNumericValue()
Reads value of gpio pin as int type.
Definition: BlackGPIO.cpp:270
Definition: BlackGPIO.h:72
gpioName
Definition: BlackGPIO.h:58
Definition: BlackGPIO.h:49
Definition: BlackGPIO.h:76
errorCoreGPIO * gpioCoreError
is used to hold the errors of BlackCoreGPIO class
Definition: BlackGPIO.h:114
Interacts with end user, to use GPIO.
Definition: BlackGPIO.h:305
void toggleValue()
Toggles value of GPIO pin.
Definition: BlackGPIO.cpp:367
Definition: BlackGPIO.h:82
Base class of the other classes.
Definition: BlackCore.h:80