Motorcortex Core  version: 2.7.6
wd_gpiolines.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2018 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_WD_GPIOLINES_H
7 #define MOTORCORTEX_CORE_WD_GPIOLINES_H
8 
9 #include <vector>
10 #include <initializer_list>
11 #include <linux/gpio.h>
12 
13 namespace mcx {
14 
15 namespace watchdog {
16 
17 enum GpioLineDir {
18  INPUT = GPIOHANDLE_REQUEST_INPUT,
19  OUTPUT = GPIOHANDLE_REQUEST_OUTPUT
20 };
21 
22 class GpioLines {
23 public:
24 
25  GpioLines();
26 
27  GpioLines(std::initializer_list<unsigned int> line_offset_list);
28 
29  ~GpioLines();
30 
31  bool open(const char* device, GpioLineDir dir);
32 
33  bool update();
34 
35  void add(unsigned int line_offset);
36 
37  void add(std::initializer_list<unsigned int> line_offset_list);
38 
39  bool set(unsigned int line_offset, bool value);
40 
41  bool set(std::initializer_list<unsigned int> line_offset_list, bool value);
42 
43  bool get(unsigned int line_offset) const;
44 
45  unsigned int length() const;
46 
47  const unsigned int* lines() const;
48 
49  const gpiohandle_data* data() const;
50 
51 private:
52 
53  std::vector<unsigned int> mapping_;
54  std::vector<unsigned int> lines_;
55  gpiohandle_data data_{};
56  GpioLineDir dir_{GpioLineDir::INPUT};
57  int fd_{};
58 };
59 
60 } // namespace watchdog
61 
62 } // namespace mcx
63 
64 #endif //MOTORCORTEX_CORE_WD_GPIOLINES_H
mcx::watchdog::GpioLines
Definition: wd_gpiolines.h:22