Demo program for StrCommandHandler calss library.
Dependencies: mbed SerialInputReactionHandler StrCommandHandler
Revision 1:c39728f6555e, committed 2020-10-21
- Comitter:
- aktk
- Date:
- Wed Oct 21 17:53:04 2020 +0000
- Parent:
- 0:4749705f54ab
- Commit message:
- Modified as it do just led blinking so as not to send char data.
Changed in this revision
diff -r 4749705f54ab -r c39728f6555e SerialInputReactionHandler.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialInputReactionHandler.lib Wed Oct 21 17:53:04 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/aktk/code/SerialInputReactionHandler/#4718a4eaf340
diff -r 4749705f54ab -r c39728f6555e StrCommandHandler.lib --- a/StrCommandHandler.lib Thu Oct 31 18:59:53 2019 +0000 +++ b/StrCommandHandler.lib Wed Oct 21 17:53:04 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/aktk/code/StrCommandHandler/#1d46d90eb7bf +https://os.mbed.com/users/aktk/code/StrCommandHandler/#a4873d38a32c
diff -r 4749705f54ab -r c39728f6555e main.cpp --- a/main.cpp Thu Oct 31 18:59:53 2019 +0000 +++ b/main.cpp Wed Oct 21 17:53:04 2020 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "StrCommandHandler.h" +#include "SerialInputReactionHandler.h" DigitalOut myled1(LED1); @@ -7,72 +8,56 @@ DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + Serial pc(USBTX, USBRX); // tx, rx StrCommandHandler cmdHandler(5); -int func1(void) + +void * func1(void) { myled1 = 1; myled2 = 0; myled3 = 0; - return 1; + return NULL; } -int func2(void) +void * func2(void) { myled1 = 0; myled2 = 1; myled3 = 0; - return 2; + return NULL; } -int func3(void) +void * func3(void) { myled1 = 0; myled2 = 0; myled3 = 1; - return 3; + return NULL; } int main() { - char command[16] ; - int itr = 0; - int rlt; - pc.baud(921600); - cmdHandler.map("func1", func1); cmdHandler.map("func2", func2); - cmdHandler.map("func3", func3); + cmdHandler.map(SerialInputReactionHandler::ARROW_UP, func3); + cmdHandler.list(); + + SerialInputReactionHandler *reactor = new SerialInputReactionHandler(); + //reactor->attach(callback(&cmdHandler, &StrCommandHandler::exe)); + //reactor.startReception(&pc, SerialInputReactionHandler::KB_TILL_ENTER); + - cmdHandler.list(); PRELOOP: pc.puts("\ncommand: "); - itr = 0; - while(1) { - command[itr] = pc.getc(); - if( - command[itr] == '\r' - || command[itr] == '\n' - ) { - command[itr] = '\0'; - pc.puts("\n"); - pc.puts("reveived: "); - pc.puts(command); - pc.puts("\t"); - rlt = cmdHandler.exe(command); - printf("result: %x\n", rlt); - break; - } else { - pc.putc(command[itr]); - } - if (itr == 15) - break; - itr++; + myled4 = !myled4; + wait(.5); } goto PRELOOP; } \ No newline at end of file