gpio_interface.h
Go to the documentation of this file.
1 //
2 // Created by yezi on 2021/9/22.
3 //
4 
5 #pragma once
6 
7 #include <hardware_interface/internal/hardware_resource_manager.h>
8 
9 namespace rm_control
10 {
12 {
15 };
16 
17 struct GpioData
18 {
19  std::string name;
21  int pin;
22  bool* value;
23 };
24 
26 {
27 public:
28  GpioStateHandle() = default;
29  GpioStateHandle(std::string name, GpioType type, bool* value) : name_(std::move(name)), type_(type), value_(value)
30  {
31  if (!value)
32  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
33  "'. value pointer is null.");
34  }
35  std::string getName() const
36  {
37  return name_;
38  }
39  GpioType getType() const
40  {
41  return type_;
42  }
43  bool getValue() const
44  {
45  assert(value_);
46  return *value_;
47  }
48 
49 private:
50  std::string name_;
52  bool* value_ = { nullptr };
53 };
54 
56 {
57 public:
58  GpioCommandHandle() = default;
59  GpioCommandHandle(std::string name, GpioType type, bool* cmd) : name_(std::move(name)), type_(type), cmd_(cmd)
60  {
61  if (!cmd)
62  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
63  "'. command pointer is null.");
64  }
65  std::string getName() const
66  {
67  return name_;
68  }
69  bool getCommand() const
70  {
71  assert(cmd_);
72  return *cmd_;
73  }
74 
75  void setCommand(bool value)
76  {
77  assert(cmd_);
78  *cmd_ = value;
79  }
80 
81 private:
82  std::string name_;
84  bool* cmd_ = { nullptr };
85 };
86 
88  : public hardware_interface::HardwareResourceManager<GpioStateHandle, hardware_interface::DontClaimResources>
89 {
90 };
91 
93  : public hardware_interface::HardwareResourceManager<GpioCommandHandle, hardware_interface::ClaimResources>
94 {
95 };
96 
97 } // namespace rm_control
rm_control::GpioData::value
bool * value
Definition: gpio_interface.h:22
rm_control::GpioStateHandle::value_
bool * value_
Definition: gpio_interface.h:52
rm_control::OUTPUT
@ OUTPUT
Definition: gpio_interface.h:14
rm_control::GpioCommandHandle::getCommand
bool getCommand() const
Definition: gpio_interface.h:69
rm_control::GpioCommandHandle::getName
std::string getName() const
Definition: gpio_interface.h:65
rm_control::GpioStateHandle::getType
GpioType getType() const
Definition: gpio_interface.h:39
rm_control::GpioStateHandle::name_
std::string name_
Definition: gpio_interface.h:50
rm_control::INPUT
@ INPUT
Definition: gpio_interface.h:13
rm_control::GpioData::pin
int pin
Definition: gpio_interface.h:21
rm_control::GpioData::name
std::string name
Definition: gpio_interface.h:19
rm_control::GpioStateInterface
Definition: gpio_interface.h:87
rm_control::GpioCommandHandle::name_
std::string name_
Definition: gpio_interface.h:82
rm_control::GpioCommandInterface
Definition: gpio_interface.h:92
rm_control::GpioStateHandle::type_
GpioType type_
Definition: gpio_interface.h:51
rm_control::GpioCommandHandle::setCommand
void setCommand(bool value)
Definition: gpio_interface.h:75
rm_control
Definition: actuator_extra_interface.h:43
rm_control::GpioData
Definition: gpio_interface.h:17
rm_control::GpioStateHandle::GpioStateHandle
GpioStateHandle()=default
rm_control::GpioStateHandle::getName
std::string getName() const
Definition: gpio_interface.h:35
rm_control::GpioCommandHandle
Definition: gpio_interface.h:55
std
rm_control::GpioCommandHandle::GpioCommandHandle
GpioCommandHandle()=default
rm_control::GpioStateHandle
Definition: gpio_interface.h:25
rm_control::GpioCommandHandle::type_
GpioType type_
Definition: gpio_interface.h:83
cmd
string cmd
rm_control::GpioStateHandle::getValue
bool getValue() const
Definition: gpio_interface.h:43
rm_control::GpioType
GpioType
Definition: gpio_interface.h:11
rm_control::GpioStateHandle::GpioStateHandle
GpioStateHandle(std::string name, GpioType type, bool *value)
Definition: gpio_interface.h:29
rm_control::GpioData::type
GpioType type
Definition: gpio_interface.h:20
rm_control::GpioCommandHandle::cmd_
bool * cmd_
Definition: gpio_interface.h:84
rm_control::GpioCommandHandle::GpioCommandHandle
GpioCommandHandle(std::string name, GpioType type, bool *cmd)
Definition: gpio_interface.h:59


rm_common
Author(s):
autogenerated on Sun Apr 6 2025 02:22:01