![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 48:244d6d81bb52
- Parent:
- 47:6d128e500875
- Child:
- 49:d51f96a46cc3
--- a/main.cpp Mon Jan 08 21:53:40 2018 +0000 +++ b/main.cpp Tue Jan 09 00:37:01 2018 +0000 @@ -20,10 +20,12 @@ #include "SERIAL_COMMANDS.hpp" #include "SAMPLE.hpp" #include "THREADS.hpp" + void SD_Card()//Writes data to the SD card { while(1) { + Thread::signal_wait(1); Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again SD_Card_Write(); } @@ -32,7 +34,7 @@ { while(1) { - Thread::wait(NetworkWait);//Waits Network Wait amount of time + Thread::wait(NetworkWaitTime);//Waits Network Wait amount of time Networking(); } } @@ -52,7 +54,66 @@ } } - +void LED_Logging() +{ + while(1) + { + Yellow_led.switchOn(); + if(Log_Value == 0) + { + Thread::wait(3000); + } + else if(Log_Value == 1) + { + Yellow_led.flash(0.2); + Thread::wait(2800); + } + else if(Log_Value == 2) + { + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(2400); + } + else if(Log_Value == 3) + { + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(2000); + } + else if(Log_Value == 4) + { + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(1600); + } + else if(Log_Value == 5) + { + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(200); + Yellow_led.flash(0.2); + Thread::wait(1200); + } + else + { + Log_Value = 0; + } + } +} void Sample() { Sample_Event(); @@ -68,42 +129,6 @@ post(); //Power on Self Test - //Initialise the SD card (this needs to move) - if ( sd.init() != 0) { - printf("SD Init failed \n"); - LCD.Display_Clear(); - LCD.Write_String("CANNOT INIT SD"); //Change me - errorCode(FATAL); - } - //Create a filing system for SD Card - FATFileSystem fs("sd", &sd); - - //Open to WRITE - FILE* fp = fopen("/sd/test.csv","a");//test.csv is created in the SD Card - if (fp == NULL) { - error("Could not open file for write\n"); - LCD.Display_Clear(); - LCD.Write_String("CANNOT OPEN FILE"); - errorCode(FATAL); - } - //Close File - fclose(fp); - int network_temp; - network_temp = Network_Init(); - if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in - { - error("Could not access network"); - LCD.Display_Clear(); - LCD.Write_String("Could not access network"); - errorCode(NETWORK_FATAL); - } - //Last message before sampling begins - LCD.Display_Clear(); - LCD.Write_String("READY PLAYER"); - LCD.DDRAM_Address(0x40); - LCD.Write_String(" One "); - LCD.DDRAM_Address(0x00); - Sample_Rate = TimerInterval; //Run interrupt Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); @@ -113,7 +138,7 @@ t3.start(LCD_Output); t4.start(Network); t5.start(Serial_Commands); - + t6.start(LED_Logging); //Main thread ID idMain = osThreadGetId(); //CMSIS RTOS call @@ -124,19 +149,26 @@ id3 = t3.gettid(); id4 = t4.gettid(); id5 = t5.gettid(); + id6 = t6.gettid(); - while(true) { + + while(true) + { + if(SD_CARD_DETECT.read() == 1) + { + t2.signal_set(0); + } + else if(SD_CARD_DETECT.read() == 0) + { + t2.signal_set(1); + } + else + { + t2.signal_set(1); + } if(onBoardSwitch == 1) { - fclose(fp);//Close File - sd.deinit();//Close down - LCD.Display_Clear(); - LCD.DDRAM_Address(0x00); - LCD.Write_String("SD Card"); - LCD.DDRAM_Address(0x40); - LCD.Write_String("Unmounted"); - LCD.DDRAM_Address(0x00); - pc.printf("SD Card Unmounted\n"); + SD_Card_Eject(); Green_led.switchOn(); } }