SMACC2
Loading...
Searching...
No Matches
cb_default_keyboard_behavior.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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{
25{
26public:
28 std::function<void(char)> postEventKeyPress;
29
30 void onEntry()
31 {
32 this->requiresComponent(this->cpSubscriber1);
33 this->cpSubscriber1->OnKeyPress(&CbDefaultKeyboardBehavior::OnKeyPress, this);
34 }
35
36 template <typename TOrthogonal, typename TSourceObject>
38 {
39 postEventKeyPress = [=](char character)
40 {
41 if (character == 'a')
43 else if (character == 'b')
45 else if (character == 'c')
47 else if (character == 'd')
49 else if (character == 'e')
51 else if (character == 'f')
53 else if (character == 'g')
55 else if (character == 'h')
57 else if (character == 'i')
59 else if (character == 'j')
61 else if (character == 'k')
63 else if (character == 'l')
65 else if (character == 'm')
67 else if (character == 'n')
69 else if (character == 'o')
71 else if (character == 'p')
73 else if (character == 'q')
75 else if (character == 'r')
77 else if (character == 's')
79 else if (character == 't')
81 else if (character == 'u')
83 else if (character == 'v')
85 else if (character == 'w')
87 else if (character == 'x')
89 else if (character == 'y')
91 else if (character == 'z')
93 };
94 }
95
96 void OnKeyPress(char character) { postEventKeyPress(character); }
97
98 template <typename TEv>
100 {
101 RCLCPP_WARN(
102 getLogger(), "CbDefaultKeyboardBehavior %ld ev: %s", (long)(void *)this,
103 smacc2::demangleSymbol(typeid(TEv).name()).c_str());
104 auto event = new TEv();
105 this->postEvent(event);
106 }
107};
108} // 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()