SMACC
Loading...
Searching...
No Matches
cl_keyboard.h
Go to the documentation of this file.
1#pragma once
2
3#include <smacc/smacc.h>
5
6#include <boost/asio/posix/stream_descriptor.hpp>
7#include <boost/asio.hpp>
8#include <iostream>
9#include <thread>
10
11#include <std_msgs/UInt16.h>
12
13namespace cl_keyboard
14{
15//----------------- TIMER sc::event DEFINITION ----------------------------------------------
16template <typename TSource, typename TOrthogonal>
17struct EvKeyPressA : sc::event<EvKeyPressA<TSource, TOrthogonal>>
18{
19};
20
21template <typename TSource, typename TOrthogonal>
22struct EvKeyPressB : sc::event<EvKeyPressB<TSource, TOrthogonal>>
23{
24};
25
26template <typename TSource, typename TOrthogonal>
27struct EvKeyPressC : sc::event<EvKeyPressC<TSource, TOrthogonal>>
28{
29};
30
31template <typename TSource, typename TOrthogonal>
32struct EvKeyPressD : sc::event<EvKeyPressD<TSource, TOrthogonal>>
33{
34};
35
36template <typename TSource, typename TOrthogonal>
37struct EvKeyPressE : sc::event<EvKeyPressE<TSource, TOrthogonal>>
38{
39};
40
41template <typename TSource, typename TOrthogonal>
42struct EvKeyPressF : sc::event<EvKeyPressF<TSource, TOrthogonal>>
43{
44};
45
46template <typename TSource, typename TOrthogonal>
47struct EvKeyPressG : sc::event<EvKeyPressG<TSource, TOrthogonal>>
48{
49};
50
51template <typename TSource, typename TOrthogonal>
52struct EvKeyPressH : sc::event<EvKeyPressH<TSource, TOrthogonal>>
53{
54};
55
56template <typename TSource, typename TOrthogonal>
57struct EvKeyPressI : sc::event<EvKeyPressI<TSource, TOrthogonal>>
58{
59};
60
61template <typename TSource, typename TOrthogonal>
62struct EvKeyPressJ : sc::event<EvKeyPressJ<TSource, TOrthogonal>>
63{
64};
65
66template <typename TSource, typename TOrthogonal>
67struct EvKeyPressK : sc::event<EvKeyPressK<TSource, TOrthogonal>>
68{
69};
70
71template <typename TSource, typename TOrthogonal>
72struct EvKeyPressL : sc::event<EvKeyPressL<TSource, TOrthogonal>>
73{
74};
75
76template <typename TSource, typename TOrthogonal>
77struct EvKeyPressM : sc::event<EvKeyPressM<TSource, TOrthogonal>>
78{
79};
80
81template <typename TSource, typename TOrthogonal>
82struct EvKeyPressN : sc::event<EvKeyPressN<TSource, TOrthogonal>>
83{
84};
85
86template <typename TSource, typename TOrthogonal>
87struct EvKeyPressO : sc::event<EvKeyPressO<TSource, TOrthogonal>>
88{
89};
90
91template <typename TSource, typename TOrthogonal>
92struct EvKeyPressP : sc::event<EvKeyPressP<TSource, TOrthogonal>>
93{
94};
95
96template <typename TSource, typename TOrthogonal>
97struct EvKeyPressQ : sc::event<EvKeyPressQ<TSource, TOrthogonal>>
98{
99};
100
101template <typename TSource, typename TOrthogonal>
102struct EvKeyPressR : sc::event<EvKeyPressR<TSource, TOrthogonal>>
103{
104};
105
106template <typename TSource, typename TOrthogonal>
107struct EvKeyPressS : sc::event<EvKeyPressS<TSource, TOrthogonal>>
108{
109};
110
111template <typename TSource, typename TOrthogonal>
112struct EvKeyPressT : sc::event<EvKeyPressT<TSource, TOrthogonal>>
113{
114};
115
116template <typename TSource, typename TOrthogonal>
117struct EvKeyPressU : sc::event<EvKeyPressU<TSource, TOrthogonal>>
118{
119};
120
121template <typename TSource, typename TOrthogonal>
122struct EvKeyPressV : sc::event<EvKeyPressV<TSource, TOrthogonal>>
123{
124};
125
126template <typename TSource, typename TOrthogonal>
127struct EvKeyPressW : sc::event<EvKeyPressW<TSource, TOrthogonal>>
128{
129};
130
131template <typename TSource, typename TOrthogonal>
132struct EvKeyPressX : sc::event<EvKeyPressX<TSource, TOrthogonal>>
133{
134};
135
136template <typename TSource, typename TOrthogonal>
137struct EvKeyPressY : sc::event<EvKeyPressY<TSource, TOrthogonal>>
138{
139};
140
141template <typename TSource, typename TOrthogonal>
142struct EvKeyPressZ : sc::event<EvKeyPressZ<TSource, TOrthogonal>>
143{
144};
145
146//------------------ KEYBOARD CLIENT ---------------------------------------------
147
149{
150public:
151 smacc::SmaccSignal<void(char keypress)> OnKeyPress_;
152
153 template <typename T>
154 void OnKeyPress(void (T::*callback)(char keypress), T *object)
155 {
156 //this->connectSignal(OnKeyPress_, callback, object);
157 this->getStateMachine()->createSignalConnection(OnKeyPress_, callback, object);
158 }
159
160 ClKeyboard();
161
162 virtual ~ClKeyboard();
163
164 virtual void initialize() override;
165
166 std::function<void(std_msgs::UInt16)> postEventKeyPress;
167
168 template <typename TOrthogonal, typename TSourceObject>
170 {
171 // call to the base configuration to properly handling the message and initial message smacc events
173
174 postEventKeyPress = [=](auto unicode_keychar) {
175 char character = (char)unicode_keychar.data;
176 ROS_WARN("detected keyboard: %c", character);
177
178 if (character == 'a')
179 this->postKeyEvent<EvKeyPressA<ClKeyboard, TOrthogonal>>();
180 else if (character == 'b')
181 this->postKeyEvent<EvKeyPressB<ClKeyboard, TOrthogonal>>();
182 else if (character == 'c')
183 this->postKeyEvent<EvKeyPressC<ClKeyboard, TOrthogonal>>();
184 else if (character == 'd')
185 this->postKeyEvent<EvKeyPressD<ClKeyboard, TOrthogonal>>();
186 else if (character == 'e')
187 this->postKeyEvent<EvKeyPressE<ClKeyboard, TOrthogonal>>();
188 else if (character == 'f')
189 this->postKeyEvent<EvKeyPressF<ClKeyboard, TOrthogonal>>();
190 else if (character == 'g')
191 this->postKeyEvent<EvKeyPressG<ClKeyboard, TOrthogonal>>();
192 else if (character == 'h')
193 this->postKeyEvent<EvKeyPressH<ClKeyboard, TOrthogonal>>();
194 else if (character == 'y')
195 this->postKeyEvent<EvKeyPressI<ClKeyboard, TOrthogonal>>();
196 else if (character == 'j')
197 this->postKeyEvent<EvKeyPressJ<ClKeyboard, TOrthogonal>>();
198 else if (character == 'k')
199 this->postKeyEvent<EvKeyPressK<ClKeyboard, TOrthogonal>>();
200 else if (character == 'l')
201 this->postKeyEvent<EvKeyPressL<ClKeyboard, TOrthogonal>>();
202 else if (character == 'm')
203 this->postKeyEvent<EvKeyPressM<ClKeyboard, TOrthogonal>>();
204 else if (character == 'n')
205 this->postKeyEvent<EvKeyPressN<ClKeyboard, TOrthogonal>>();
206 else if (character == 'o')
207 this->postKeyEvent<EvKeyPressO<ClKeyboard, TOrthogonal>>();
208 else if (character == 'p')
209 this->postKeyEvent<EvKeyPressP<ClKeyboard, TOrthogonal>>();
210 else if (character == 'q')
211 this->postKeyEvent<EvKeyPressQ<ClKeyboard, TOrthogonal>>();
212 else if (character == 'r')
213 this->postKeyEvent<EvKeyPressR<ClKeyboard, TOrthogonal>>();
214 else if (character == 's')
215 this->postKeyEvent<EvKeyPressS<ClKeyboard, TOrthogonal>>();
216 else if (character == 't')
217 this->postKeyEvent<EvKeyPressT<ClKeyboard, TOrthogonal>>();
218 else if (character == 'u')
219 this->postKeyEvent<EvKeyPressU<ClKeyboard, TOrthogonal>>();
220 else if (character == 'v')
221 this->postKeyEvent<EvKeyPressV<ClKeyboard, TOrthogonal>>();
222 else if (character == 'w')
223 this->postKeyEvent<EvKeyPressW<ClKeyboard, TOrthogonal>>();
224 else if (character == 'x')
225 this->postKeyEvent<EvKeyPressX<ClKeyboard, TOrthogonal>>();
226 else if (character == 'y')
227 this->postKeyEvent<EvKeyPressY<ClKeyboard, TOrthogonal>>();
228 else if (character == 'z')
229 this->postKeyEvent<EvKeyPressZ<ClKeyboard, TOrthogonal>>();
230 OnKeyPress_(character); /* */
231 };
232 }
233
234 void onKeyboardMessage(const std_msgs::UInt16 &unicode_keychar);
235
236 template <typename TEv>
238 {
239 ROS_WARN("ClKeyboard ev: %s", smacc::demangleSymbol(typeid(TEv).name()).c_str());
240 this->postEvent<TEv>();
241 }
242
243private:
245};
246} // namespace cl_keyboard
smacc::SmaccSignal< void(char keypress)> OnKeyPress_
Definition: cl_keyboard.h:151
std::function< void(std_msgs::UInt16)> postEventKeyPress
Definition: cl_keyboard.h:166
void OnKeyPress(void(T::*callback)(char keypress), T *object)
Definition: cl_keyboard.h:154
virtual void initialize() override
Definition: cl_keyboard.cpp:14
void onKeyboardMessage(const std_msgs::UInt16 &unicode_keychar)
Definition: cl_keyboard.cpp:24
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
std::string demangleSymbol()
Definition: introspection.h:75