FINAL PROJECT isn't it

Fork of ELEC351 by Plymouth ELEC351 Group T

Committer:
chills
Date:
Sat Dec 30 21:31:20 2017 +0000
Revision:
24:7d2da96e05ad
Parent:
23:3c85d7f657a2
Child:
25:36699ed589ab
2017_12_30 21:28; Serial Commands runs Serial Comms;

Who changed what in which revision?

UserRevisionLine numberNew 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 8:0e4481b64353 4 Current Verision 3
thomasmorris 6:97f586597310 5 Overiew: Working Tasks 1,5,7
thomasmorris 8:0e4481b64353 6
thomasmorris 12:536eca338ae8 7 Last Revision: Added Mail Box to serial
thomasmorris 8:0e4481b64353 8 Todo:
thomasmorris 12:536eca338ae8 9 make a mailbox within SD card, LCD, network so they can be used from within
thomasmorris 12:536eca338ae8 10 Fix the network so it uses the mail box data.
thomasmorris 12:536eca338ae8 11 Place the LCD write functions in their own function
thomasmorris 6:97f586597310 12 */
thomasmorris 6:97f586597310 13
thomasmorris 8:0e4481b64353 14 //Includes and Definitions
chills 24:7d2da96e05ad 15 #include "sample_hardware.hpp"
chills 24:7d2da96e05ad 16 #include "Networkbits.hpp"
chills 24:7d2da96e05ad 17 #include "rtos.h"
chills 24:7d2da96e05ad 18 #include "LED.hpp"
chills 24:7d2da96e05ad 19 #include "DATA.hpp"
chills 24:7d2da96e05ad 20 #include "LCD.hpp"
chills 24:7d2da96e05ad 21 #define SamplingTime 1
chills 24:7d2da96e05ad 22 #define NotSamplingTime 0
chills 24:7d2da96e05ad 23 #define Print_Time_to_LCD 1
chills 24:7d2da96e05ad 24 #define Dont_Print_Time_to_LCD 0
chills 24:7d2da96e05ad 25 #define TimerInterval 2 //This is in seconds
chills 24:7d2da96e05ad 26 #define EDGE_RISEN 1
chills 24:7d2da96e05ad 27 #define EDGE_FALLEN 0
chills 24:7d2da96e05ad 28 #define mailsize 5
chills 24:7d2da96e05ad 29 #include <iostream>
chills 24:7d2da96e05ad 30 Serial pc(USBTX, USBRX);
chills 24:7d2da96e05ad 31 //SW1+SW2 are declared as interrupt ins in sample hardware.cpp
thomasmorris 8:0e4481b64353 32
chills 24:7d2da96e05ad 33 void Serial_Comms();
chills 24:7d2da96e05ad 34
chills 24:7d2da96e05ad 35 //Thread IDs
chills 24:7d2da96e05ad 36 osThreadId idMain;
chills 24:7d2da96e05ad 37 osThreadId id1;
chills 24:7d2da96e05ad 38 osThreadId id2;
chills 24:7d2da96e05ad 39 osThreadId id3;
chills 24:7d2da96e05ad 40 osThreadId id4;
chills 24:7d2da96e05ad 41 osThreadId id5;
chills 24:7d2da96e05ad 42
chills 24:7d2da96e05ad 43
chills 24:7d2da96e05ad 44 Timeout sw1TimeOut;//Used to prevent switch bounce
chills 24:7d2da96e05ad 45
chills 24:7d2da96e05ad 46 LED Red_led(PE_15);
chills 24:7d2da96e05ad 47 LED Yellow_led(PB_10);
chills 24:7d2da96e05ad 48 LED Green_led(PB_11);
chills 24:7d2da96e05ad 49
chills 24:7d2da96e05ad 50 LCD LCD(D8,D9,D4,A0,A1,A2,A3,D7,D6,D3,D1);
chills 24:7d2da96e05ad 51 char LCD_buffer [50];
chills 24:7d2da96e05ad 52 int LCD_sprintf;
chills 24:7d2da96e05ad 53
chills 24:7d2da96e05ad 54 //Tickers
chills 24:7d2da96e05ad 55
chills 24:7d2da96e05ad 56 Ticker Sample_timer;
chills 24:7d2da96e05ad 57
chills 24:7d2da96e05ad 58 //Threads
chills 24:7d2da96e05ad 59 Thread t1;
chills 24:7d2da96e05ad 60 Thread t2;
chills 24:7d2da96e05ad 61 Thread t3;
chills 24:7d2da96e05ad 62 Thread t4;
chills 24:7d2da96e05ad 63 Thread t5;
chills 24:7d2da96e05ad 64
chills 24:7d2da96e05ad 65 double temp = 0;
chills 24:7d2da96e05ad 66 double pressure = 0;
chills 24:7d2da96e05ad 67 double lux = 0;
chills 24:7d2da96e05ad 68 string buffer_time = 0;
chills 24:7d2da96e05ad 69
chills 24:7d2da96e05ad 70 char buffer[32];
chills 24:7d2da96e05ad 71 char scom_time_buffer[32];
chills 24:7d2da96e05ad 72 char msel_time_buffer[32];
chills 24:7d2da96e05ad 73
chills 24:7d2da96e05ad 74 void SW1FallingEdge();
chills 24:7d2da96e05ad 75 void SW1TimeOutHandler();
chills 24:7d2da96e05ad 76
chills 24:7d2da96e05ad 77
chills 24:7d2da96e05ad 78
chills 24:7d2da96e05ad 79 using namespace std;
chills 24:7d2da96e05ad 80
chills 24:7d2da96e05ad 81 int mode = 0;
chills 24:7d2da96e05ad 82
chills 24:7d2da96e05ad 83 Mail<DATA, mailsize> mail_box; //Mail Queue, Type DATA, Capacity mailsize(defined above), name mail_box
chills 24:7d2da96e05ad 84
chills 13:db857b3744c6 85 void Network() //Interrupt service routine for handling the timeout
thomasmorris 8:0e4481b64353 86 {
chills 13:db857b3744c6 87 osEvent evt_network = mail_box.get(); //Get the latest entry from "mail_box"
chills 13:db857b3744c6 88
chills 13:db857b3744c6 89 if (evt_network.status == osEventMail)
chills 13:db857b3744c6 90 {
chills 17:37d883f40c3d 91 DATA *Rec_Data_Network = (DATA*)evt_network.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 92 DATA msg_network; //Create temporary instance of DATA class
chills 13:db857b3744c6 93
chills 17:37d883f40c3d 94 msg_network.set_time(Rec_Data_Network->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 95 msg_network.set_temperature(Rec_Data_Network->get_temperature()); //Copy temperature from mailbox to temporary instance
chills 17:37d883f40c3d 96 msg_network.set_pressure(Rec_Data_Network->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 97 msg_network.set_light(Rec_Data_Network->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 98 mail_box.free(Rec_Data_Network); //Free space in the mailbox (delete earliest sample taken)
chills 13:db857b3744c6 99
chills 24:7d2da96e05ad 100 networktest();
chills 13:db857b3744c6 101 }
chills 13:db857b3744c6 102 }
chills 13:db857b3744c6 103
thomasmorris 8:0e4481b64353 104 void SW1TimeOutHandler()
thomasmorris 8:0e4481b64353 105 {
thomasmorris 7:dfe19413fdc2 106 sw1TimeOut.detach(); //Stop the timeout counter firing
thomasmorris 7:dfe19413fdc2 107 SW1.fall(&SW1FallingEdge); //Now wait for a falling edge
thomasmorris 7:dfe19413fdc2 108 }
chills 24:7d2da96e05ad 109 void SDWrite()//End of skype chat
thomasmorris 12:536eca338ae8 110 {
chills 13:db857b3744c6 111 osEvent evt_sd = mail_box.get(); //Get the latest entry from "mail_box"
chills 13:db857b3744c6 112
chills 13:db857b3744c6 113 if (evt_sd.status == osEventMail)
chills 13:db857b3744c6 114 {
chills 17:37d883f40c3d 115 DATA *Rec_Data_SD = (DATA*)evt_sd.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 116 DATA msg_sd; //Create temporary instance of DATA class
chills 13:db857b3744c6 117
chills 17:37d883f40c3d 118 msg_sd.set_time(Rec_Data_SD->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 119 msg_sd.set_temperature(Rec_Data_SD->get_temperature()); //Copy temperature from mailbox to temporary instance
chills 17:37d883f40c3d 120 msg_sd.set_pressure(Rec_Data_SD->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 121 msg_sd.set_light(Rec_Data_SD->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 122 mail_box.free(Rec_Data_SD); //Free space in the mailbox (delete earliest sample taken)
chills 13:db857b3744c6 123 }
thomasmorris 12:536eca338ae8 124 }
thomasmorris 7:dfe19413fdc2 125 //Interrupt service routive for SW1 falling edge (release)
thomasmorris 19:54bc302a82ea 126 void SW1FallingEdge()
thomasmorris 19:54bc302a82ea 127 {
thomasmorris 7:dfe19413fdc2 128 SW1.fall(NULL); //Disable this interrupt
chills 16:067916791a25 129 Yellow_led.Toggle(); //Toggle LED
thomasmorris 7:dfe19413fdc2 130
thomasmorris 7:dfe19413fdc2 131 mode = mode +1;//Cycles through modes
thomasmorris 7:dfe19413fdc2 132 if(mode >1)
thomasmorris 7:dfe19413fdc2 133 {
thomasmorris 7:dfe19413fdc2 134 mode = 0;
thomasmorris 7:dfe19413fdc2 135 }
thomasmorris 7:dfe19413fdc2 136
thomasmorris 7:dfe19413fdc2 137 sw1TimeOut.attach(&SW1TimeOutHandler, 0.2); //Start timeout counter
thomasmorris 7:dfe19413fdc2 138 }
thomasmorris 7:dfe19413fdc2 139 void ModeSelection()
thomasmorris 7:dfe19413fdc2 140 {
thomasmorris 7:dfe19413fdc2 141 while(1){
chills 13:db857b3744c6 142
chills 24:7d2da96e05ad 143 //Thread::wait(1000);
chills 13:db857b3744c6 144
chills 13:db857b3744c6 145 osEvent evt_lcd = mail_box.get(); //Get the latest entry from "mail_box"
chills 13:db857b3744c6 146
chills 13:db857b3744c6 147 if (evt_lcd.status == osEventMail)
thomasmorris 7:dfe19413fdc2 148 {
chills 17:37d883f40c3d 149 DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 150 DATA msg_lcd; //Create temporary instance of DATA class
chills 13:db857b3744c6 151
chills 17:37d883f40c3d 152 msg_lcd.set_time(Rec_Data_LCD->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 153 msg_lcd.set_temperature(Rec_Data_LCD->get_temperature()); //Copy temperature from mailbox to temporary instance
chills 17:37d883f40c3d 154 msg_lcd.set_pressure(Rec_Data_LCD->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 155 msg_lcd.set_light(Rec_Data_LCD->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 156 mail_box.free(Rec_Data_LCD); //Free space in the mailbox (delete earliest sample taken)
chills 13:db857b3744c6 157
chills 13:db857b3744c6 158 if(mode == 0)//Print values to the LCD
chills 13:db857b3744c6 159 {
chills 13:db857b3744c6 160 //Write new data to LCD (not fast!)
thomasmorris 21:3c078c799caa 161
chills 24:7d2da96e05ad 162 /*LCD_sprintf = */sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",msg_lcd.get_temperature(),msg_lcd.get_pressure(),msg_lcd.get_light());//Used for converting to a sting
thomasmorris 21:3c078c799caa 163
thomasmorris 21:3c078c799caa 164 //LCD.Display_Clear();
thomasmorris 21:3c078c799caa 165 LCD.DDRAM_Address(0x00);
thomasmorris 21:3c078c799caa 166 LCD.Write_String("Temp Pres li");
thomasmorris 21:3c078c799caa 167 LCD.DDRAM_Address(0x40);
thomasmorris 21:3c078c799caa 168
thomasmorris 21:3c078c799caa 169 LCD.Write_String(LCD_buffer);
thomasmorris 21:3c078c799caa 170 //LCD.Write_String("Temp Pres li\n");
thomasmorris 21:3c078c799caa 171 //LCD.Write_String("%1.1f ", msg_lcd.get_temperature());//Print Temperature to LCD
thomasmorris 21:3c078c799caa 172 //LCD.Write_String("%1.1f ", msg_lcd.get_pressure());//Print Pressure to LCD
thomasmorris 21:3c078c799caa 173 //LCD.Write_String("%1.1f\n", msg_lcd.get_light()); //Print Light to LCD
thomasmorris 21:3c078c799caa 174
chills 13:db857b3744c6 175 }
chills 13:db857b3744c6 176 else if(mode == 1)//Print the Time to the LCD
chills 13:db857b3744c6 177 {
chills 17:37d883f40c3d 178 time_t msel_time = msg_lcd.get_time(); //Declare local variable for time
thomasmorris 18:194a606ccd47 179 strftime(scom_time_buffer, 32, "%I:%M %p", localtime(&msel_time)); //Format time as a string
thomasmorris 21:3c078c799caa 180 LCD.Display_Clear();
chills 24:7d2da96e05ad 181 LCD_sprintf = sprintf (LCD_buffer, "%s",scom_time_buffer);
thomasmorris 21:3c078c799caa 182 LCD.DDRAM_Address(0x00);
thomasmorris 21:3c078c799caa 183 LCD.Write_String("Current Time:");
thomasmorris 21:3c078c799caa 184 LCD.DDRAM_Address(0x40);
thomasmorris 21:3c078c799caa 185 LCD.Write_String(LCD_buffer);
thomasmorris 21:3c078c799caa 186
chills 13:db857b3744c6 187 }
chills 13:db857b3744c6 188 else
chills 13:db857b3744c6 189 {
chills 13:db857b3744c6 190 mode = 0;
chills 13:db857b3744c6 191 }
thomasmorris 7:dfe19413fdc2 192 }
thomasmorris 7:dfe19413fdc2 193 }
thomasmorris 7:dfe19413fdc2 194 }
thomasmorris 22:eb4cc12087b2 195 void Serial_Commands()
thomasmorris 22:eb4cc12087b2 196 {
chills 24:7d2da96e05ad 197 string Serial_Input;
thomasmorris 22:eb4cc12087b2 198 while(1)
thomasmorris 22:eb4cc12087b2 199 {
chills 24:7d2da96e05ad 200 cout << "Please type in a command" << endl;
chills 24:7d2da96e05ad 201
thomasmorris 22:eb4cc12087b2 202 cin >> Serial_Input;
chills 24:7d2da96e05ad 203
thomasmorris 22:eb4cc12087b2 204 if (Serial_Input == "Test")
thomasmorris 22:eb4cc12087b2 205 {
chills 24:7d2da96e05ad 206 cout << "Test Confirmed" << endl;
thomasmorris 22:eb4cc12087b2 207 }
chills 24:7d2da96e05ad 208 else if(Serial_Input == "READ-ALL")
thomasmorris 22:eb4cc12087b2 209 {
chills 24:7d2da96e05ad 210 cout << "Read All Confirmed" << endl;
chills 24:7d2da96e05ad 211 t2.start(Serial_Comms);
thomasmorris 22:eb4cc12087b2 212 }
chills 24:7d2da96e05ad 213 else if(Serial_Input == "DELETE ALL")
thomasmorris 22:eb4cc12087b2 214 {
thomasmorris 22:eb4cc12087b2 215
thomasmorris 22:eb4cc12087b2 216 }
chills 24:7d2da96e05ad 217 else if(Serial_Input == "READ <n>")
thomasmorris 22:eb4cc12087b2 218 {
thomasmorris 22:eb4cc12087b2 219
thomasmorris 22:eb4cc12087b2 220 }
chills 24:7d2da96e05ad 221 else if(Serial_Input == "DELETE <n>")
thomasmorris 22:eb4cc12087b2 222 {
thomasmorris 22:eb4cc12087b2 223
thomasmorris 22:eb4cc12087b2 224 }
chills 24:7d2da96e05ad 225 else if(Serial_Input == "SETDATE <dd> <mm> <yyyy>")
thomasmorris 22:eb4cc12087b2 226 {
thomasmorris 22:eb4cc12087b2 227
thomasmorris 22:eb4cc12087b2 228 }
chills 24:7d2da96e05ad 229 else if(Serial_Input == "SETT <T>")
thomasmorris 22:eb4cc12087b2 230 {
thomasmorris 22:eb4cc12087b2 231
thomasmorris 22:eb4cc12087b2 232 }
chills 24:7d2da96e05ad 233 else if(Serial_Input == "STATE <x>")
thomasmorris 22:eb4cc12087b2 234 {
thomasmorris 22:eb4cc12087b2 235
thomasmorris 22:eb4cc12087b2 236 }
chills 24:7d2da96e05ad 237 else if(Serial_Input == "LOGGING <x>")
thomasmorris 22:eb4cc12087b2 238 {
thomasmorris 22:eb4cc12087b2 239
thomasmorris 22:eb4cc12087b2 240 }
thomasmorris 22:eb4cc12087b2 241 else if(Serial_Input == "HELP")// Use this to display all of the availble commands
thomasmorris 22:eb4cc12087b2 242 {
chills 24:7d2da96e05ad 243 cout << "Avalible Commands are: "<< endl;
chills 24:7d2da96e05ad 244 cout << "READ ALL , DELETE ALL READ<n> ,DELETE<n> , SETDATE<dd> <mm> <yyyy> , SETTIME <hh> <mm> <ss>, SETT <T> , STATE <x>, LOGGING <x>, HELP"<< endl;
thomasmorris 22:eb4cc12087b2 245 }
thomasmorris 22:eb4cc12087b2 246 else
thomasmorris 22:eb4cc12087b2 247 {
thomasmorris 22:eb4cc12087b2 248 cout << "Please enter a acceptable command" << endl;
thomasmorris 22:eb4cc12087b2 249 }
thomasmorris 22:eb4cc12087b2 250 }
thomasmorris 22:eb4cc12087b2 251 }
chills 24:7d2da96e05ad 252 void Serial_Comms()//Thread for Serial Communications
thomasmorris 5:2594b953f111 253 {
chills 24:7d2da96e05ad 254 cout << "In Serial Comms" << endl;
thomasmorris 5:2594b953f111 255 while(1)
thomasmorris 5:2594b953f111 256 {
chills 24:7d2da96e05ad 257 Thread::signal_wait(1);
chills 13:db857b3744c6 258 osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box"
chills 10:46946784326d 259
chills 13:db857b3744c6 260 if (evt_serial.status == osEventMail)
thomasmorris 12:536eca338ae8 261 {
chills 17:37d883f40c3d 262 DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 263 DATA msg_serial; //Create temporary instance of DATA class
chills 11:e7b5ed6cd3cf 264
chills 17:37d883f40c3d 265 msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 266 msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance
chills 17:37d883f40c3d 267 msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 268 msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 269 mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken)
chills 11:e7b5ed6cd3cf 270
chills 17:37d883f40c3d 271 time_t scom_time = msg_serial.get_time(); //Declare local variable for time
chills 17:37d883f40c3d 272 strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string
chills 17:37d883f40c3d 273 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
chills 15:c1592fc1a501 274
chills 13:db857b3744c6 275 pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature
chills 13:db857b3744c6 276 pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure
chills 13:db857b3744c6 277 pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light
chills 10:46946784326d 278 }
thomasmorris 7:dfe19413fdc2 279 Green_led.Toggle();
chills 16:067916791a25 280 //Thread::wait(1000);
thomasmorris 5:2594b953f111 281 }
thomasmorris 5:2594b953f111 282 }
thomasmorris 5:2594b953f111 283
chills 10:46946784326d 284 void Sample_signal_set() //Sets the Signal for when to sample the sensors
thomasmorris 5:2594b953f111 285 {
chills 10:46946784326d 286 t1.signal_set(SamplingTime); //Set the sampling thread signal high
chills 24:7d2da96e05ad 287 t2.signal_set(1);
thomasmorris 5:2594b953f111 288 }
thomasmorris 5:2594b953f111 289 void Sample()//Samples the hardware and prints the result to the LCD
thomasmorris 5:2594b953f111 290 {
thomasmorris 5:2594b953f111 291 while(1)
thomasmorris 5:2594b953f111 292 {
chills 10:46946784326d 293 Thread::signal_wait(SamplingTime); //Set the time between samples
chills 10:46946784326d 294
chills 10:46946784326d 295 temp = sensor.getTemperature(); //Read Temperature
chills 10:46946784326d 296 pressure = sensor.getPressure(); //Read Pressure
chills 10:46946784326d 297 lux = adcIn.read(); //Read Light
chills 16:067916791a25 298 time_t buffer_time = time(NULL); //Read Time
thomasmorris 7:dfe19413fdc2 299
chills 16:067916791a25 300 DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data
thomasmorris 5:2594b953f111 301
chills 16:067916791a25 302 if (Send_Data == NULL){ //If Data is empty
chills 16:067916791a25 303 //pc.printf("Out of memory\n\r"); //Print out of memory warning
chills 10:46946784326d 304 return;
chills 10:46946784326d 305 }
chills 10:46946784326d 306
chills 10:46946784326d 307 Send_Data->set_time(buffer_time); //Pass in Time
chills 10:46946784326d 308 Send_Data->set_temperature(temp); //Pass in Temp
chills 10:46946784326d 309 Send_Data->set_pressure(pressure); //Pass in Pres
chills 10:46946784326d 310 Send_Data->set_light(lux); //Pass in Light
chills 10:46946784326d 311
chills 10:46946784326d 312 osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox
chills 10:46946784326d 313
chills 10:46946784326d 314 if (stat == osErrorResource){ //If mailbox overfills
chills 10:46946784326d 315 //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); //Print error message
chills 10:46946784326d 316 mail_box.free(Send_Data); //Free the mail box
chills 10:46946784326d 317 return;
chills 10:46946784326d 318 }
thomasmorris 5:2594b953f111 319 Red_led.Toggle();
thomasmorris 5:2594b953f111 320 t1.signal_set(NotSamplingTime);
thomasmorris 5:2594b953f111 321 }
thomasmorris 5:2594b953f111 322 }
thomasmorris 5:2594b953f111 323 int main()
thomasmorris 5:2594b953f111 324 {
chills 24:7d2da96e05ad 325
chills 24:7d2da96e05ad 326
chills 24:7d2da96e05ad 327
noutram 1:e1cf7663f5ff 328 //Greeting
chills 16:067916791a25 329 pc.printf("Test Start");
chills 16:067916791a25 330 pc.printf("\n\r");
chills 16:067916791a25 331
chills 10:46946784326d 332 set_time(1512940530); //Set RTC time to December 10 2017
chills 10:46946784326d 333 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 5:2594b953f111 334
chills 20:cbb71f84cff9 335 LCD.Initialise();
chills 24:7d2da96e05ad 336 LCD.DDRAM_Address(0x40);
thomasmorris 21:3c078c799caa 337
chills 24:7d2da96e05ad 338
chills 24:7d2da96e05ad 339 /*post(); //Power on Self Test
noutram 1:e1cf7663f5ff 340
noutram 3:a88838ff33e7 341 //Initialise the SD card (this needs to move)
noutram 1:e1cf7663f5ff 342 if ( sd.init() != 0) {
noutram 1:e1cf7663f5ff 343 printf("Init failed \n");
chills 24:7d2da96e05ad 344 lcd.cls();
chills 24:7d2da96e05ad 345 lcd.printf("CANNOT INIT SD"); //Change me
noutram 1:e1cf7663f5ff 346 errorCode(FATAL);
noutram 1:e1cf7663f5ff 347 }
noutram 1:e1cf7663f5ff 348
noutram 1:e1cf7663f5ff 349 //Create a filing system for SD Card
noutram 1:e1cf7663f5ff 350 FATFileSystem fs("sd", &sd);
noutram 0:36e89e3ed7c4 351
noutram 1:e1cf7663f5ff 352 //Open to WRITE
noutram 1:e1cf7663f5ff 353 FILE* fp = fopen("/sd/test.csv","a");
noutram 1:e1cf7663f5ff 354 if (fp == NULL) {
noutram 1:e1cf7663f5ff 355 error("Could not open file for write\n");
chills 24:7d2da96e05ad 356 lcd.cls();
chills 24:7d2da96e05ad 357 lcd.printf("CANNOT OPEN FILE\n\n");//Change me
noutram 1:e1cf7663f5ff 358 errorCode(FATAL);
noutram 1:e1cf7663f5ff 359 }
noutram 3:a88838ff33e7 360
noutram 3:a88838ff33e7 361 //Last message before sampling begins
chills 24:7d2da96e05ad 362 lcd.cls();//change me
chills 24:7d2da96e05ad 363 lcd.printf("READY\n\n");//change me
thomasmorris 5:2594b953f111 364
chills 24:7d2da96e05ad 365 */
chills 24:7d2da96e05ad 366
chills 24:7d2da96e05ad 367 //Run interrupt
chills 24:7d2da96e05ad 368 Sample_timer.attach(&Sample_signal_set,TimerInterval);
thomasmorris 23:3c85d7f657a2 369 SW1.fall(&SW1FallingEdge);
chills 24:7d2da96e05ad 370
thomasmorris 5:2594b953f111 371 t1.start(Sample);
thomasmorris 21:3c078c799caa 372 t3.start(ModeSelection);
chills 24:7d2da96e05ad 373 //t4.start(Network);
thomasmorris 23:3c85d7f657a2 374 t5.start(Serial_Commands);
chills 24:7d2da96e05ad 375
chills 24:7d2da96e05ad 376
thomasmorris 5:2594b953f111 377 //Main thread ID
thomasmorris 5:2594b953f111 378
thomasmorris 5:2594b953f111 379 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 5:2594b953f111 380
thomasmorris 5:2594b953f111 381 //Thread ID
thomasmorris 5:2594b953f111 382 id1 = t1.gettid();
thomasmorris 5:2594b953f111 383 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 384 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 385 id4 = t4.gettid();
chills 24:7d2da96e05ad 386 id5 = t5.gettid();
thomasmorris 21:3c078c799caa 387
thomasmorris 5:2594b953f111 388
thomasmorris 5:2594b953f111 389 //Toggle Green LED after a button has been pressed
noutram 1:e1cf7663f5ff 390 //Press either switch to unmount
thomasmorris 7:dfe19413fdc2 391 DigitalIn onBoardSwitch(USER_BUTTON);
thomasmorris 21:3c078c799caa 392
thomasmorris 7:dfe19413fdc2 393 while (onBoardSwitch == 0){
thomasmorris 7:dfe19413fdc2 394
noutram 1:e1cf7663f5ff 395 }
noutram 1:e1cf7663f5ff 396
noutram 1:e1cf7663f5ff 397 //Close File
chills 15:c1592fc1a501 398 /*
noutram 1:e1cf7663f5ff 399 fclose(fp);
noutram 1:e1cf7663f5ff 400
noutram 1:e1cf7663f5ff 401 //Close down
noutram 1:e1cf7663f5ff 402 sd.deinit();
noutram 1:e1cf7663f5ff 403 printf("Unmounted...\n");
noutram 1:e1cf7663f5ff 404 lcd.cls();
noutram 1:e1cf7663f5ff 405 lcd.printf("Unmounted...\n\n");
chills 15:c1592fc1a501 406 */
noutram 1:e1cf7663f5ff 407
noutram 1:e1cf7663f5ff 408 while(true) {
noutram 1:e1cf7663f5ff 409 greenLED = 1;
noutram 1:e1cf7663f5ff 410 wait(0.5);
noutram 1:e1cf7663f5ff 411 greenLED = 0;
noutram 1:e1cf7663f5ff 412 wait(0.1);
noutram 0:36e89e3ed7c4 413 }
noutram 0:36e89e3ed7c4 414 }
noutram 0:36e89e3ed7c4 415
noutram 1:e1cf7663f5ff 416
noutram 1:e1cf7663f5ff 417