SMACC
Loading...
Searching...
No Matches
cb_default_keyboard_behavior.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <std_msgs/UInt16.h>
7
8namespace cl_keyboard
9{
11{
12public:
14 std::function<void(char)> postEventKeyPress;
15
16 void onEntry()
17 {
18 this->requiresClient(ClKeyboard_);
19 this->ClKeyboard_->OnKeyPress(&CbDefaultKeyboardBehavior::OnKeyPress, this);
20 }
21
22 template <typename TOrthogonal, typename TSourceObject>
24 {
25 postEventKeyPress = [=](char character) {
26 if (character == 'a')
27 postKeyEvent<EvKeyPressA<CbDefaultKeyboardBehavior, TOrthogonal>>();
28 else if (character == 'b')
29 postKeyEvent<EvKeyPressB<CbDefaultKeyboardBehavior, TOrthogonal>>();
30 else if (character == 'c')
31 postKeyEvent<EvKeyPressC<CbDefaultKeyboardBehavior, TOrthogonal>>();
32 else if (character == 'd')
33 postKeyEvent<EvKeyPressD<CbDefaultKeyboardBehavior, TOrthogonal>>();
34 else if (character == 'e')
35 postKeyEvent<EvKeyPressE<CbDefaultKeyboardBehavior, TOrthogonal>>();
36 else if (character == 'f')
37 postKeyEvent<EvKeyPressF<CbDefaultKeyboardBehavior, TOrthogonal>>();
38 else if (character == 'g')
39 postKeyEvent<EvKeyPressG<CbDefaultKeyboardBehavior, TOrthogonal>>();
40 else if (character == 'h')
41 postKeyEvent<EvKeyPressH<CbDefaultKeyboardBehavior, TOrthogonal>>();
42 else if (character == 'i')
43 postKeyEvent<EvKeyPressI<CbDefaultKeyboardBehavior, TOrthogonal>>();
44 else if (character == 'j')
45 postKeyEvent<EvKeyPressJ<CbDefaultKeyboardBehavior, TOrthogonal>>();
46 else if (character == 'k')
47 postKeyEvent<EvKeyPressK<CbDefaultKeyboardBehavior, TOrthogonal>>();
48 else if (character == 'l')
49 postKeyEvent<EvKeyPressL<CbDefaultKeyboardBehavior, TOrthogonal>>();
50 else if (character == 'm')
51 postKeyEvent<EvKeyPressM<CbDefaultKeyboardBehavior, TOrthogonal>>();
52 else if (character == 'n')
53 postKeyEvent<EvKeyPressN<CbDefaultKeyboardBehavior, TOrthogonal>>();
54 else if (character == 'o')
55 postKeyEvent<EvKeyPressO<CbDefaultKeyboardBehavior, TOrthogonal>>();
56 else if (character == 'p')
57 postKeyEvent<EvKeyPressP<CbDefaultKeyboardBehavior, TOrthogonal>>();
58 else if (character == 'q')
59 postKeyEvent<EvKeyPressQ<CbDefaultKeyboardBehavior, TOrthogonal>>();
60 else if (character == 'r')
61 postKeyEvent<EvKeyPressR<CbDefaultKeyboardBehavior, TOrthogonal>>();
62 else if (character == 's')
63 postKeyEvent<EvKeyPressS<CbDefaultKeyboardBehavior, TOrthogonal>>();
64 else if (character == 't')
65 postKeyEvent<EvKeyPressT<CbDefaultKeyboardBehavior, TOrthogonal>>();
66 else if (character == 'u')
67 postKeyEvent<EvKeyPressU<CbDefaultKeyboardBehavior, TOrthogonal>>();
68 else if (character == 'v')
69 postKeyEvent<EvKeyPressV<CbDefaultKeyboardBehavior, TOrthogonal>>();
70 else if (character == 'w')
71 postKeyEvent<EvKeyPressW<CbDefaultKeyboardBehavior, TOrthogonal>>();
72 else if (character == 'x')
73 postKeyEvent<EvKeyPressX<CbDefaultKeyboardBehavior, TOrthogonal>>();
74 else if (character == 'y')
75 postKeyEvent<EvKeyPressY<CbDefaultKeyboardBehavior, TOrthogonal>>();
76 else if (character == 'z')
77 postKeyEvent<EvKeyPressZ<CbDefaultKeyboardBehavior, TOrthogonal>>();
78 };
79 }
80
81 void OnKeyPress(char character)
82 {
83 postEventKeyPress(character);
84 }
85
86 template <typename TEv>
88 {
89 ROS_WARN("CbDefaultKeyboardBehavior %ld ev: %s", (long)(void *)this, smacc::demangleSymbol(typeid(TEv).name()).c_str());
90 auto event = new TEv();
91 this->postEvent(event);
92 }
93};
94} // namespace cl_keyboard
void OnKeyPress(void(T::*callback)(char keypress), T *object)
Definition: cl_keyboard.h:154
void requiresClient(SmaccClientType *&storage)
std::string demangleSymbol()
Definition: introspection.h:75