Jamie Satchell
/
SOFT253_Weather_Sensor_JSatchell
MAIN
Fork of SOFT253_Template_Weather_OS_54 by
Diff: prompt.cpp
- Revision:
- 36:af6abc6f7590
- Child:
- 37:13f74964a045
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prompt.cpp Mon May 15 08:58:08 2017 +0000 @@ -0,0 +1,61 @@ +#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); + } +} \ No newline at end of file