SMACC2
Loading...
Searching...
No Matches
cb_default_keyboard_behavior.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
19
20#include <std_msgs/msg/u_int16.hpp>
21
22namespace cl_keyboard
23{
24using namespace cl_keyboard::components;
25
27{
28public:
30 std::function<void(char)> postEventKeyPress;
31
32 void onEntry()
33 {
34 this->requiresComponent(this->cpSubscriber1);
35 this->cpSubscriber1->OnKeyPress(&CbDefaultKeyboardBehavior::OnKeyPress, this);
36 }
37
38 template <typename TOrthogonal, typename TSourceObject>
40 {
41 postEventKeyPress = [=](char character)
42 {
43 if (character == 'a')
45 else if (character == 'b')
47 else if (character == 'c')
49 else if (character == 'd')
51 else if (character == 'e')
53 else if (character == 'f')
55 else if (character == 'g')
57 else if (character == 'h')
59 else if (character == 'i')
61 else if (character == 'j')
63 else if (character == 'k')
65 else if (character == 'l')
67 else if (character == 'm')
69 else if (character == 'n')
71 else if (character == 'o')
73 else if (character == 'p')
75 else if (character == 'q')
77 else if (character == 'r')
79 else if (character == 's')
81 else if (character == 't')
83 else if (character == 'u')
85 else if (character == 'v')
87 else if (character == 'w')
89 else if (character == 'x')
91 else if (character == 'y')
93 else if (character == 'z')
95 };
96 }
97
98 void OnKeyPress(char character) { postEventKeyPress(character); }
99
100 template <typename TEv>
102 {
103 RCLCPP_WARN(
104 getLogger(), "CbDefaultKeyboardBehavior %ld ev: %s", (long)(void *)this,
105 smacc2::demangleSymbol(typeid(TEv).name()).c_str());
106 auto event = new TEv();
107 this->postEvent(event);
108 }
109};
110} // namespace cl_keyboard
void OnKeyPress(void(T::*callback)(char keypress), T *object)
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
std::string demangleSymbol()