MAIN

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
J_Satchell
Date:
Mon May 15 08:58:08 2017 +0000
Revision:
36:af6abc6f7590
Child:
37:13f74964a045
Almost done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
J_Satchell 36:af6abc6f7590 1 #include "mbed.h"
J_Satchell 36:af6abc6f7590 2 #include "log.hpp"
J_Satchell 36:af6abc6f7590 3 #include "Data.hpp"
J_Satchell 36:af6abc6f7590 4
J_Satchell 36:af6abc6f7590 5 Serial serial(USBTX, USBRX);
J_Satchell 36:af6abc6f7590 6 Mutex mutex_p;
J_Satchell 36:af6abc6f7590 7
J_Satchell 36:af6abc6f7590 8
J_Satchell 36:af6abc6f7590 9 void readline(char* buffer)
J_Satchell 36:af6abc6f7590 10 {
J_Satchell 36:af6abc6f7590 11 int i = 0;
J_Satchell 36:af6abc6f7590 12 while (1)
J_Satchell 36:af6abc6f7590 13 {
J_Satchell 36:af6abc6f7590 14 char c = serial.getc();
J_Satchell 36:af6abc6f7590 15 serial.putc(c);
J_Satchell 36:af6abc6f7590 16 buffer[i] = c;
J_Satchell 36:af6abc6f7590 17
J_Satchell 36:af6abc6f7590 18 if (c == '\n' || c == '\r')
J_Satchell 36:af6abc6f7590 19 break;
J_Satchell 36:af6abc6f7590 20 else
J_Satchell 36:af6abc6f7590 21 i ++;
J_Satchell 36:af6abc6f7590 22 }
J_Satchell 36:af6abc6f7590 23 buffer[i] = '\0';
J_Satchell 36:af6abc6f7590 24 }
J_Satchell 36:af6abc6f7590 25
J_Satchell 36:af6abc6f7590 26 void prompt_init()
J_Satchell 36:af6abc6f7590 27 {
J_Satchell 36:af6abc6f7590 28 serial.printf("Welcome to the nucleo board low level environmental sensor, type 'help' for commands\r\n");
J_Satchell 36:af6abc6f7590 29 }
J_Satchell 36:af6abc6f7590 30
J_Satchell 36:af6abc6f7590 31
J_Satchell 36:af6abc6f7590 32
J_Satchell 36:af6abc6f7590 33 void prompt_interpret(char* cmd)
J_Satchell 36:af6abc6f7590 34 { mutex_p.lock();
J_Satchell 36:af6abc6f7590 35 int n = log_length();
J_Satchell 36:af6abc6f7590 36 n = (n - 1);
J_Satchell 36:af6abc6f7590 37 if (strcmp(cmd, "help") == 0){
J_Satchell 36:af6abc6f7590 38 serial.printf("Commands:\r\n help -\r\n READ ALL - Show all records \r\n");
J_Satchell 36:af6abc6f7590 39 }
J_Satchell 36:af6abc6f7590 40 else if (strcmp(cmd, "READ ALL") == 0)
J_Satchell 36:af6abc6f7590 41 {serial.printf("\r\n");
J_Satchell 36:af6abc6f7590 42 for (int i = n - 1; i >= 1; i--){
J_Satchell 36:af6abc6f7590 43 Data entry = log_get(i);
J_Satchell 36:af6abc6f7590 44 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);
J_Satchell 36:af6abc6f7590 45 }
J_Satchell 36:af6abc6f7590 46 }
J_Satchell 36:af6abc6f7590 47 else{
J_Satchell 36:af6abc6f7590 48 serial.printf("Unknown command!\r\n");
J_Satchell 36:af6abc6f7590 49 }
J_Satchell 36:af6abc6f7590 50 mutex_p.unlock();
J_Satchell 36:af6abc6f7590 51 }
J_Satchell 36:af6abc6f7590 52 void prompt_run()
J_Satchell 36:af6abc6f7590 53 {
J_Satchell 36:af6abc6f7590 54 while (1)
J_Satchell 36:af6abc6f7590 55 {
J_Satchell 36:af6abc6f7590 56 char buffer[64];
J_Satchell 36:af6abc6f7590 57 readline(buffer);
J_Satchell 36:af6abc6f7590 58
J_Satchell 36:af6abc6f7590 59 prompt_interpret(buffer);
J_Satchell 36:af6abc6f7590 60 }
J_Satchell 36:af6abc6f7590 61 }