Network, SD card, Serial, LCD and sensors all work! :) ** Don't Press the User Button without an SD Card inserted!! **
Dependencies: BMP280
Fork of Thread_Communication_V2 by
main.cpp
- Committer:
- GeorgeJourneaux
- Date:
- 2017-12-14
- Revision:
- 2:28d12a3db239
- Parent:
- 1:bca9993a0df3
- Child:
- 3:73497379c0cb
File content as of revision 2:28d12a3db239:
#include "mbed.h" #include "main.h" LCD lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15); BMP280 Sensor(D14, D15); void PrintLCD (); void Rx_interrupt(); void Serial_CMD(); volatile int rx_in=0; char rx_line[80]; int s_cmd = 0; /* Mail */ typedef struct { float LDR_Value; float temp_Value; float press_Value; } mail_t; Mail<mail_t, 16> mail_box; Thread t1; Thread t2; Thread S_CMD; void PrintLCD () { int i = 0; while(1){ char lightString[16]; char tempString[16]; char pressString[16]; lcd.Clear(); lcd.RowSelect(0); switch (i){ case 0: osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; sprintf(lightString,"%.4f", mail->LDR_Value); sprintf(tempString,"%2.2f", mail->temp_Value); sprintf(pressString,"%4.2f", mail->press_Value); mail_box.free(mail); } lcd.Write("Light Level:"); lcd.RowSelect(1); lcd.Write(lightString); i++; break; case 1: lcd.Write("Temperature:"); lcd.RowSelect(1); lcd.Write(tempString); i++; break; case 2: lcd.Write("Pressure:"); lcd.RowSelect(1); lcd.Write(pressString); i =0; break; default: i = 0; break; } Red_int = !Red_int; Thread::wait (5000); } } int main() { t1.start(PrintLCD); pc.baud(9600); pc.attach(&Rx_interrupt, Serial::RxIrq); S_CMD.start(Serial_CMD); while(1) { Green_int = !Green_int; mail_t *mail = mail_box.alloc(); mail->LDR_Value = LDR_In.read(); mail->temp_Value = Sensor.getTemperature(); mail->press_Value = Sensor.getPressure(); mail_box.put(mail); Thread::wait (15000); } } void Rx_interrupt() { while (pc.readable()) { rx_line[rx_in] = pc.getc(); pc.putc(rx_line[rx_in]); if(rx_line[rx_in] == 0xD){ s_cmd = 1; } else{ rx_in = (rx_in + 1); } } } void Serial_CMD(){ while(1){ if(s_cmd == 1){ pc.attach(NULL, Serial::RxIrq); if(strstr(rx_line, "READ ALL")){ pc.printf("READ ALL\n\r"); } else if(strstr(rx_line, "DELETE ALL")){ pc.printf("DELETE ALL\n\r"); } else if(strstr(rx_line, "READ")){ pc.printf("READ\n\r"); } else if(strstr(rx_line, "DELETE")){ pc.printf("SETDATE\n\r"); } else if(strstr(rx_line, "SETTIME")){ pc.printf("SETTIME\n\r"); } else if(strstr(rx_line, "SETT")){ pc.printf("SETT\n\r"); } else if(strstr(rx_line, "STATE")){ pc.printf("STATE\n\r"); } else if(strstr(rx_line, "LOGGING")){ pc.printf("LOGGING\n\r"); } else{ pc.printf("ERROR\n\r"); } memset(rx_line, NULL, 80); rx_in = 0; pc.attach(&Rx_interrupt, Serial::RxIrq); s_cmd = 0; } Thread::wait(5); } }