rm_control
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
9namespace rm_control
10{
16
18{
19 std::string name;
21 int pin;
22 bool* value;
23};
24
26{
27public:
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 }
40 {
41 return type_;
42 }
43 bool getValue() const
44 {
45 assert(value_);
46 return *value_;
47 }
48
49private:
50 std::string name_;
51 GpioType type_;
52 bool* value_ = { nullptr };
53};
54
56{
57public:
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
81private:
82 std::string name_;
83 GpioType type_;
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
Definition gpio_interface.h:56
bool getCommand() const
Definition gpio_interface.h:69
GpioCommandHandle(std::string name, GpioType type, bool *cmd)
Definition gpio_interface.h:59
std::string getName() const
Definition gpio_interface.h:65
void setCommand(bool value)
Definition gpio_interface.h:75
Definition gpio_interface.h:94
Definition gpio_interface.h:26
std::string getName() const
Definition gpio_interface.h:35
GpioStateHandle(std::string name, GpioType type, bool *value)
Definition gpio_interface.h:29
bool getValue() const
Definition gpio_interface.h:43
GpioType getType() const
Definition gpio_interface.h:39
Definition gpio_interface.h:89
Definition actuator_extra_interface.h:44
GpioType
Definition gpio_interface.h:12
@ OUTPUT
Definition gpio_interface.h:14
@ INPUT
Definition gpio_interface.h:13
Definition gpio_interface.h:18
bool * value
Definition gpio_interface.h:22
GpioType type
Definition gpio_interface.h:20
int pin
Definition gpio_interface.h:21
std::string name
Definition gpio_interface.h:19