![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: main.cpp
- Revision:
- 43:3983059e0d91
- Parent:
- 42:b1f29874ab70
- Child:
- 44:b523c9a9dd97
--- a/main.cpp Wed Apr 05 16:12:42 2017 +0000 +++ b/main.cpp Thu Apr 06 10:48:12 2017 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "rtos.h" -#include "string.h" +#include <string.h> #include <stdio.h> #include <ctype.h> #include "hts221.h" @@ -102,8 +102,8 @@ } int CompareCommands(char command[],char targetcommand[], int size) { - int ret = -1, i = 0; - for(i = 0; i< size; i ++) + int i; + for(i = 0; i < size; i ++) { if(command[i] != targetcommand[i]) return -1; @@ -124,19 +124,39 @@ charCmd = getchar(); if(charCmd != NULL) { - if(charCmd != 13) + if (charCmd == 127 && crtChar > 0 ) + { + printf("%c",charCmd); + command[--crtChar] = '\0'; + } + else if(charCmd != 13 && charCmd != 127) { command[crtChar++] = charCmd; printf("%c",charCmd); } - else + else if(charCmd == 13) { printf("\r\n\r\nCommand entered: %s\r\n", command); - if(CompareCommands(command,"list all",crtChar) == 1) + // this thing that follows splits a string into multiple strings, just like String.Split(char[] delimiters) + // here we will check for commands and parameters :) + char *charPos; + charPos = strtok(command," -,"); + if(CompareCommands(charPos, "list",4) == 1) { - listBuffer->ListAll(); + charPos = strtok(NULL," -,"); + if(CompareCommands(charPos, "all",3) == 1) + { + listBuffer->ListAll(); + } + else if(strtol(charPos,NULL,10) != 0) + { + listBuffer->ListX(atoi(charPos)); + } } + // printf("%s \r\n", charPos); + // charPos = strtok(NULL," -,"); + printf("Awaiting command: \r\n"); int i = 0;