![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MAIN
Fork of SOFT253_Template_Weather_OS_54 by
prompt.cpp
- Committer:
- J_Satchell
- Date:
- 2017-05-15
- Revision:
- 36:af6abc6f7590
- Child:
- 37:13f74964a045
File content as of revision 36:af6abc6f7590:
#include "mbed.h" #include "log.hpp" #include "Data.hpp" Serial serial(USBTX, USBRX); Mutex mutex_p; void readline(char* buffer) { int i = 0; while (1) { char c = serial.getc(); serial.putc(c); buffer[i] = c; if (c == '\n' || c == '\r') break; else i ++; } buffer[i] = '\0'; } void prompt_init() { serial.printf("Welcome to the nucleo board low level environmental sensor, type 'help' for commands\r\n"); } void prompt_interpret(char* cmd) { mutex_p.lock(); int n = log_length(); n = (n - 1); if (strcmp(cmd, "help") == 0){ serial.printf("Commands:\r\n help -\r\n READ ALL - Show all records \r\n"); } else if (strcmp(cmd, "READ ALL") == 0) {serial.printf("\r\n"); for (int i = n - 1; i >= 1; i--){ Data entry = log_get(i); serial.printf("%4.2fC %3.1f%% %6.1f %i %i %i \r\n", entry.tempCelsius, entry.humi, entry.pressure, entry.seconds, entry.minutes, entry.hours); } } else{ serial.printf("Unknown command!\r\n"); } mutex_p.unlock(); } void prompt_run() { while (1) { char buffer[64]; readline(buffer); prompt_interpret(buffer); } }