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 std::function<void(ArrowKey)> postEventArrowPress;
30
31 void onEntry()
32 {
33 this->requiresComponent(this->cpSubscriber1);
34 this->cpSubscriber1->OnKeyPress(&CbDefaultKeyboardBehavior::OnKeyPress, this);
35 this->cpSubscriber1->OnArrowPress(&CbDefaultKeyboardBehavior::OnArrowPress, 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 postEventArrowPress = [=](ArrowKey arrow)
98 {
99 switch (arrow)
100 {
101 case ArrowKey::Up:
103 break;
104 case ArrowKey::Down:
106 break;
107 case ArrowKey::Left:
109 break;
110 case ArrowKey::Right:
112 break;
113 }
114 };
115 }
116
117 void OnKeyPress(char character) { postEventKeyPress(character); }
118
120
121 template <typename TEv>
123 {
124 RCLCPP_WARN(
125 getLogger(), "CbDefaultKeyboardBehavior %ld ev: %s", (long)(void *)this,
126 smacc2::demangleSymbol(typeid(TEv).name()).c_str());
127 auto event = new TEv();
128 this->postEvent(event);
129 }
130};
131} // namespace cl_keyboard
void OnArrowPress(void(T::*callback)(ArrowKey arrow), T *object)
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()