GroupZ - 05012018 1511

Committer:
mslade
Date:
Tue Jan 09 14:53:07 2018 +0000
Revision:
1:84581acd1333
Parent:
0:1c898341428b
Final Version - Group U

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mslade 0:1c898341428b 1 #include "mbed.h"
mslade 1:84581acd1333 2 #include "lcdClass.h"
mslade 0:1c898341428b 3 #include "math.h"
mslade 1:84581acd1333 4 #include "SDBlockDevice.h"
mslade 1:84581acd1333 5 #include "FATFileSystem.h"
mslade 0:1c898341428b 6 #include "EthernetInterface.h"
mslade 0:1c898341428b 7 #include "TCPServer.h"
mslade 0:1c898341428b 8 #include "TCPSocket.h"
mslade 0:1c898341428b 9 #include "BMP280.h"
mslade 0:1c898341428b 10 #include <string>
mslade 0:1c898341428b 11 #include <iostream>
mslade 0:1c898341428b 12 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
mslade 0:1c898341428b 13 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
mslade 0:1c898341428b 14 #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \
mslade 0:1c898341428b 15 HTTP_HEADER_FIELDS "\r\n" \
mslade 0:1c898341428b 16 "\r\n" \
mslade 0:1c898341428b 17 HTTP_MESSAGE_BODY "\r\n"
mslade 0:1c898341428b 18
mslade 0:1c898341428b 19 #define IP "10.0.0.10"
mslade 0:1c898341428b 20 #define NETMASK "255.0.0.0"
mslade 0:1c898341428b 21 #define GATEWAY "10.0.0.1"
mslade 1:84581acd1333 22 //********************Variables and Initialisations****************************************//
mslade 1:84581acd1333 23 Serial myserial(USBTX,USBRX); lcdClass mylcd(D9,D8,D7,D6,D5,D4); DigitalOut leds(D11);
mslade 1:84581acd1333 24 InterruptIn SWi1(D1); InterruptIn SWi2(D0); InterruptIn SWi3(D2); AnalogIn ldrin(A0);
mslade 1:84581acd1333 25 int SW1 = 0; int SW2 = 0; int SW3 = 0; int record = 0; int serialmode = 0; int pcinput = 0;
mslade 1:84581acd1333 26 int lcdmode = 2; int datemode = 1; int y = 2015; int mon = 1; int d = 1; int h = 0; int minu = 0;
mslade 1:84581acd1333 27 Thread thread1, thread2, thread3, thread4, thread5, thread6; int serialcheck = 0; int samplerate = 1000;
mslade 1:84581acd1333 28 Semaphore mysem(10); char ldrString[10]; char tempString[10]; char presString[10]; BMP280 BMP(D14, D15);
mslade 1:84581acd1333 29 string database[5][120]; bool togPress = false; bool debugmode = false; bool data120 = false; bool switchactive = false;
mslade 1:84581acd1333 30 struct tm T; bool mainset = false; int SetDateTime(int year, int month, int day, int hour, int min);
mslade 1:84581acd1333 31 bool Pressed, Pressed1, yearPress, monPress, dayPress, hourPress, minPress = false; InterruptIn onBoardSwitch(USER_BUTTON);
mslade 1:84581acd1333 32 bool EditTimeParam = false; int TimeParam = 0; char Row1[32]; char Row2[32];
mslade 1:84581acd1333 33 SDBlockDevice sd(PB_5, D12, D13, D10); FATFileSystem fs("sd", &sd); //set up SD
mslade 1:84581acd1333 34 void serialmenu(); void ratelimiter(); void clockz(); void showrecord();
mslade 1:84581acd1333 35 //******************Variables and Initialisations*****************************************//
mslade 0:1c898341428b 36
mslade 1:84581acd1333 37 void sensors(void const *name) {
mslade 1:84581acd1333 38 //This function is used to sample the sensors, control the serial menu and update the 2D array
mslade 1:84581acd1333 39 while(true) {
mslade 0:1c898341428b 40 mysem.wait();
mslade 1:84581acd1333 41 Thread::wait(samplerate); //Set thread wait to the samplerate (default 1000ms)
mslade 1:84581acd1333 42 if (debugmode) {leds = 1;} //Turn on white LED
mslade 1:84581acd1333 43 time_t timer = time(NULL); //Set time to 0
mslade 1:84581acd1333 44 strftime(Row1, 32, "%H:%M:%S", localtime(&timer));//Format Time as string
mslade 1:84581acd1333 45 strftime(Row2, 32, "%d/%m/%Y", localtime(&timer)); //Format Date as string
mslade 1:84581acd1333 46 float ldr = floor(ldrin*30000)/100; //Set ldr to ldr value to 2 decimal points
mslade 1:84581acd1333 47 float temp = BMP.getTemperature(); //Set temp to the BMP temperature
mslade 1:84581acd1333 48 float presh = BMP.getPressure() ; //Set presh to the BMP pressure
mslade 1:84581acd1333 49 sprintf(ldrString , "%2.2f", ldr); //Format ldr as string
mslade 1:84581acd1333 50 sprintf(tempString, "%2.2f", temp); //Format temp as string
mslade 1:84581acd1333 51 sprintf(presString, "%3.2f", presh); //Format pressure as string
mslade 0:1c898341428b 52
mslade 1:84581acd1333 53 //Case statment for mode set by serial
mslade 1:84581acd1333 54 //0: Main, 1: live data, 2: show data, 3: delete data, 4: set samplerate, 5: set Time/date, 6: toggle debug, 7: show IP
mslade 1:84581acd1333 55 if (serialmode == 0 && mainset == false) {serialmenu(); mainset = true;}
mslade 1:84581acd1333 56 if (serialmode == 1 && mainset == false) {mainset = true; myserial.printf("ldr=%s temp=%s pres=%s \r\n", ldrString, tempString, presString); }
mslade 1:84581acd1333 57 if (serialmode == 2 && mainset == false) {showrecord(); mainset = true; }
mslade 1:84581acd1333 58 if (serialmode == 3 && mainset == false) {mainset = true; myserial.printf("Deleted all temp sensor data \r\n"); memset(database,0,sizeof(database));}
mslade 1:84581acd1333 59 if (serialmode == 4 && mainset == false) {ratelimiter(); mainset = true;}
mslade 1:84581acd1333 60 if (serialmode == 5 && mainset == false) {mainset = true; myserial.printf("Set Time/Date \r\n");}
mslade 1:84581acd1333 61 if (serialmode == 6 && mainset == false) {mainset = true; debugmode = !debugmode; if (debugmode) {myserial.printf("Debug on \r\n");} else {myserial.printf("Debug off \r\n");} }
mslade 1:84581acd1333 62 if (serialmode == 7 && mainset == false) {mainset = true; myserial.printf("IP: %s \r\n", IP);}
mslade 1:84581acd1333 63
mslade 1:84581acd1333 64 //Update 2D array with data
mslade 1:84581acd1333 65 database[0][record] = ldrString; //Column 1: ldr data
mslade 1:84581acd1333 66 database[1][record] = tempString; //Column 2: temp data
mslade 1:84581acd1333 67 database[2][record] = presString; //Column 3: pressure data
mslade 1:84581acd1333 68 database[3][record] = Row1;
mslade 1:84581acd1333 69 database[4][record] = Row2;
mslade 1:84581acd1333 70 if (debugmode) {leds = 0;} //Turn off white led
mslade 1:84581acd1333 71 if (record > 119) {record = 0; data120 = true; } else { record += 1;} //Increment record counter
mslade 1:84581acd1333 72 mysem.release(); //Release thread.
mslade 0:1c898341428b 73 }
mslade 0:1c898341428b 74 }
mslade 0:1c898341428b 75
mslade 1:84581acd1333 76 void showrecord(){
mslade 1:84581acd1333 77 //This function is used to display the last 120 data entries on serial
mslade 1:84581acd1333 78
mslade 1:84581acd1333 79 //Don't display the data until there is 120 data entries.
mslade 1:84581acd1333 80 if (data120 == false) {myserial.printf("Not enough records. Please wait %d seconds. \r\n", 120-record); serialmode = 0; mainset = false;}
mslade 1:84581acd1333 81 else {
mslade 1:84581acd1333 82 for(int i=record; i < 120; i++) { //Displays all the recent values from current record to 120 (FIFO buffer)
mslade 1:84581acd1333 83 string response;
mslade 1:84581acd1333 84 response = "Time:" ; response += database[3][i]; //Add time
mslade 1:84581acd1333 85 response += " Date:"; response += database[4][i]; //Add date
mslade 1:84581acd1333 86 response += " LDR:" ; response += database[0][i]; //Add LDR value
mslade 1:84581acd1333 87 response += " Temp:"; response += database[1][i]; //Add Temp value
mslade 1:84581acd1333 88 response += " Pres:"; response += database[2][i]; //Add pressure value
mslade 1:84581acd1333 89 response += "\r\n"; //Line return
mslade 1:84581acd1333 90 myserial.printf(response.c_str()); //Display Time, LDR, Temp, Press
mslade 1:84581acd1333 91 }
mslade 1:84581acd1333 92 for(int i = 0; i < record; i++){ //displays all the recent values from 0 to record (FIFO buffer)
mslade 1:84581acd1333 93 string response;
mslade 1:84581acd1333 94 response = "Time:" ; response += database[3][i]; //Add time
mslade 1:84581acd1333 95 response += " Date:"; response += database[4][i]; //Add date
mslade 1:84581acd1333 96 response += " LDR:" ; response += database[0][i]; //Add LDR value
mslade 1:84581acd1333 97 response += " Temp:"; response += database[1][i]; //Add Temp value
mslade 1:84581acd1333 98 response += " Pres:"; response += database[2][i]; //Add pressure value
mslade 1:84581acd1333 99 response += "\r\n"; //Line return
mslade 1:84581acd1333 100 myserial.printf(response.c_str()); //Display Time, LDR, Temp, Press }
mslade 1:84581acd1333 101 }
mslade 1:84581acd1333 102 }
mslade 1:84581acd1333 103 }
mslade 1:84581acd1333 104 void LCDupdate (void const *name){
mslade 1:84581acd1333 105 //The purpose of this function is to update the LCD screen
mslade 1:84581acd1333 106 while (true) {
mslade 1:84581acd1333 107 mysem.wait();
mslade 1:84581acd1333 108 Thread::wait(50); //Wait 50ms
mslade 1:84581acd1333 109 if (SW3 == 1) { if (togPress == false) { if (lcdmode == 2) {lcdmode = 1;} else {lcdmode += 1;} togPress = true; mylcd.cls(); }
mslade 1:84581acd1333 110 } else { togPress = false;} //Toggle mode
mslade 1:84581acd1333 111 if (lcdmode == 1) { clockz(); } //Display time
mslade 1:84581acd1333 112 if (lcdmode == 2) { //Display live sensor data
mslade 1:84581acd1333 113 mylcd.locate(9,1); mylcd.printf("L:%s ", ldrString); //Display LDR value
mslade 1:84581acd1333 114 mylcd.locate(0,1); mylcd.printf("T:%s ", tempString); //Display temp value
mslade 1:84581acd1333 115 mylcd.locate(4,0); mylcd.printf("P:%s ", presString); //Display pressure value
mslade 1:84581acd1333 116 }
mslade 1:84581acd1333 117 mysem.release(); //Release thread
mslade 1:84581acd1333 118 }
mslade 1:84581acd1333 119 }
mslade 1:84581acd1333 120
mslade 0:1c898341428b 121
mslade 0:1c898341428b 122 void enet(void const *name)
mslade 1:84581acd1333 123 //The purpose of this function is to set up and transmit data via ethernet
mslade 0:1c898341428b 124 {
mslade 1:84581acd1333 125 EthernetInterface eth; //Configure an ethernet connection
mslade 1:84581acd1333 126 eth.set_network(IP, NETMASK, GATEWAY); //Configure network
mslade 1:84581acd1333 127 eth.connect(); //Connect ethernet
mslade 1:84581acd1333 128 TCPServer srv; //Socket for communication
mslade 1:84581acd1333 129 SocketAddress clt_addr; //Address of incoming connection
mslade 1:84581acd1333 130 srv.open(&eth); // Open the server on ethernet stack
mslade 1:84581acd1333 131 srv.bind(eth.get_ip_address(), 80); // Bind the HTTP port (TCP 80) to the server
mslade 1:84581acd1333 132 srv.listen(5); // Can handle 5 simultaneous connections
mslade 0:1c898341428b 133 while (true) {
mslade 0:1c898341428b 134 mysem.wait();
mslade 0:1c898341428b 135 using namespace std;
mslade 0:1c898341428b 136 TCPSocket clt_sock;
mslade 0:1c898341428b 137 srv.accept(&clt_sock, &clt_addr);
mslade 1:84581acd1333 138
mslade 1:84581acd1333 139 //This code sends the HTML website to the computer.
mslade 0:1c898341428b 140 string response;
mslade 0:1c898341428b 141 response = "<html> \r\n ";
mslade 0:1c898341428b 142 response += "<meta http-equiv=\"refresh\" content=\"1; url=http://10.0.0.10\">";
mslade 1:84581acd1333 143 response += "\r\n <h1 style=\"color:black; font-size: 200%; position: fixed; top:17.5%; left:38%;\"> ";
mslade 1:84581acd1333 144 response += Row1;
mslade 0:1c898341428b 145 response += "</h1> \r\n <h1 style=\"color:black; font-size: 200%; position: fixed; top:17.5%; left:55.5%;\">";
mslade 1:84581acd1333 146 response += Row2;
mslade 0:1c898341428b 147 response += "</h1> \r\n <h1 style=\"color:black; font-size: 400%; position: fixed; top:30%; left:46%;\">";
mslade 1:84581acd1333 148 response += tempString;
mslade 0:1c898341428b 149 response += "</h1> \r\n <h1 style=\"color:black; font-size: 400%; position: fixed; top:51%; left:46%;\">";
mslade 1:84581acd1333 150 response += ldrString;
mslade 0:1c898341428b 151 response += "</h1> \r\n <h1 style=\"color:black; font-size: 400%; position: fixed; top:72%; left:46%;\">";
mslade 1:84581acd1333 152 response += presString;
mslade 0:1c898341428b 153 response += "</h1> \r\n <body style=\"background-image:url(https://image.ibb.co/nyTj9w/pic2.png); background-size: 100% 100%;\"></body> ";
mslade 0:1c898341428b 154 response += "\r\n </html>";
mslade 0:1c898341428b 155 clt_sock.send(response.c_str(), response.size()+1);
mslade 1:84581acd1333 156 Thread::wait(samplerate); //Thread wait 10ms
mslade 1:84581acd1333 157 mysem.release(); //Release thread
mslade 1:84581acd1333 158 }
mslade 1:84581acd1333 159 }
mslade 1:84581acd1333 160 void serialin(void const *name){
mslade 1:84581acd1333 161 //The purpose of this function is to handle the serial communication
mslade 1:84581acd1333 162
mslade 1:84581acd1333 163 while (true) {
mslade 1:84581acd1333 164 mysem.wait();
mslade 1:84581acd1333 165 Thread::wait(1000); //Thread wait 1000ms
mslade 1:84581acd1333 166 myserial.scanf("%d", &serialcheck); //Wait for command from serial
mslade 1:84581acd1333 167 if (serialmode != 5 && serialcheck == 9) {serialmode = 0; mainset = false;} //if command is 9 return to main menu
mslade 1:84581acd1333 168 else if (serialmode == 0) {serialmode = serialcheck; mainset = false; myserial.printf("press 9 to return to main menu\r\n");}
mslade 1:84581acd1333 169 else if (serialmode == 4) { //if the mode is set samplerate:
mslade 1:84581acd1333 170 if (serialcheck == 1) {samplerate = 100; } //Set samplerate to 0.1s
mslade 1:84581acd1333 171 if (serialcheck == 2) {samplerate = 1000;} //Set samplerate to 1s
mslade 1:84581acd1333 172 if (serialcheck == 3) {samplerate = 5000;} //Set samplerate to 5s
mslade 1:84581acd1333 173 if (serialcheck == 4) {samplerate = 10000;} //Set samplerate to 10s
mslade 1:84581acd1333 174 if (serialcheck == 5) {samplerate = 15000;} //Set samplerate to 15s
mslade 1:84581acd1333 175 if (serialcheck == 6) {samplerate = 30000;} //Set samplerate to 30s
mslade 1:84581acd1333 176 if (serialcheck == 7) {samplerate = 60000;} //Set samplerate to 60s
mslade 1:84581acd1333 177 if (serialcheck < 8 && serialcheck > 0) {myserial.printf("Sample rate set to %dms \r\n", samplerate); serialmode = 0; mainset = false;}
mslade 1:84581acd1333 178 }
mslade 1:84581acd1333 179 if (serialmode == 5) { //if the mode is set date/time
mslade 1:84581acd1333 180 if (mainset == false) {datemode = 1; mainset = true; }
mslade 1:84581acd1333 181 if (datemode == 1) { myserial.printf(" Set year: "); datemode++;} //set year
mslade 1:84581acd1333 182 else if (datemode == 2) { myserial.printf("%d \r\n Set month: ",serialcheck); y = serialcheck; datemode++;} //set month
mslade 1:84581acd1333 183 else if (datemode == 3) { myserial.printf("%d \r\n Set day: ",serialcheck); mon = serialcheck; datemode++;} //set day
mslade 1:84581acd1333 184 else if (datemode == 4) { myserial.printf("%d \r\n Set hour: ",serialcheck); d = serialcheck; datemode++;} //set hour
mslade 1:84581acd1333 185 else if (datemode == 5) { myserial.printf("%d \r\n Set minute: ", serialcheck); h = serialcheck; datemode++;} //set minute
mslade 1:84581acd1333 186 else {myserial.printf("%d \r\nDate set to: %d/%d/%d %d:%d \r\n", serialcheck,d, mon, y, h, serialcheck); minu = serialcheck; serialmode = 0;set_time(SetDateTime(y, mon, d, h, minu)); mainset = false;}
mslade 1:84581acd1333 187 }
mslade 1:84581acd1333 188 mysem.release();
mslade 1:84581acd1333 189 }
mslade 1:84581acd1333 190 }
mslade 1:84581acd1333 191
mslade 1:84581acd1333 192 void interrupts(void const *name){
mslade 1:84581acd1333 193 //The purpose of this function is to wait for Interrupt-In's
mslade 1:84581acd1333 194 while (true) {
mslade 1:84581acd1333 195 mysem.wait();
mslade 1:84581acd1333 196 Thread::wait(40); //Thread wait 40ms
mslade 1:84581acd1333 197 SW1 = SWi1; //Set SW1
mslade 1:84581acd1333 198 SW2 = SWi2; //Set SW2
mslade 1:84581acd1333 199 SW3 = SWi3; //Set SW3
mslade 1:84581acd1333 200 mysem.release(); //Release thread
mslade 1:84581acd1333 201 }
mslade 1:84581acd1333 202 }
mslade 1:84581acd1333 203 void SDcard(void const *name){
mslade 1:84581acd1333 204 while (true) {
mslade 1:84581acd1333 205 mysem.wait();
mslade 1:84581acd1333 206 Thread::wait(samplerate);
mslade 1:84581acd1333 207 FILE* fp = fopen("/sd/test.txt","a"); //edit test.txt file
mslade 1:84581acd1333 208 string response;
mslade 1:84581acd1333 209 response = Row1; response += ","; //Add time
mslade 1:84581acd1333 210 response += Row2; response += ","; //Add date
mslade 1:84581acd1333 211 response += ldrString; response += ","; //Add ldr value
mslade 1:84581acd1333 212 response += tempString; response += ","; //Add temp value
mslade 1:84581acd1333 213 response += presString; response += "\r\n"; //Add pressure value
mslade 1:84581acd1333 214 fprintf(fp, response.c_str()); //Print response
mslade 1:84581acd1333 215 if (onBoardSwitch == 1) { //if switch is pressed start eject
mslade 1:84581acd1333 216 switchactive = true;
mslade 1:84581acd1333 217 }
mslade 1:84581acd1333 218 if (switchactive == true) {
mslade 1:84581acd1333 219 sd.deinit(); //eject SD
mslade 1:84581acd1333 220 }
mslade 1:84581acd1333 221 fclose(fp); //Close test.txt
mslade 0:1c898341428b 222 mysem.release();
mslade 0:1c898341428b 223 }
mslade 1:84581acd1333 224 }
mslade 1:84581acd1333 225 int SetDateTime(int year, int month, int day, int hour, int min)
mslade 1:84581acd1333 226 { //The purpose of this function is to set the date and time
mslade 1:84581acd1333 227 T.tm_year = year - 1900; //Set year
mslade 1:84581acd1333 228 T.tm_mon = month - 1; //Set month
mslade 1:84581acd1333 229 T.tm_mday = day; //Set day
mslade 1:84581acd1333 230 T.tm_hour = hour; //Set hour
mslade 1:84581acd1333 231 T.tm_min = minu; //Set minute
mslade 1:84581acd1333 232 T.tm_sec = 0; //Set second
mslade 1:84581acd1333 233 return (mktime(&T));
mslade 1:84581acd1333 234 }
mslade 1:84581acd1333 235
mslade 1:84581acd1333 236 void clockz() {
mslade 1:84581acd1333 237 //The purpose of this function is to set the time on the LCD
mslade 1:84581acd1333 238 if ((SW1 == 1) && (SW2 == 1)) { //If both buttons pressed
mslade 1:84581acd1333 239 if (Pressed == false) { //if first time:
mslade 1:84581acd1333 240 EditTimeParam = not EditTimeParam; //Toggle mode
mslade 1:84581acd1333 241 if (EditTimeParam == false) { set_time(SetDateTime(y, mon, d, h, minu)); } //Set Datetime
mslade 1:84581acd1333 242 mylcd.cls(); //Clear LCD screen
mslade 1:84581acd1333 243 Pressed = true;
mslade 1:84581acd1333 244 }
mslade 1:84581acd1333 245 }
mslade 1:84581acd1333 246 else{ Pressed = false; }
mslade 1:84581acd1333 247 if (EditTimeParam == true) {
mslade 1:84581acd1333 248 if (SW1 == 1) { //if switch is pressed
mslade 1:84581acd1333 249 if (Pressed1 == false) {
mslade 1:84581acd1333 250 TimeParam++; //increment TimeParam for switch case
mslade 1:84581acd1333 251 mylcd.cls(); //Clear LCD screen
mslade 1:84581acd1333 252 Pressed1 = true;
mslade 1:84581acd1333 253 if (TimeParam > 4) {TimeParam = 0;}
mslade 1:84581acd1333 254 }
mslade 1:84581acd1333 255 }
mslade 1:84581acd1333 256 else {
mslade 1:84581acd1333 257 Pressed1 = false;
mslade 1:84581acd1333 258 }
mslade 1:84581acd1333 259 switch (TimeParam) {
mslade 1:84581acd1333 260 case 0: //Year
mslade 1:84581acd1333 261 if (SW2 == 1) { if (yearPress == false) { y++; yearPress = true; } } else { yearPress = false; } //Increment year
mslade 1:84581acd1333 262 if (y > 2030) { y = 2015; mylcd.cls(); } //If upper limit hit, reset to lower limit
mslade 1:84581acd1333 263 mylcd.locate(0, 0); mylcd.printf("Year: %d\n", y); //Display year
mslade 1:84581acd1333 264 break;
mslade 1:84581acd1333 265 case 1: //Month
mslade 1:84581acd1333 266 if (SW2 == 1) { if (monPress == false) { mon++; monPress = true; } } else { monPress = false; } //Increment month
mslade 1:84581acd1333 267 if (mon > 12) { mon = 1; mylcd.cls(); } //if upper limit hit, reset to lower limit
mslade 1:84581acd1333 268 mylcd.locate(0, 0); mylcd.printf("Month: %d\n", mon); //Display month
mslade 1:84581acd1333 269 break;
mslade 1:84581acd1333 270 case 2: //Day
mslade 1:84581acd1333 271 if (SW2 == 1) { if (dayPress == false) { d++; dayPress = true; } } else { dayPress = false; } //Increment day
mslade 1:84581acd1333 272 if ((mon == (4 || 6 || 9 || 11)) && (d > 30)) { d = 1; mylcd.cls(); } else if ((mon == 2) && (d > 28)) { d = 0; mylcd.cls(); } else if (d > 31) { d = 0; mylcd.cls(); }
mslade 1:84581acd1333 273 mylcd.locate(0, 0); mylcd.printf("Day: %d\n", d); //Display day
mslade 1:84581acd1333 274 break;
mslade 1:84581acd1333 275 case 3: //Hour
mslade 1:84581acd1333 276 if (SW2 == 1) { if (hourPress == false) { h++; hourPress = true; } } else { hourPress = false; } //Increment hour
mslade 1:84581acd1333 277 if (h > 23) { h = 0; mylcd.cls(); } //if upper limit hit, reset to lower limit
mslade 1:84581acd1333 278 mylcd.locate(0, 0); mylcd.printf("Hour: %d\n", h); //Display hour
mslade 1:84581acd1333 279 break;
mslade 1:84581acd1333 280 case 4: //Minute
mslade 1:84581acd1333 281 if (SW2 == 1) { if (minPress == false) { minu++; minPress = true; } } else { minPress = false; } //Increment minute
mslade 1:84581acd1333 282 if (minu > 59) { minu = 0; mylcd.cls(); } //if upper limit hit, reset to lower limit
mslade 1:84581acd1333 283 mylcd.locate(0, 0); mylcd.printf("Minute: %d\n", minu); //Display minute
mslade 1:84581acd1333 284 break;
mslade 1:84581acd1333 285 }
mslade 1:84581acd1333 286 }
mslade 1:84581acd1333 287 else {
mslade 1:84581acd1333 288 mylcd.locate(0, 0); mylcd.printf("%s", Row1); //Print Time on LCD, row 1
mslade 1:84581acd1333 289 mylcd.locate(0, 1); mylcd.printf("%s", Row2); //Print Date on LCD, row 2
mslade 1:84581acd1333 290 }
mslade 1:84581acd1333 291 }
mslade 1:84581acd1333 292
mslade 1:84581acd1333 293 void serialmenu() {
mslade 1:84581acd1333 294 //The purpose of this function is to print the serial menu
mslade 1:84581acd1333 295 myserial.printf("Welcome to Group Z ELEC351 Coursework. Press 9 to start. \r\n");
mslade 1:84581acd1333 296 myserial.printf("Please select (type in the number) an option: \r\n");
mslade 1:84581acd1333 297 myserial.printf("1. Show live sensor data \r\n");
mslade 1:84581acd1333 298 myserial.printf("2. Show old sensor data \r\n");
mslade 1:84581acd1333 299 myserial.printf("3. delete all sensor data \r\n");
mslade 1:84581acd1333 300 myserial.printf("4. Select sampling rate \r\n");
mslade 1:84581acd1333 301 myserial.printf("5. Set time/date \r\n");
mslade 1:84581acd1333 302 myserial.printf("6. Toggle debug \r\n");
mslade 1:84581acd1333 303 myserial.printf("7. Show IP address \r\n");
mslade 1:84581acd1333 304 }
mslade 1:84581acd1333 305 void ratelimiter() {
mslade 1:84581acd1333 306 //The purpose of this function is to print the samplerate options to the serial
mslade 1:84581acd1333 307 myserial.printf("Please select (type in the number) a sample rate: \r\n");
mslade 1:84581acd1333 308 myserial.printf("1. 0.1s \r\n");
mslade 1:84581acd1333 309 myserial.printf("2. 1s \r\n");
mslade 1:84581acd1333 310 myserial.printf("3. 5s \r\n");
mslade 1:84581acd1333 311 myserial.printf("4. 10s \r\n");
mslade 1:84581acd1333 312 myserial.printf("5. 15s \r\n");
mslade 1:84581acd1333 313 myserial.printf("6. 30s \r\n");
mslade 1:84581acd1333 314 myserial.printf("7. 60s \r\n");
mslade 1:84581acd1333 315 }
mslade 1:84581acd1333 316 int main(){
mslade 1:84581acd1333 317 //The purpose of this function is to be the main code to run the threads.
mslade 1:84581acd1333 318 myserial.baud(115200); //Set serial speed to 115200
mslade 1:84581acd1333 319 mylcd.cls(); //Clear LCD
mslade 1:84581acd1333 320 thread1.start(callback(enet, (void *) "Thread1\r\n")); // Start Ethernet thread
mslade 1:84581acd1333 321 thread2.start(callback(sensors, (void *) "Thread2\r\n")); // Start sensors thread
mslade 1:84581acd1333 322 thread3.start(callback(serialin,(void *) "Thread3\r\n")); // Start Serialin thread
mslade 1:84581acd1333 323 thread4.start(callback(interrupts,(void *) "Thread4\r\n")); // Start interrupts thread
mslade 1:84581acd1333 324 thread5.start(callback(LCDupdate,(void *) "Thread5\r\n")); // Start LCDupdate thread
mslade 1:84581acd1333 325 thread6.start(callback(SDcard,(void *) "Thread6\r\n")); // Start SDcard thread
mslade 1:84581acd1333 326 set_time(SetDateTime(y, mon, d, h, minu)); //Set DateTime
mslade 0:1c898341428b 327 }