trabalho final
Dependencies: X_NUCLEO_IKS01A1-f255a2c75ecb mbed-rtos mbed
main.cpp
- Committer:
- Jacinta
- Date:
- 2016-05-13
- Revision:
- 0:1eaebb55408a
- Child:
- 2:0b8065489409
File content as of revision 0:1eaebb55408a:
/** ****************************************************************************** * @file main.cpp * @author ANG Group (Nelson Santos; Irina Baptista; Pierluigi Urru) * @version V0.0.1 * @date 05-May-2016 * @brief Simple Example application for using the X_NUCLEO_IKS01A1 * MEMS Inertial & Environmental Sensor Nucleo expansion board. ****************************************************************************** */ #include "mbed.h" #include "x_nucleo_iks01a1.h" #include <cstring> #include <ctime> #include <stdexcept> #include "sensor.h" #include "userMethods.h" Serial pc(USBTX, USBRX); ExpansionBoard e; UserMethods u; struct tm dt; char command[20]; char arg[10]; void sensorReadings(void const *args){ e.readData(); wait(e.T); } void userInteraction(void const *args) { pc.printf("\n\rWelcome! Type one of the following commands"); pc.printf("\n\r READ ALL\n\r READ <n>\n\r DELETE ALL\n\r DELETE <n>"); pc.printf("\n\r SETDATE dd mm yyyy\n\r SETTIME hh mm ss"); pc.printf("\n\r SETT <T>\n\r STATE <x>\n\r LOGGING <x>"); scanf("%s", command); if (strcmp("READ", command)==0) { scanf("%s", arg); if(strcmp("ALL", arg)==0) //readAllSamples() 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"); } else if (strcmp("DELETE", command)==0) { scanf("%s", arg); if (strcmp("ALL", arg)==0) //deleteAllSamplesOrSomething() 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"); } else if (strcmp("SETDATE", command)==0) { bool isUpdate; isUpdate = u.setDate(); printf("Date Updated: %s\n", isUpdate?"true":"false"); } else if (strcmp("SETTIME", command)==0) { bool isUpdate; isUpdate = u.setTime(); printf("Time Updated: %s\n", isUpdate?"true":"false"); } else if (strcmp("SETT", command)==0) { scanf("%s", arg); if (atof(arg) >= 0.1 && atof(arg) <= 60.0 ) { e.T = atof(arg); printf("T UPDATED TO %.1f", e.T); } //else throw std::out_of_range ("T MUST BE WITHIN 0.1 AND 60.0"); } else if (strcmp("STATE", command)==0) { scanf("%s", arg); if (strcmp("ON", arg)==0) //TODO For now it just reads data and prints it out, FIFO needed e.startSampling(); else if (strcmp("OFF", arg)==0) e.stopSampling(); else printf("The argument is invalid"); } else if(strcmp("LOGGING", command)==0) { scanf("%s", arg); if (strcmp("ON", arg)==0) { //startLogging(); printf("LOGGING ON"); } else if (strcmp("OFF", arg)==0) { //stopLogging(); printf("LOGGING OFF"); } else printf("The argument is invalid"); } else 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; } void getData(const void*) { while(true) { //Block on queuefor at most 5s if no data is available osEvent event = e.mail_box.get(5000); if(event.status == osEventTimeout) { printf("mail_box.get %02x, Timeout error", event.status); return; } else if (event.status == osEventMail) { // Successful, store log_data //TODO Store it somewhere Log *log_d = (Log*)event.value.p; e.mail_box.free(log_d); } } } int main() { pc.baud(9600); Thread userInteraction(); Thread sensorReadings(); return 0; }