
trabalho
Dependencies: X_NUCLEO_IKS01A1 mbed-rtos mbed
Fork of HelloWorld_IKS01A1 by
Revision 22:e36f91afc0aa, committed 2016-05-07
- Comitter:
- stwykd
- Date:
- Sat May 07 17:56:22 2016 +0000
- Parent:
- 21:6292c9ac498a
- Child:
- 23:61e09468bf3d
- Commit message:
- Create welcome message
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat May 07 17:38:39 2016 +0000 +++ b/main.cpp Sat May 07 17:56:22 2016 +0000 @@ -13,73 +13,79 @@ #include "x_nucleo_iks01a1.h" #include "mailBox.cpp" #include "expansionBoard.cpp" -//#include <iostream> #include <cstring> #include <ctime> #include <stdexcept> struct tm t; double T; +Serial p(USBTX, USBRX); int main() { char command[20]; char arg[10]; - scanf("%s", command); + + p.printf("Welcome! Those type one of the following commands"); + p.printf("\n\r READ ALL\n\r READ <n>\n\r DELETE ALL\n\r DELETE <n>"); + p.printf("\n\r SETDATE dd mm yyyy\n\r SETTIME hh mm ss"); + p.printf("\n\r SETT <T>\n\r STATE <x>\n\r LOGGING <x>"); + + p.scanf("%s", command); if (strcmp("READ", command)==0) { - scanf("%s", arg); + p.scanf("%s", arg); if(strcmp("ALL", arg)==0) //readAllSamples() - printf("You ended up in READ ALL"); + p.printf("You ended up in READ ALL"); else if (atoi(arg)!= 0) //readSample(atoi(arg)); - printf("You ended up in READ <n>"); - else printf("The argument is invalid"); + p.printf("You ended up in READ <n>"); + else p.printf("The argument is invalid"); } else if (strcmp("DELETE", command)==0) { - scanf("%s", arg); + p.scanf("%s", arg); if (strcmp("ALL", arg)==0) //deleteAllSamplesOrSomething() - printf("You ended up in READ ALL"); + p.printf("You ended up in READ ALL"); else if (atoi(arg)!= 0) //deleteSample(atoi(arg)); - printf("You ended up in DELETE <n>"); - else printf("The argument is invalid"); + p.printf("You ended up in DELETE <n>"); + else p.printf("The argument is invalid"); } else if (strcmp("SETDATE", command)==0) { char day[2], month[2], year[4]; //Read day - scanf("%s", day); + p.scanf("%s", day); if (atoi(day)!=0) t.tm_mday = atoi(day); // Read month - scanf("%s", month); + p.scanf("%s", month); if (atoi(month)!=0) t.tm_mon = atoi(month)-1; //Read year - scanf("%s", year); + p.scanf("%s", year); if (atoi(year)!=0) t.tm_year = atoi(year)-1900; // Check whether date is correct if (mktime(&t)>0) { - printf("DATE UPDATED TO %d %d %d", t.tm_mday, + p.printf("DATE UPDATED TO %d %d %d", t.tm_mday, t.tm_mon+1, t.tm_year+1900); set_time(mktime(&t)); } - else printf("Time inserted is invalid"); + else p.printf("Time inserted is invalid"); } else if (strcmp("SETTIME", command)==0) { char hour[2], min[2], sec[2]; - scanf("%s", hour); + p.scanf("%s", hour); if (atoi(hour)!=0) t.tm_hour = atoi(hour); - scanf("%s", min); + p.scanf("%s", min); if (atoi(min)!=0) t.tm_min = atoi(min); - scanf("%s", sec); + p.scanf("%s", sec); if (atoi(sec)!=0) t.tm_sec = atoi(sec); @@ -88,45 +94,44 @@ // Check whether time is correct if (mktime(&t)>0) { set_time(mktime(&t)); - printf("TIME UPDATED TO %d %d %d", t.tm_hour, + p.printf("TIME UPDATED TO %d %d %d", t.tm_hour, t.tm_min, t.tm_sec); } - else printf("Time inserted is invalid"); + else p.printf("Time inserted is invalid"); } else if (strcmp("SETT", command)==0) { - scanf("%s", arg); + p.scanf("%s", arg); if (atof(arg) >= 0.1 && atof(arg) <= 60.0 ) { T = atof(arg); - printf("T UPDATED TO %.1f", T); + p.printf("T UPDATED TO %.1f", T); } - //TODO Find a way to enable exceptions //else throw std::out_of_range ("T MUST BE WITHIN 0.1 AND 60.0"); } else if (strcmp("STATE", command)==0) { - scanf("%s", arg); + p.scanf("%s", arg); if (strcmp("ON", arg)==0) { //startSampling(); - printf("SAMPLING ON"); + p.printf("SAMPLING ON"); } else if (strcmp("OFF", arg)==0) { //stopSampling(); - printf("SAMPLIG OFF"); + p.printf("SAMPLIG OFF"); } - else printf("The argument is invalid"); + else p.printf("The argument is invalid"); } else if (strcmp("LOGGING", command)==0) { - scanf("%s", arg); + p.scanf("%s", arg); if (strcmp("ON", arg)==0) { //startLogging(); - printf("LOGGING ON"); + p.printf("LOGGING ON"); } else if (strcmp("OFF", arg)==0) { //stopLogging(); - printf("LOGGING OFF"); + p.printf("LOGGING OFF"); } - else printf("The argument is invalid"); + else p.printf("The argument is invalid"); } - else printf("There is no command matching. Please try again"); + else p.printf("There is no command matching. Please try again"); // Clear the input to avoid it to being reused in the next cycle command[0] = arg[0] = 0;