libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Gpio.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef GPIO_H_
32 #define GPIO_H_
33 
34 #include <map>
35 #include <mutex>
36 #include <memory>
37 #include <vector>
38 
39 namespace BaseLib
40 {
41 
42 class SharedObjects;
43 class FileDescriptor;
44 
45 namespace LowLevel
46 {
47 
48 class Gpio
49 {
50 public:
52  {
53  enum Enum
54  {
55  IN,
57  };
58  };
59 
60  struct GpioEdge
61  {
62  enum Enum
63  {
66  BOTH
67  };
68  };
69 
70  Gpio(BaseLib::SharedObjects* baseLib, std::string gpioPath);
71  virtual ~Gpio();
72 
73  virtual void openDevice(uint32_t index, bool readOnly);
74  virtual void getPath(uint32_t index);
75  virtual void closeDevice(uint32_t index);
76  virtual bool get(uint32_t index);
77 
86  virtual int32_t poll(uint32_t index, int32_t timeout, bool debounce);
87 
88  virtual void set(uint32_t index, bool value);
89  virtual void setPermission(uint32_t index, int32_t userID, int32_t groupID, bool readOnly);
90  virtual void exportGpio(uint32_t index);
91  virtual void setDirection(uint32_t index, GpioDirection::Enum direction);
92  virtual void setEdge(uint32_t index, GpioEdge::Enum edge);
93  virtual bool isOpen(uint32_t index);
94  virtual void setup(int32_t userId, int32_t groupId, bool setPermissions, std::vector<uint32_t>& exportGpios);
95  virtual std::shared_ptr<FileDescriptor> getFileDescriptor(uint32_t index);
96 protected:
97  class GpioInfo
98  {
99  public:
100  std::string path;
101  std::shared_ptr<FileDescriptor> fileDescriptor;
102  };
103 
105  std::string _gpioPath;
106  std::mutex _gpioMutex;
107  std::map<uint32_t, GpioInfo> _gpioInfo;
108 };
109 
110 }
111 }
112 #endif
virtual void getPath(uint32_t index)
Definition: Gpio.cpp:85
Definition: Gpio.h:48
virtual std::shared_ptr< FileDescriptor > getFileDescriptor(uint32_t index)
Definition: Gpio.cpp:393
This is the base library main class.
Definition: BaseLib.h:95
virtual void exportGpio(uint32_t index)
Definition: Gpio.cpp:333
Definition: BaseLib.cpp:34
std::string _gpioPath
Definition: Gpio.h:105
std::shared_ptr< FileDescriptor > fileDescriptor
Definition: Gpio.h:101
std::mutex _gpioMutex
Definition: Gpio.h:106
virtual bool isOpen(uint32_t index)
Definition: Gpio.cpp:315
virtual void setPermission(uint32_t index, int32_t userID, int32_t groupID, bool readOnly)
Definition: Gpio.cpp:261
PVariable value
Definition: UiElements.h:217
virtual void closeDevice(uint32_t index)
Definition: Gpio.cpp:146
virtual void setEdge(uint32_t index, GpioEdge::Enum edge)
Definition: Gpio.cpp:438
std::string path
Definition: Gpio.h:100
virtual int32_t poll(uint32_t index, int32_t timeout, bool debounce)
Waits for a GPIO input to change and returns the input value.
Definition: Gpio.cpp:188
virtual void openDevice(uint32_t index, bool readOnly)
Definition: Gpio.cpp:58
virtual void setDirection(uint32_t index, GpioDirection::Enum direction)
Definition: Gpio.cpp:411
BaseLib::SharedObjects * _bl
Definition: Gpio.h:104
std::map< uint32_t, GpioInfo > _gpioInfo
Definition: Gpio.h:107
virtual ~Gpio()
Definition: Gpio.cpp:48
Gpio(BaseLib::SharedObjects *baseLib, std::string gpioPath)
Definition: Gpio.cpp:42
virtual void setup(int32_t userId, int32_t groupId, bool setPermissions, std::vector< uint32_t > &exportGpios)
Definition: Gpio.cpp:377