SMACC2
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{
25{
26public:
28 std::function<void(char)> postEventKeyPress;
29
30 void onEntry();
31
32 template <typename TOrthogonal, typename TSourceObject>
34 {
35 postEventKeyPress = [=](char character) {
36 if (character == 'a')
37 postKeyEvent<EvKeyPressA<CbDefaultKeyboardBehavior, TOrthogonal>>();
38 else if (character == 'b')
39 postKeyEvent<EvKeyPressB<CbDefaultKeyboardBehavior, TOrthogonal>>();
40 else if (character == 'c')
41 postKeyEvent<EvKeyPressC<CbDefaultKeyboardBehavior, TOrthogonal>>();
42 else if (character == 'd')
43 postKeyEvent<EvKeyPressD<CbDefaultKeyboardBehavior, TOrthogonal>>();
44 else if (character == 'e')
45 postKeyEvent<EvKeyPressE<CbDefaultKeyboardBehavior, TOrthogonal>>();
46 else if (character == 'f')
47 postKeyEvent<EvKeyPressF<CbDefaultKeyboardBehavior, TOrthogonal>>();
48 else if (character == 'g')
49 postKeyEvent<EvKeyPressG<CbDefaultKeyboardBehavior, TOrthogonal>>();
50 else if (character == 'h')
51 postKeyEvent<EvKeyPressH<CbDefaultKeyboardBehavior, TOrthogonal>>();
52 else if (character == 'y')
53 postKeyEvent<EvKeyPressI<CbDefaultKeyboardBehavior, TOrthogonal>>();
54 else if (character == 'j')
55 postKeyEvent<EvKeyPressJ<CbDefaultKeyboardBehavior, TOrthogonal>>();
56 else if (character == 'k')
57 postKeyEvent<EvKeyPressK<CbDefaultKeyboardBehavior, TOrthogonal>>();
58 else if (character == 'l')
59 postKeyEvent<EvKeyPressL<CbDefaultKeyboardBehavior, TOrthogonal>>();
60 else if (character == 'm')
61 postKeyEvent<EvKeyPressM<CbDefaultKeyboardBehavior, TOrthogonal>>();
62 else if (character == 'n')
63 postKeyEvent<EvKeyPressN<CbDefaultKeyboardBehavior, TOrthogonal>>();
64 else if (character == 'o')
65 postKeyEvent<EvKeyPressO<CbDefaultKeyboardBehavior, TOrthogonal>>();
66 else if (character == 'p')
67 postKeyEvent<EvKeyPressP<CbDefaultKeyboardBehavior, TOrthogonal>>();
68 else if (character == 'q')
69 postKeyEvent<EvKeyPressQ<CbDefaultKeyboardBehavior, TOrthogonal>>();
70 else if (character == 'r')
71 postKeyEvent<EvKeyPressR<CbDefaultKeyboardBehavior, TOrthogonal>>();
72 else if (character == 's')
73 postKeyEvent<EvKeyPressS<CbDefaultKeyboardBehavior, TOrthogonal>>();
74 else if (character == 't')
75 postKeyEvent<EvKeyPressT<CbDefaultKeyboardBehavior, TOrthogonal>>();
76 else if (character == 'u')
77 postKeyEvent<EvKeyPressU<CbDefaultKeyboardBehavior, TOrthogonal>>();
78 else if (character == 'v')
79 postKeyEvent<EvKeyPressV<CbDefaultKeyboardBehavior, TOrthogonal>>();
80 else if (character == 'w')
81 postKeyEvent<EvKeyPressW<CbDefaultKeyboardBehavior, TOrthogonal>>();
82 else if (character == 'x')
83 postKeyEvent<EvKeyPressX<CbDefaultKeyboardBehavior, TOrthogonal>>();
84 else if (character == 'y')
85 postKeyEvent<EvKeyPressY<CbDefaultKeyboardBehavior, TOrthogonal>>();
86 else if (character == 'z')
87 postKeyEvent<EvKeyPressZ<CbDefaultKeyboardBehavior, TOrthogonal>>();
88 };
89 }
90
91 void OnKeyPress(char character);
92
93 template <typename TEv>
95 {
96 RCLCPP_WARN(
97 getLogger(), "CbDefaultKeyboardBehavior %ld ev: %s", (long)(void *)this,
98 smacc2::demangleSymbol(typeid(TEv).name()).c_str());
99 auto event = new TEv();
100 this->postEvent(event);
101 }
102};
103} // namespace cl_keyboard
std::string demangleSymbol(const std::string &name)