Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
main.cpp@51:47f5db68500b, 2018-01-09 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Jan 09 15:15:08 2018 +0000
- Revision:
- 51:47f5db68500b
- Parent:
- 49:d51f96a46cc3
- Child:
- 52:99915f5240b2
Commenting Left; Sort out LCD number problem.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 6:97f586597310 | 1 | /* |
thomasmorris | 6:97f586597310 | 2 | ELEC 351 Group T |
thomasmorris | 6:97f586597310 | 3 | Team Members : Christopher Hills, Thomas Morris |
thomasmorris | 51:47f5db68500b | 4 | Current Verision 23 |
thomasmorris | 42:ae1640bca2e1 | 5 | Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13,14,15 |
thomasmorris | 51:47f5db68500b | 6 | EASTER EGG IS HERE!! |
thomasmorris | 51:47f5db68500b | 7 | */ |
thomasmorris | 8:0e4481b64353 | 8 | |
thomasmorris | 6:97f586597310 | 9 | |
thomasmorris | 25:36699ed589ab | 10 | #include "SETUP.hpp" |
thomasmorris | 35:26b0a9b55d82 | 11 | #include "NETWORK.hpp" |
thomasmorris | 47:6d128e500875 | 12 | #include "FIFO.hpp" |
thomasmorris | 47:6d128e500875 | 13 | #include "SD_CARD.hpp" |
thomasmorris | 47:6d128e500875 | 14 | #include "SERIAL_COMMANDS.hpp" |
thomasmorris | 47:6d128e500875 | 15 | #include "SAMPLE.hpp" |
thomasmorris | 47:6d128e500875 | 16 | #include "THREADS.hpp" |
thomasmorris | 41:859b5e1e3d9a | 17 | void SD_Card()//Writes data to the SD card |
thomasmorris | 41:859b5e1e3d9a | 18 | { |
thomasmorris | 41:859b5e1e3d9a | 19 | while(1) |
thomasmorris | 41:859b5e1e3d9a | 20 | { |
thomasmorris | 48:244d6d81bb52 | 21 | Thread::signal_wait(1); |
thomasmorris | 42:ae1640bca2e1 | 22 | Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again |
thomasmorris | 47:6d128e500875 | 23 | SD_Card_Write(); |
thomasmorris | 41:859b5e1e3d9a | 24 | } |
thomasmorris | 38:8d86e0d8a816 | 25 | } |
thomasmorris | 35:26b0a9b55d82 | 26 | void Network() |
thomasmorris | 8:0e4481b64353 | 27 | { |
thomasmorris | 35:26b0a9b55d82 | 28 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 29 | { |
thomasmorris | 48:244d6d81bb52 | 30 | Thread::wait(NetworkWaitTime);//Waits Network Wait amount of time |
thomasmorris | 47:6d128e500875 | 31 | Networking(); |
thomasmorris | 35:26b0a9b55d82 | 32 | } |
chills | 13:db857b3744c6 | 33 | } |
thomasmorris | 47:6d128e500875 | 34 | void LCD_Output() |
thomasmorris | 30:4cde05cc7c4f | 35 | { |
thomasmorris | 30:4cde05cc7c4f | 36 | while(1) |
thomasmorris | 29:64b1f95a807c | 37 | { |
thomasmorris | 41:859b5e1e3d9a | 38 | Thread::wait(10);//Small wait |
thomasmorris | 47:6d128e500875 | 39 | LCD_Print_Output(); |
thomasmorris | 7:dfe19413fdc2 | 40 | } |
thomasmorris | 7:dfe19413fdc2 | 41 | } |
thomasmorris | 47:6d128e500875 | 42 | void Serial_Commands() |
thomasmorris | 22:eb4cc12087b2 | 43 | { |
thomasmorris | 47:6d128e500875 | 44 | while(1) |
thomasmorris | 47:6d128e500875 | 45 | { |
thomasmorris | 47:6d128e500875 | 46 | Serial_Commands_Output(); |
thomasmorris | 47:6d128e500875 | 47 | } |
thomasmorris | 42:ae1640bca2e1 | 48 | |
thomasmorris | 22:eb4cc12087b2 | 49 | } |
thomasmorris | 48:244d6d81bb52 | 50 | void LED_Logging() |
thomasmorris | 48:244d6d81bb52 | 51 | { |
thomasmorris | 48:244d6d81bb52 | 52 | while(1) |
thomasmorris | 48:244d6d81bb52 | 53 | { |
thomasmorris | 48:244d6d81bb52 | 54 | if(Log_Value == 0) |
thomasmorris | 48:244d6d81bb52 | 55 | { |
thomasmorris | 48:244d6d81bb52 | 56 | Thread::wait(3000); |
thomasmorris | 48:244d6d81bb52 | 57 | } |
thomasmorris | 48:244d6d81bb52 | 58 | else if(Log_Value == 1) |
thomasmorris | 48:244d6d81bb52 | 59 | { |
thomasmorris | 48:244d6d81bb52 | 60 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 61 | Thread::wait(2800); |
thomasmorris | 48:244d6d81bb52 | 62 | } |
thomasmorris | 48:244d6d81bb52 | 63 | else if(Log_Value == 2) |
thomasmorris | 48:244d6d81bb52 | 64 | { |
thomasmorris | 48:244d6d81bb52 | 65 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 66 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 67 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 68 | Thread::wait(2400); |
thomasmorris | 48:244d6d81bb52 | 69 | } |
thomasmorris | 48:244d6d81bb52 | 70 | else if(Log_Value == 3) |
thomasmorris | 48:244d6d81bb52 | 71 | { |
thomasmorris | 48:244d6d81bb52 | 72 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 73 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 74 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 75 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 76 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 77 | Thread::wait(2000); |
thomasmorris | 48:244d6d81bb52 | 78 | } |
thomasmorris | 48:244d6d81bb52 | 79 | else if(Log_Value == 4) |
thomasmorris | 48:244d6d81bb52 | 80 | { |
thomasmorris | 48:244d6d81bb52 | 81 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 82 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 83 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 84 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 85 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 86 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 87 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 88 | Thread::wait(1600); |
thomasmorris | 48:244d6d81bb52 | 89 | } |
thomasmorris | 48:244d6d81bb52 | 90 | else if(Log_Value == 5) |
thomasmorris | 48:244d6d81bb52 | 91 | { |
thomasmorris | 48:244d6d81bb52 | 92 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 93 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 94 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 95 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 96 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 97 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 98 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 99 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 100 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 101 | Thread::wait(1200); |
thomasmorris | 48:244d6d81bb52 | 102 | } |
thomasmorris | 48:244d6d81bb52 | 103 | else |
thomasmorris | 48:244d6d81bb52 | 104 | { |
thomasmorris | 48:244d6d81bb52 | 105 | Log_Value = 0; |
thomasmorris | 48:244d6d81bb52 | 106 | } |
thomasmorris | 48:244d6d81bb52 | 107 | } |
thomasmorris | 48:244d6d81bb52 | 108 | } |
thomasmorris | 47:6d128e500875 | 109 | void Sample() |
thomasmorris | 5:2594b953f111 | 110 | { |
thomasmorris | 47:6d128e500875 | 111 | Sample_Event(); |
thomasmorris | 25:36699ed589ab | 112 | } |
thomasmorris | 25:36699ed589ab | 113 | int main() |
thomasmorris | 25:36699ed589ab | 114 | { |
thomasmorris | 37:7c4d7f206039 | 115 | set_time(1515352584); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 116 | |
chills | 10:46946784326d | 117 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 118 | |
chills | 20:cbb71f84cff9 | 119 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 120 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 121 | |
thomasmorris | 25:36699ed589ab | 122 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 123 | |
thomasmorris | 25:36699ed589ab | 124 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 125 | //Run interrupt |
chills | 26:78f5e454e59f | 126 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 127 | |
thomasmorris | 5:2594b953f111 | 128 | t1.start(Sample); |
thomasmorris | 41:859b5e1e3d9a | 129 | t2.start(SD_Card); |
thomasmorris | 30:4cde05cc7c4f | 130 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 131 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 132 | t5.start(Serial_Commands); |
thomasmorris | 48:244d6d81bb52 | 133 | t6.start(LED_Logging); |
thomasmorris | 5:2594b953f111 | 134 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 135 | |
thomasmorris | 5:2594b953f111 | 136 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 137 | |
thomasmorris | 5:2594b953f111 | 138 | //Thread ID |
thomasmorris | 5:2594b953f111 | 139 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 140 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 141 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 142 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 143 | id5 = t5.gettid(); |
thomasmorris | 48:244d6d81bb52 | 144 | id6 = t6.gettid(); |
thomasmorris | 25:36699ed589ab | 145 | |
thomasmorris | 48:244d6d81bb52 | 146 | while(true) |
thomasmorris | 48:244d6d81bb52 | 147 | { |
thomasmorris | 48:244d6d81bb52 | 148 | if(SD_CARD_DETECT.read() == 1) |
thomasmorris | 48:244d6d81bb52 | 149 | { |
thomasmorris | 49:d51f96a46cc3 | 150 | t2.signal_set(DONT_WRITE_TO_SD_CARD); |
thomasmorris | 49:d51f96a46cc3 | 151 | errorCode(SD_CARD_REMOVED); |
thomasmorris | 48:244d6d81bb52 | 152 | } |
thomasmorris | 48:244d6d81bb52 | 153 | else if(SD_CARD_DETECT.read() == 0) |
thomasmorris | 48:244d6d81bb52 | 154 | { |
thomasmorris | 49:d51f96a46cc3 | 155 | t2.signal_set(SD_CARD_WRITE); |
thomasmorris | 48:244d6d81bb52 | 156 | } |
thomasmorris | 48:244d6d81bb52 | 157 | else |
thomasmorris | 48:244d6d81bb52 | 158 | { |
thomasmorris | 49:d51f96a46cc3 | 159 | t2.signal_set(SD_CARD_WRITE); |
thomasmorris | 48:244d6d81bb52 | 160 | } |
thomasmorris | 41:859b5e1e3d9a | 161 | if(onBoardSwitch == 1) |
thomasmorris | 41:859b5e1e3d9a | 162 | { |
thomasmorris | 48:244d6d81bb52 | 163 | SD_Card_Eject(); |
thomasmorris | 45:875f7e18a386 | 164 | Green_led.switchOn(); |
thomasmorris | 41:859b5e1e3d9a | 165 | } |
noutram | 0:36e89e3ed7c4 | 166 | } |
thomasmorris | 45:875f7e18a386 | 167 | } |