listen serial input and react by callback registered.
Dependents: Interference_Simple StrCommandHandler_Demo SerialInputReactionHandler_DEMO
Diff: SerialInputReactionHandler.cpp
- Revision:
- 2:4718a4eaf340
- Parent:
- 1:fd211f137803
- Child:
- 3:599073f82114
diff -r fd211f137803 -r 4718a4eaf340 SerialInputReactionHandler.cpp --- a/SerialInputReactionHandler.cpp Tue Nov 12 02:41:58 2019 +0000 +++ b/SerialInputReactionHandler.cpp Thu Nov 14 01:52:06 2019 +0000 @@ -1,26 +1,49 @@ #include "SerialInputReactionHandler.h" +//void SerialInputReactionHandler::doNothing(char const * const){} +//void SerialInputReactionHandler::doNothing(void *){} +//template <typename T> +//void SerialInputReactionHandler::doNothing(T arg) {} + char const * const SerialInputReactionHandler::ARROW_UP = "\x1b\x5b\x41"; char const * const SerialInputReactionHandler::ARROW_DOWN = "\x1b\x5b\x42"; char const * const SerialInputReactionHandler::ARROW_RIGHT= "\x1b\x5b\x43"; char const * const SerialInputReactionHandler::ARROW_LEFT = "\x1b\x5b\x44"; SerialInputReactionHandler::SerialInputReactionHandler( - Callback<int(char const * const)> arg_callback_onCommand + Callback<void *(char const * const)> arg_callback_onCommand, + Callback<void (char const * const)> arg_commonPre_callback_onCommand, + Callback<void (void *)> arg_commonPost_callback_onCommand ) { funcIfInput[KB_SINGLE_INPUT] = &SerialInputReactionHandler::listenKBSingleInput; funcIfInput[KB_TILL_ENTER] = &SerialInputReactionHandler::listenKBTillEnter; callback_onCommand = arg_callback_onCommand; + commonPre_callback_onCommand = arg_commonPre_callback_onCommand; + commonPost_callback_onCommand = arg_commonPost_callback_onCommand; } void SerialInputReactionHandler::attach( - Callback<int (char const * const)> arg_callback_onCommand + Callback<void * (char const * const)> arg_callback_onCommand ) { callback_onCommand = arg_callback_onCommand; } +void SerialInputReactionHandler::attach_PreProc( + Callback<void (char const * const)> arg_commonPre_callback_onCommand +) +{ + commonPre_callback_onCommand = arg_commonPre_callback_onCommand; +} + +void SerialInputReactionHandler::attach_PostProc( + Callback<void (void *)> arg_commonPost_callback_onCommand +) +{ + commonPost_callback_onCommand = arg_commonPost_callback_onCommand; +} + void SerialInputReactionHandler::startReception( Serial * arg_serial_socket, InputMode arg_mode @@ -36,13 +59,8 @@ m_serial_socket->attach(NULL); } -void SerialInputReactionHandler::commonProcedure() -{ -} - void SerialInputReactionHandler::sig_bind() { - commonProcedure(); (this->*funcIfInput[m_input_mode])(); } @@ -62,23 +80,6 @@ discardBuffer(); } -bool isUpperCase (const char arg_c) -{ - return ('A' <= arg_c && arg_c <= 'Z'); -} - -bool isLowerCase (const char arg_c) -{ - return ('a' <= arg_c && arg_c <= 'z'); -} - -bool isSymbol (const char arg_c) -{ - return ((0x20 <= arg_c && arg_c <= 0x40) - || (0x5B <= arg_c && arg_c <= 0x60) - || (0x7B <= arg_c && arg_c <= 0x7E)); -} - bool SerialInputReactionHandler::isArrowSymbol() { // If only 0x1B, ESC KEY should be Pressed, else some symbol sequence.