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