![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tapton School Project to monitor and log SEN students physiological condition using GSR (conductivity) & Heart Rate and displaying output and logging the data to an SD card
main.cpp@0:0e26bf847b57, 2018-02-09 (annotated)
- Committer:
- raheel123
- Date:
- Fri Feb 09 08:34:23 2018 +0000
- Revision:
- 0:0e26bf847b57
Tapton school SENtinel project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
raheel123 | 0:0e26bf847b57 | 1 | /**************************************************************************************/ |
raheel123 | 0:0e26bf847b57 | 2 | /**************************************************************************************/ |
raheel123 | 0:0e26bf847b57 | 3 | /*SMARTGPU2 intelligent embedded graphics processor unit |
raheel123 | 0:0e26bf847b57 | 4 | those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset |
raheel123 | 0:0e26bf847b57 | 5 | Board: |
raheel123 | 0:0e26bf847b57 | 6 | http://www.vizictechnologies.com/ |
raheel123 | 0:0e26bf847b57 | 7 | |
raheel123 | 0:0e26bf847b57 | 8 | www.vizictechnologies.com |
raheel123 | 0:0e26bf847b57 | 9 | Vizic Technologies copyright 2014 */ |
raheel123 | 0:0e26bf847b57 | 10 | /**************************************************************************************/ |
raheel123 | 0:0e26bf847b57 | 11 | /**************************************************************************************/ |
raheel123 | 0:0e26bf847b57 | 12 | |
raheel123 | 0:0e26bf847b57 | 13 | #include "mbed.h" |
raheel123 | 0:0e26bf847b57 | 14 | #include "SMARTGPU2.h" |
raheel123 | 0:0e26bf847b57 | 15 | #include "DFRobot_Heartrate.h" |
raheel123 | 0:0e26bf847b57 | 16 | #include "inttypes.h" |
raheel123 | 0:0e26bf847b57 | 17 | AnalogIn hrm (p16); |
raheel123 | 0:0e26bf847b57 | 18 | DigitalIn DigHRM (p21); |
raheel123 | 0:0e26bf847b57 | 19 | AnalogIn gsr(p19); // alalogue input pin for the galvanic skin response sensor |
raheel123 | 0:0e26bf847b57 | 20 | |
raheel123 | 0:0e26bf847b57 | 21 | |
raheel123 | 0:0e26bf847b57 | 22 | Serial pc(USBTX, USBRX); // pc's usb tx, rx |
raheel123 | 0:0e26bf847b57 | 23 | |
raheel123 | 0:0e26bf847b57 | 24 | DigitalOut led_1(LED1); |
raheel123 | 0:0e26bf847b57 | 25 | DigitalOut led_2(LED2); |
raheel123 | 0:0e26bf847b57 | 26 | DigitalOut led_3(LED3); |
raheel123 | 0:0e26bf847b57 | 27 | DigitalOut led_4(LED4); |
raheel123 | 0:0e26bf847b57 | 28 | int rateValue; |
raheel123 | 0:0e26bf847b57 | 29 | //const char rateVal = &rateValue; |
raheel123 | 0:0e26bf847b57 | 30 | DFRobot_Heartrate heartrate(DIGITAL_MODE); |
raheel123 | 0:0e26bf847b57 | 31 | SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd" |
raheel123 | 0:0e26bf847b57 | 32 | |
raheel123 | 0:0e26bf847b57 | 33 | TIME timeRTC; |
raheel123 | 0:0e26bf847b57 | 34 | STATE stateRTC; |
raheel123 | 0:0e26bf847b57 | 35 | /***************************************************/ |
raheel123 | 0:0e26bf847b57 | 36 | /***************************************************/ |
raheel123 | 0:0e26bf847b57 | 37 | void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board |
raheel123 | 0:0e26bf847b57 | 38 | lcd.reset(); //physically reset SMARTGPU2 |
raheel123 | 0:0e26bf847b57 | 39 | lcd.start(); //initialize the SMARTGPU2 processor |
raheel123 | 0:0e26bf847b57 | 40 | } |
raheel123 | 0:0e26bf847b57 | 41 | |
raheel123 | 0:0e26bf847b57 | 42 | float gsrValue = 0,gsrbaseline = 0,hrmValue = 0,hrmbaseline = 0; |
raheel123 | 0:0e26bf847b57 | 43 | |
raheel123 | 0:0e26bf847b57 | 44 | void Get_gsrBaseline(void) |
raheel123 | 0:0e26bf847b57 | 45 | { |
raheel123 | 0:0e26bf847b57 | 46 | double gsrsum = 0; |
raheel123 | 0:0e26bf847b57 | 47 | wait(1); |
raheel123 | 0:0e26bf847b57 | 48 | for(int i=0; i<500; i++) { |
raheel123 | 0:0e26bf847b57 | 49 | gsrValue = gsr; |
raheel123 | 0:0e26bf847b57 | 50 | gsrsum += gsrValue; |
raheel123 | 0:0e26bf847b57 | 51 | wait(0.005); |
raheel123 | 0:0e26bf847b57 | 52 | } |
raheel123 | 0:0e26bf847b57 | 53 | gsrbaseline = gsrsum/500; |
raheel123 | 0:0e26bf847b57 | 54 | } |
raheel123 | 0:0e26bf847b57 | 55 | |
raheel123 | 0:0e26bf847b57 | 56 | // calculate hrmbaseline to compare against |
raheel123 | 0:0e26bf847b57 | 57 | void Get_hrmBaseline(void) |
raheel123 | 0:0e26bf847b57 | 58 | { |
raheel123 | 0:0e26bf847b57 | 59 | double hrmsum = 0; |
raheel123 | 0:0e26bf847b57 | 60 | wait(1); |
raheel123 | 0:0e26bf847b57 | 61 | for(int i=0; i<500; i++) { |
raheel123 | 0:0e26bf847b57 | 62 | hrmValue = hrm; |
raheel123 | 0:0e26bf847b57 | 63 | hrmsum += hrmValue; |
raheel123 | 0:0e26bf847b57 | 64 | |
raheel123 | 0:0e26bf847b57 | 65 | wait(0.005); |
raheel123 | 0:0e26bf847b57 | 66 | } |
raheel123 | 0:0e26bf847b57 | 67 | hrmbaseline = hrmsum/500; |
raheel123 | 0:0e26bf847b57 | 68 | } |
raheel123 | 0:0e26bf847b57 | 69 | |
raheel123 | 0:0e26bf847b57 | 70 | FILERESULT fres; //create the variable that will store all SMARTGPU2 commands responses |
raheel123 | 0:0e26bf847b57 | 71 | int sdok; |
raheel123 | 0:0e26bf847b57 | 72 | |
raheel123 | 0:0e26bf847b57 | 73 | unsigned int row=10; |
raheel123 | 0:0e26bf847b57 | 74 | |
raheel123 | 0:0e26bf847b57 | 75 | //function that checks if the SD card operation had a problem |
raheel123 | 0:0e26bf847b57 | 76 | void die(unsigned char response){ //if the response is different than OK, print and wait for 3 seconds |
raheel123 | 0:0e26bf847b57 | 77 | // NUMBEROFBYTES charsPrint; |
raheel123 | 0:0e26bf847b57 | 78 | pc.printf("%d\r\n",response); //write to the USB PC if there is a problem |
raheel123 | 0:0e26bf847b57 | 79 | if(response!=F_OK){ |
raheel123 | 0:0e26bf847b57 | 80 | pc.printf("Error on microSD... \r\n"); |
raheel123 | 0:0e26bf847b57 | 81 | wait(3); |
raheel123 | 0:0e26bf847b57 | 82 | // while(1); |
raheel123 | 0:0e26bf847b57 | 83 | } |
raheel123 | 0:0e26bf847b57 | 84 | sdok=1; |
raheel123 | 0:0e26bf847b57 | 85 | } |
raheel123 | 0:0e26bf847b57 | 86 | |
raheel123 | 0:0e26bf847b57 | 87 | |
raheel123 | 0:0e26bf847b57 | 88 | int main() { //start of main program ******** |
raheel123 | 0:0e26bf847b57 | 89 | |
raheel123 | 0:0e26bf847b57 | 90 | SMARTGPUREPLY res; // responses from GPU |
raheel123 | 0:0e26bf847b57 | 91 | POINT point; |
raheel123 | 0:0e26bf847b57 | 92 | |
raheel123 | 0:0e26bf847b57 | 93 | int but1; // button pressed variable |
raheel123 | 0:0e26bf847b57 | 94 | pc.baud(9600); |
raheel123 | 0:0e26bf847b57 | 95 | |
raheel123 | 0:0e26bf847b57 | 96 | initializeSmartGPU2(); //Init communication with SmartGPU2 board |
raheel123 | 0:0e26bf847b57 | 97 | |
raheel123 | 0:0e26bf847b57 | 98 | lcd.baudChange(BAUD6); //set a fast baud! for fast drawing |
raheel123 | 0:0e26bf847b57 | 99 | |
raheel123 | 0:0e26bf847b57 | 100 | res = lcd.setupRTC(&stateRTC); // start the SmartGPU2 Real Time Clock RTC |
raheel123 | 0:0e26bf847b57 | 101 | |
raheel123 | 0:0e26bf847b57 | 102 | NUMBEROFBYTES bytes; // for use in text string call |
raheel123 | 0:0e26bf847b57 | 103 | |
raheel123 | 0:0e26bf847b57 | 104 | float gsrValue = 0,gsrbaseline = 0,aHRMvalue = 0,dHRMvalue = 0; |
raheel123 | 0:0e26bf847b57 | 105 | |
raheel123 | 0:0e26bf847b57 | 106 | while(1) |
raheel123 | 0:0e26bf847b57 | 107 | { // set up a loop to keep endless operation and changes to user operation |
raheel123 | 0:0e26bf847b57 | 108 | pc.printf("Start of Main\r\n"); |
raheel123 | 0:0e26bf847b57 | 109 | but1 = 0; |
raheel123 | 0:0e26bf847b57 | 110 | gsrbaseline = gsr; |
raheel123 | 0:0e26bf847b57 | 111 | lcd.erase(); |
raheel123 | 0:0e26bf847b57 | 112 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 113 | lcd.setTextSize(FONT1); |
raheel123 | 0:0e26bf847b57 | 114 | |
raheel123 | 0:0e26bf847b57 | 115 | //draw the object button1 and button2 |
raheel123 | 0:0e26bf847b57 | 116 | lcd.objButton(10, 170, 150, 220, DESELECTED, "Change?"); |
raheel123 | 0:0e26bf847b57 | 117 | lcd.objButton(170, 170, 309, 220, DESELECTED, "Continue"); |
raheel123 | 0:0e26bf847b57 | 118 | |
raheel123 | 0:0e26bf847b57 | 119 | res = lcd.getRTCTimeDate(&timeRTC); |
raheel123 | 0:0e26bf847b57 | 120 | lcd.string(70,40,300,60,"Hour Minutes Seconds", &bytes); |
raheel123 | 0:0e26bf847b57 | 121 | lcd.string(0,60,69,80,"Time:", &bytes); |
raheel123 | 0:0e26bf847b57 | 122 | lcd.string(70,100,300,120,"Day Month Year", &bytes); |
raheel123 | 0:0e26bf847b57 | 123 | lcd.string(0,120,100,140,"Date:", &bytes); |
raheel123 | 0:0e26bf847b57 | 124 | |
raheel123 | 0:0e26bf847b57 | 125 | lcd.printNumber(85,60, timeRTC.hour); |
raheel123 | 0:0e26bf847b57 | 126 | lcd.printNumber(130,60, timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 127 | lcd.printNumber(190,60, timeRTC.second); |
raheel123 | 0:0e26bf847b57 | 128 | lcd.printNumber(85,120, timeRTC.day); |
raheel123 | 0:0e26bf847b57 | 129 | lcd.printNumber(130,120, timeRTC.month); |
raheel123 | 0:0e26bf847b57 | 130 | lcd.printNumber(190,120, timeRTC.year); |
raheel123 | 0:0e26bf847b57 | 131 | |
raheel123 | 0:0e26bf847b57 | 132 | lcd.setTextColour(GREEN); |
raheel123 | 0:0e26bf847b57 | 133 | lcd.string(0,0,300,20,"Press Change? to set the time", &bytes); |
raheel123 | 0:0e26bf847b57 | 134 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 135 | pc.printf("TEST\r\n");//debug |
raheel123 | 0:0e26bf847b57 | 136 | but1=0; // prepare for catching a button press |
raheel123 | 0:0e26bf847b57 | 137 | led_2=0; //debug |
raheel123 | 0:0e26bf847b57 | 138 | while (but1 == 0) //wait for button press loop |
raheel123 | 0:0e26bf847b57 | 139 | { |
raheel123 | 0:0e26bf847b57 | 140 | //ask for a touch |
raheel123 | 0:0e26bf847b57 | 141 | if(lcd.touchScreen(&point)==VALID) |
raheel123 | 0:0e26bf847b57 | 142 | { //if a touch on screen is valid check which button |
raheel123 | 0:0e26bf847b57 | 143 | if(point.y>170 && point.y<220 && point.x<160) |
raheel123 | 0:0e26bf847b57 | 144 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 145 | lcd.objButton(10, 170, 150, 220, SELECTED, "Change Time?"); |
raheel123 | 0:0e26bf847b57 | 146 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 147 | lcd.objButton(10, 170, 150, 220, DESELECTED, "Change Time?"); |
raheel123 | 0:0e26bf847b57 | 148 | pc.printf("change time button pressed\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 149 | timeRTC.hour = 8; // SET DATE AND TIME VALUES HERE ONCE |
raheel123 | 0:0e26bf847b57 | 150 | timeRTC.minute = 45; |
raheel123 | 0:0e26bf847b57 | 151 | timeRTC.second = 1; |
raheel123 | 0:0e26bf847b57 | 152 | timeRTC.day = 8; |
raheel123 | 0:0e26bf847b57 | 153 | timeRTC.month = 2; |
raheel123 | 0:0e26bf847b57 | 154 | timeRTC.year = 2018; |
raheel123 | 0:0e26bf847b57 | 155 | res = lcd.setRTCTimeDate(&timeRTC); // send the above values to the RTC |
raheel123 | 0:0e26bf847b57 | 156 | wait(2); |
raheel123 | 0:0e26bf847b57 | 157 | res = lcd.getRTCTimeDate(&timeRTC); // get the RTC values back |
raheel123 | 0:0e26bf847b57 | 158 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 159 | lcd.drawRectangle(200, 0, 318, 20, BLACK, FILL); // date refresh |
raheel123 | 0:0e26bf847b57 | 160 | lcd.drawRectangle(85, 60, 300, 80, BLACK, FILL); //time refresh |
raheel123 | 0:0e26bf847b57 | 161 | lcd.drawRectangle(85, 120, 300, 110, BLACK, FILL); //clears the area of screen with numbers so not to overwrite causing blurred numbers |
raheel123 | 0:0e26bf847b57 | 162 | lcd.printNumber(85,60, timeRTC.hour); |
raheel123 | 0:0e26bf847b57 | 163 | lcd.printNumber(130,60, timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 164 | lcd.printNumber(190,60, timeRTC.second); |
raheel123 | 0:0e26bf847b57 | 165 | lcd.printNumber(85,120, timeRTC.day); |
raheel123 | 0:0e26bf847b57 | 166 | lcd.printNumber(130,120, timeRTC.month); |
raheel123 | 0:0e26bf847b57 | 167 | lcd.printNumber(190,120, timeRTC.year); |
raheel123 | 0:0e26bf847b57 | 168 | lcd.drawRectangle(0, 0, 300, 20, BLACK, FILL); // date refresh |
raheel123 | 0:0e26bf847b57 | 169 | lcd.string(0,0,300,20,"OK new time set from storred values", &bytes); |
raheel123 | 0:0e26bf847b57 | 170 | wait(3);// display for 2 seconds |
raheel123 | 0:0e26bf847b57 | 171 | led_2=1; |
raheel123 | 0:0e26bf847b57 | 172 | but1 = 1; // button was pressed so set var to get out of this button press loop |
raheel123 | 0:0e26bf847b57 | 173 | } //end of Button 1 pressed IF |
raheel123 | 0:0e26bf847b57 | 174 | |
raheel123 | 0:0e26bf847b57 | 175 | //IF BUTTON2 |
raheel123 | 0:0e26bf847b57 | 176 | if(point.y>170 && point.y<220 && point.x>160) |
raheel123 | 0:0e26bf847b57 | 177 | { //if the touch on button2 draw the object button2 as SELECTED |
raheel123 | 0:0e26bf847b57 | 178 | lcd.objButton(170, 170, 309, 220, SELECTED, "Continue"); |
raheel123 | 0:0e26bf847b57 | 179 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 180 | lcd.objButton(170, 170, 309, 220, DESELECTED, "Continue"); |
raheel123 | 0:0e26bf847b57 | 181 | but1 = 1;// button was pressed so set var to get out of thi sbutton press loop |
raheel123 | 0:0e26bf847b57 | 182 | pc.printf("continue button pressed\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 183 | }//end of Button 2 pressed IF |
raheel123 | 0:0e26bf847b57 | 184 | } // end of has a valid screen touch been made IF |
raheel123 | 0:0e26bf847b57 | 185 | } //end of second wait for button press while statement |
raheel123 | 0:0e26bf847b57 | 186 | |
raheel123 | 0:0e26bf847b57 | 187 | but1=0; //reset button pressed var |
raheel123 | 0:0e26bf847b57 | 188 | int candidate=0; //set up a var to track which candidate to be monitored |
raheel123 | 0:0e26bf847b57 | 189 | lcd.erase(); //clear the screen |
raheel123 | 0:0e26bf847b57 | 190 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 191 | |
raheel123 | 0:0e26bf847b57 | 192 | //draw the object button1 through button4 for Candidate selection |
raheel123 | 0:0e26bf847b57 | 193 | lcd.string(0,0,300,20,"Select the Candidate to be monitored", &bytes); |
raheel123 | 0:0e26bf847b57 | 194 | lcd.objButton(10, 30, 200, 60, DESELECTED, "Candidate 1"); |
raheel123 | 0:0e26bf847b57 | 195 | lcd.objButton(10, 85, 200, 120, DESELECTED, "Candidate 2"); |
raheel123 | 0:0e26bf847b57 | 196 | lcd.objButton(10, 145, 200, 180, DESELECTED, "Candidate 3"); |
raheel123 | 0:0e26bf847b57 | 197 | lcd.objButton(10, 205, 200, 238, DESELECTED, "Candidate 4"); |
raheel123 | 0:0e26bf847b57 | 198 | |
raheel123 | 0:0e26bf847b57 | 199 | while (but1 == 0) //wait for button press loop |
raheel123 | 0:0e26bf847b57 | 200 | { |
raheel123 | 0:0e26bf847b57 | 201 | //pc.printf("endless time loop\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 202 | led_4=!led_4; //debug |
raheel123 | 0:0e26bf847b57 | 203 | if(lcd.touchScreen(&point)==VALID) |
raheel123 | 0:0e26bf847b57 | 204 | { //if a touch on screen is valid check which button |
raheel123 | 0:0e26bf847b57 | 205 | if(point.y>30 && point.y<60 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 206 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 207 | lcd.objButton(10, 30, 200, 60, SELECTED, "Candidate 1"); |
raheel123 | 0:0e26bf847b57 | 208 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 209 | lcd.objButton(10, 30, 200, 60, DESELECTED, "Candidate 1"); |
raheel123 | 0:0e26bf847b57 | 210 | pc.printf("Candidate 1\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 211 | but1=1; |
raheel123 | 0:0e26bf847b57 | 212 | candidate=1; |
raheel123 | 0:0e26bf847b57 | 213 | }// end of if button 1 pressed |
raheel123 | 0:0e26bf847b57 | 214 | |
raheel123 | 0:0e26bf847b57 | 215 | if(point.y>85 && point.y<120 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 216 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 217 | lcd.objButton(10, 85, 200, 120, SELECTED, "Candidate 2"); |
raheel123 | 0:0e26bf847b57 | 218 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 219 | lcd.objButton(10, 85, 200, 120, DESELECTED, "Candidate 2"); |
raheel123 | 0:0e26bf847b57 | 220 | pc.printf("Candidate 2\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 221 | but1=1; |
raheel123 | 0:0e26bf847b57 | 222 | candidate=2; |
raheel123 | 0:0e26bf847b57 | 223 | }// end of if button 2 pressed |
raheel123 | 0:0e26bf847b57 | 224 | |
raheel123 | 0:0e26bf847b57 | 225 | if(point.y>145 && point.y<180 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 226 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 227 | lcd.objButton(10, 145, 200, 180, SELECTED, "Candidate 3"); |
raheel123 | 0:0e26bf847b57 | 228 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 229 | lcd.objButton(10, 145, 200, 180, DESELECTED, "Candidate 3"); |
raheel123 | 0:0e26bf847b57 | 230 | pc.printf("Candidate 3\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 231 | but1=1; |
raheel123 | 0:0e26bf847b57 | 232 | candidate=3; |
raheel123 | 0:0e26bf847b57 | 233 | }// end of if button 3 pressed |
raheel123 | 0:0e26bf847b57 | 234 | |
raheel123 | 0:0e26bf847b57 | 235 | if(point.y>205 && point.y<238 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 236 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 237 | lcd.objButton(10, 205, 200, 238, SELECTED, "Candidate 4"); |
raheel123 | 0:0e26bf847b57 | 238 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 239 | lcd.objButton(10, 205, 200, 238, DESELECTED, "Candidate 4"); |
raheel123 | 0:0e26bf847b57 | 240 | pc.printf("Candidate 4\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 241 | but1=1; |
raheel123 | 0:0e26bf847b57 | 242 | candidate=4; |
raheel123 | 0:0e26bf847b57 | 243 | }// end of if button 4 pressed |
raheel123 | 0:0e26bf847b57 | 244 | }// end of if screen touched |
raheel123 | 0:0e26bf847b57 | 245 | } //end of the button press while |
raheel123 | 0:0e26bf847b57 | 246 | |
raheel123 | 0:0e26bf847b57 | 247 | wait(1); |
raheel123 | 0:0e26bf847b57 | 248 | lcd.erase(); //clear the screen |
raheel123 | 0:0e26bf847b57 | 249 | lcd.setTextColour(CYAN); |
raheel123 | 0:0e26bf847b57 | 250 | lcd.setTextSize(FONT1); |
raheel123 | 0:0e26bf847b57 | 251 | if (candidate==0)lcd.string(0,0,300,20,"NO Candidate selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 252 | if (candidate==1)lcd.string(0,0,300,20,"Candidate 1 selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 253 | if (candidate==2)lcd.string(0,0,300,20,"Candidate 2 selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 254 | if (candidate==3)lcd.string(0,0,300,20,"Candidate 3 selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 255 | if (candidate==4)lcd.string(0,0,300,20,"Candidate 4 selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 256 | wait(1); |
raheel123 | 0:0e26bf847b57 | 257 | sdok=0; |
raheel123 | 0:0e26bf847b57 | 258 | |
raheel123 | 0:0e26bf847b57 | 259 | |
raheel123 | 0:0e26bf847b57 | 260 | unsigned int dirs=0, files=0, sdcardavail=0; |
raheel123 | 0:0e26bf847b57 | 261 | NUMBEROFBYTES charsPrinted; |
raheel123 | 0:0e26bf847b57 | 262 | |
raheel123 | 0:0e26bf847b57 | 263 | unsigned char response; |
raheel123 | 0:0e26bf847b57 | 264 | |
raheel123 | 0:0e26bf847b57 | 265 | fres=lcd.SDFgetList(&dirs,&files); //obtain dirs and files |
raheel123 | 0:0e26bf847b57 | 266 | die(fres); |
raheel123 | 0:0e26bf847b57 | 267 | if(sdok==1) |
raheel123 | 0:0e26bf847b57 | 268 | {//if the SD card is there and ok list the directory contents |
raheel123 | 0:0e26bf847b57 | 269 | pc.printf("SD card is there\r\n"); |
raheel123 | 0:0e26bf847b57 | 270 | sdcardavail=1; // set to determine if user given choice to save session to SD card |
raheel123 | 0:0e26bf847b57 | 271 | } //end of if statement to check if SD disc there and ok |
raheel123 | 0:0e26bf847b57 | 272 | wait(1); |
raheel123 | 0:0e26bf847b57 | 273 | |
raheel123 | 0:0e26bf847b57 | 274 | int storetosd=0; //set up a var to track if seesion to be saved to disc if so at what intervals |
raheel123 | 0:0e26bf847b57 | 275 | |
raheel123 | 0:0e26bf847b57 | 276 | if(sdcardavail==1) |
raheel123 | 0:0e26bf847b57 | 277 | { //only give these options if a SD card is available and ok |
raheel123 | 0:0e26bf847b57 | 278 | but1=0; //reset button pressed var |
raheel123 | 0:0e26bf847b57 | 279 | lcd.erase(); //clear the screen |
raheel123 | 0:0e26bf847b57 | 280 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 281 | //draw the object button1 through button4 for save to disc option selection |
raheel123 | 0:0e26bf847b57 | 282 | lcd.string(0,0,315,20,"Select if session to be saved to disc, if so, select interval required", &bytes); |
raheel123 | 0:0e26bf847b57 | 283 | lcd.objButton(10, 30, 200, 60, DESELECTED, "Don't Save"); |
raheel123 | 0:0e26bf847b57 | 284 | lcd.objButton(10, 85, 200, 120, DESELECTED, "Save, 1 minute"); |
raheel123 | 0:0e26bf847b57 | 285 | lcd.objButton(10, 145, 200, 180, DESELECTED, "Save, 15 minutes"); |
raheel123 | 0:0e26bf847b57 | 286 | lcd.objButton(10, 205, 200, 238, DESELECTED, "Save, 30 minutes"); |
raheel123 | 0:0e26bf847b57 | 287 | |
raheel123 | 0:0e26bf847b57 | 288 | while(but1 == 0) //wait for button press loop |
raheel123 | 0:0e26bf847b57 | 289 | { |
raheel123 | 0:0e26bf847b57 | 290 | //pc.printf("endless time loop\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 291 | led_4=!led_4; //debug |
raheel123 | 0:0e26bf847b57 | 292 | if(lcd.touchScreen(&point)==VALID) |
raheel123 | 0:0e26bf847b57 | 293 | { //if a touch on screen is valid check which button |
raheel123 | 0:0e26bf847b57 | 294 | if(point.y>30 && point.y<60 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 295 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 296 | lcd.objButton(10, 30, 200, 60, SELECTED, "Don't Save"); |
raheel123 | 0:0e26bf847b57 | 297 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 298 | lcd.objButton(10, 30, 200, 60, DESELECTED, "Don't Save"); |
raheel123 | 0:0e26bf847b57 | 299 | pc.printf("Don't Save\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 300 | but1=1; |
raheel123 | 0:0e26bf847b57 | 301 | storetosd=1; |
raheel123 | 0:0e26bf847b57 | 302 | }// end of if button 1 pressed |
raheel123 | 0:0e26bf847b57 | 303 | |
raheel123 | 0:0e26bf847b57 | 304 | if(point.y>85 && point.y<120 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 305 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 306 | lcd.objButton(10, 85, 200, 120, SELECTED, "Save, 1 minute"); |
raheel123 | 0:0e26bf847b57 | 307 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 308 | lcd.objButton(10, 85, 200, 120, DESELECTED, "Save, 1 minute"); |
raheel123 | 0:0e26bf847b57 | 309 | pc.printf("Save 1 minute\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 310 | but1=1; |
raheel123 | 0:0e26bf847b57 | 311 | storetosd=2; |
raheel123 | 0:0e26bf847b57 | 312 | }// end of if button 2 pressed |
raheel123 | 0:0e26bf847b57 | 313 | |
raheel123 | 0:0e26bf847b57 | 314 | if(point.y>145 && point.y<180 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 315 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 316 | lcd.objButton(10, 145, 200, 180, SELECTED, "Save, 15 minutes"); |
raheel123 | 0:0e26bf847b57 | 317 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 318 | lcd.objButton(10, 145, 200, 180, DESELECTED, "Save, 15 minutes"); |
raheel123 | 0:0e26bf847b57 | 319 | pc.printf("Save, 15 minutes\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 320 | but1=1; |
raheel123 | 0:0e26bf847b57 | 321 | storetosd=3; |
raheel123 | 0:0e26bf847b57 | 322 | }// end of if button 3 pressed |
raheel123 | 0:0e26bf847b57 | 323 | |
raheel123 | 0:0e26bf847b57 | 324 | if(point.y>205 && point.y<238 && point.x<200) |
raheel123 | 0:0e26bf847b57 | 325 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 326 | lcd.objButton(10, 205, 200, 238, SELECTED, "Save, 30 minutes"); |
raheel123 | 0:0e26bf847b57 | 327 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 328 | lcd.objButton(10, 205, 200, 238, DESELECTED, "Save, 30 minutes"); |
raheel123 | 0:0e26bf847b57 | 329 | pc.printf("Save, 30 minutes\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 330 | but1=1; |
raheel123 | 0:0e26bf847b57 | 331 | storetosd=4; |
raheel123 | 0:0e26bf847b57 | 332 | }// end of if button 4 pressed |
raheel123 | 0:0e26bf847b57 | 333 | }// end of if screen touched |
raheel123 | 0:0e26bf847b57 | 334 | } //end of the button press while |
raheel123 | 0:0e26bf847b57 | 335 | }//end of if SD card available statement |
raheel123 | 0:0e26bf847b57 | 336 | |
raheel123 | 0:0e26bf847b57 | 337 | //wait(3); |
raheel123 | 0:0e26bf847b57 | 338 | lcd.erase(); //clear the screen |
raheel123 | 0:0e26bf847b57 | 339 | lcd.setTextColour(CYAN); |
raheel123 | 0:0e26bf847b57 | 340 | lcd.setTextSize(FONT1); |
raheel123 | 0:0e26bf847b57 | 341 | if (storetosd==1)lcd.string(0,0,300,20,"Don't Save", &bytes); |
raheel123 | 0:0e26bf847b57 | 342 | if (storetosd==2)lcd.string(0,0,300,20,"1 minute selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 343 | if (storetosd==3)lcd.string(0,0,300,20,"15 minutes selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 344 | if (storetosd==4)lcd.string(0,0,300,20,"30 minutes selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 345 | if (storetosd==0)lcd.string(0,0,300,20,"nothing selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 346 | //wait(5); |
raheel123 | 0:0e26bf847b57 | 347 | |
raheel123 | 0:0e26bf847b57 | 348 | |
raheel123 | 0:0e26bf847b57 | 349 | |
raheel123 | 0:0e26bf847b57 | 350 | |
raheel123 | 0:0e26bf847b57 | 351 | lcd.erase(); |
raheel123 | 0:0e26bf847b57 | 352 | lcd.setTextColour(GREEN); |
raheel123 | 0:0e26bf847b57 | 353 | if (candidate==0)lcd.string(0,0,150,20,"NO Candidate selected", &bytes); |
raheel123 | 0:0e26bf847b57 | 354 | if (candidate==1)lcd.string(0,0,150,20,"Candidate 1", &bytes); |
raheel123 | 0:0e26bf847b57 | 355 | if (candidate==2)lcd.string(0,0,150,20,"Candidate 2", &bytes); |
raheel123 | 0:0e26bf847b57 | 356 | if (candidate==3)lcd.string(0,0,150,20,"Candidate 3", &bytes); |
raheel123 | 0:0e26bf847b57 | 357 | if (candidate==4)lcd.string(0,0,150,20,"Candidate 4", &bytes); |
raheel123 | 0:0e26bf847b57 | 358 | |
raheel123 | 0:0e26bf847b57 | 359 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 360 | lcd.string(80,220,310,238," GSR HRM OVL",&bytes); |
raheel123 | 0:0e26bf847b57 | 361 | |
raheel123 | 0:0e26bf847b57 | 362 | lcd.string(0,60,100,80,"GSR Base", &bytes); //write a string on the screen |
raheel123 | 0:0e26bf847b57 | 363 | lcd.string(0,81,100,100,"GSR Actual", &bytes); //write a string on the screen |
raheel123 | 0:0e26bf847b57 | 364 | lcd.string(0,101,100,120,"HRM Digital", &bytes); //write a string on the screen |
raheel123 | 0:0e26bf847b57 | 365 | lcd.string(0,121,100,150,"Overall", &bytes); //write a string on the screen |
raheel123 | 0:0e26bf847b57 | 366 | |
raheel123 | 0:0e26bf847b57 | 367 | float gsrdelta,gsrdeltaabs,hrmdeltaabs,hrmdelta,gsr1, gsr2, gsr3, hrm10, hrm25, hrm5, hrm15; |
raheel123 | 0:0e26bf847b57 | 368 | |
raheel123 | 0:0e26bf847b57 | 369 | Get_gsrBaseline(); |
raheel123 | 0:0e26bf847b57 | 370 | Get_hrmBaseline(); |
raheel123 | 0:0e26bf847b57 | 371 | pc.printf("Calculating Average hrm:%f\n",hrmbaseline); |
raheel123 | 0:0e26bf847b57 | 372 | |
raheel123 | 0:0e26bf847b57 | 373 | |
raheel123 | 0:0e26bf847b57 | 374 | |
raheel123 | 0:0e26bf847b57 | 375 | gsr1 = (gsrbaseline+(0.05 * gsrbaseline)); //level 1 GSR Top boundry 5% |
raheel123 | 0:0e26bf847b57 | 376 | gsr2 = (gsrbaseline+(0.10 * gsrbaseline)); //level 2 GSR Top boundry 10% |
raheel123 | 0:0e26bf847b57 | 377 | gsr3 = (gsrbaseline+(0.15 * gsrbaseline)); //level 3 GSR Top boundry 15% |
raheel123 | 0:0e26bf847b57 | 378 | hrm25 = (hrmbaseline+(0.025 * hrmbaseline)); //level 1 HRM Top boundry 25% |
raheel123 | 0:0e26bf847b57 | 379 | hrm15 = (hrmbaseline+(0.015 * hrmbaseline)); //level 2 HRM Top boundry 15% |
raheel123 | 0:0e26bf847b57 | 380 | hrm10 = (hrmbaseline+(0.010 * hrmbaseline)); //level 3 HRM Top boundry 10% |
raheel123 | 0:0e26bf847b57 | 381 | hrm5 = (hrmbaseline-(0.005 * hrmbaseline)); //level 4 HRM Top boundry 5% |
raheel123 | 0:0e26bf847b57 | 382 | |
raheel123 | 0:0e26bf847b57 | 383 | but1=0; |
raheel123 | 0:0e26bf847b57 | 384 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 385 | //draw the object button1 Exit |
raheel123 | 0:0e26bf847b57 | 386 | unsigned int writtenBytes=0; |
raheel123 | 0:0e26bf847b57 | 387 | |
raheel123 | 0:0e26bf847b57 | 388 | if(storetosd>1 && storetosd<5) |
raheel123 | 0:0e26bf847b57 | 389 | { //open a file on the SD card called log.txt |
raheel123 | 0:0e26bf847b57 | 390 | pc.printf("Try to open a file on the SD card called log.txt\r\n"); |
raheel123 | 0:0e26bf847b57 | 391 | //try to open the file |
raheel123 | 0:0e26bf847b57 | 392 | fres=lcd.SDFopenFile("log.txt", WRITEONLY, WORKSPACE0); //Try to open the file in write only mode in the workspace block 0 |
raheel123 | 0:0e26bf847b57 | 393 | if(fres!=F_OK){ //If the file doesn't Open is because it doesn't exist |
raheel123 | 0:0e26bf847b57 | 394 | pc.printf("File doesn't exist, creating log.txt file...\r\n"); |
raheel123 | 0:0e26bf847b57 | 395 | fres=lcd.SDFnewFile("log.txt"); //Try to create the file |
raheel123 | 0:0e26bf847b57 | 396 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 397 | fres=lcd.SDFopenFile("log.txt", WRITEONLY, WORKSPACE0); //Try to open the created file |
raheel123 | 0:0e26bf847b57 | 398 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 399 | } |
raheel123 | 0:0e26bf847b57 | 400 | char messagetitle[100]="Candidate, Interval , GSR Base , GSR , HRM , Day , Month , Hour , Minute , Second \n"; |
raheel123 | 0:0e26bf847b57 | 401 | |
raheel123 | 0:0e26bf847b57 | 402 | res = lcd.getRTCTimeDate(&timeRTC); // get the RTC values back |
raheel123 | 0:0e26bf847b57 | 403 | lcd.SDFsetFileTimeDate(&timeRTC, "log.txt"); //Set Time and Date to the now existing log.txt file |
raheel123 | 0:0e26bf847b57 | 404 | pc.printf("***********saving titles to file \r\n"); |
raheel123 | 0:0e26bf847b57 | 405 | writtenBytes=0; //, readbytes=0; //i=0; |
raheel123 | 0:0e26bf847b57 | 406 | fres=lcd.SDFwriteFile(messagetitle, sizeof(messagetitle), &writtenBytes, WORKSPACE0); //write to the open file in WORKSPACE0 size of message in bytes and store the successfully written Bytes on writtenBytes variable |
raheel123 | 0:0e26bf847b57 | 407 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 408 | lcd.SDFsaveFile(WORKSPACE0); //Save changes in the file contained in WORKSPACE0 |
raheel123 | 0:0e26bf847b57 | 409 | } |
raheel123 | 0:0e26bf847b57 | 410 | |
raheel123 | 0:0e26bf847b57 | 411 | char textStringgsr[9],textStringgsrb[9],textStringhrm[9],textday[3],textmonth[3],texthour[3],textminute[3],textsecond[3]; //textStringhrmb[9] if baseline achieved later |
raheel123 | 0:0e26bf847b57 | 412 | int timestore1,timestore2,length,k=0,j=0,l=0; |
raheel123 | 0:0e26bf847b57 | 413 | |
raheel123 | 0:0e26bf847b57 | 414 | res = lcd.getRTCTimeDate(&timeRTC); // get the RTC values back |
raheel123 | 0:0e26bf847b57 | 415 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 416 | lcd.string(0,21,318,40,"Time:", &bytes); |
raheel123 | 0:0e26bf847b57 | 417 | lcd.printNumber(70,21, timeRTC.hour); // write them to the TFT |
raheel123 | 0:0e26bf847b57 | 418 | lcd.printNumber(95,21, timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 419 | // lcd.printNumber(170,21, timeRTC.second); |
raheel123 | 0:0e26bf847b57 | 420 | lcd.printNumber(200,0, timeRTC.day); |
raheel123 | 0:0e26bf847b57 | 421 | lcd.printNumber(230,0, timeRTC.month); |
raheel123 | 0:0e26bf847b57 | 422 | lcd.printNumber(260,0, timeRTC.year); |
raheel123 | 0:0e26bf847b57 | 423 | timestore1 = timeRTC.minute; // store value to test later for change to help screen refresh |
raheel123 | 0:0e26bf847b57 | 424 | timestore2 = timeRTC.second; // store value to test later for change to help screen refresh |
raheel123 | 0:0e26bf847b57 | 425 | int w=0;// used for overal feeling notification |
raheel123 | 0:0e26bf847b57 | 426 | |
raheel123 | 0:0e26bf847b57 | 427 | lcd.objButton(10, 180, 50, 215, DESELECTED, "EXIT"); // draw the object button to provide exit |
raheel123 | 0:0e26bf847b57 | 428 | |
raheel123 | 0:0e26bf847b57 | 429 | while (but1 == 0) //wait for button press loop |
raheel123 | 0:0e26bf847b57 | 430 | { |
raheel123 | 0:0e26bf847b57 | 431 | |
raheel123 | 0:0e26bf847b57 | 432 | gsrValue = gsr; |
raheel123 | 0:0e26bf847b57 | 433 | aHRMvalue = hrm; |
raheel123 | 0:0e26bf847b57 | 434 | dHRMvalue = DigHRM; |
raheel123 | 0:0e26bf847b57 | 435 | // wait(1); |
raheel123 | 0:0e26bf847b57 | 436 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 437 | lcd.printNumber(110,60, gsrbaseline); |
raheel123 | 0:0e26bf847b57 | 438 | lcd.printNumber(110,81, gsrValue); |
raheel123 | 0:0e26bf847b57 | 439 | //lcd.printNumber(110,101, rateValue);// we are printing here |
raheel123 | 0:0e26bf847b57 | 440 | //lcd.printNumber(110,121, dHRMvalue); |
raheel123 | 0:0e26bf847b57 | 441 | res = lcd.getRTCTimeDate(&timeRTC); // get the RTC values back |
raheel123 | 0:0e26bf847b57 | 442 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 443 | lcd.string(0,21,318,40,"Time:", &bytes); |
raheel123 | 0:0e26bf847b57 | 444 | if(timestore1 != timeRTC.minute) //a minute has expired so send non critical data to screen |
raheel123 | 0:0e26bf847b57 | 445 | { |
raheel123 | 0:0e26bf847b57 | 446 | led_1= !led_1; //toggle led 1 to show activated |
raheel123 | 0:0e26bf847b57 | 447 | lcd.drawRectangle(200, 0, 318, 20, BLACK, FILL); // date refresh |
raheel123 | 0:0e26bf847b57 | 448 | lcd.drawRectangle(70, 21, 300, 42, BLACK, FILL); //time refresh |
raheel123 | 0:0e26bf847b57 | 449 | |
raheel123 | 0:0e26bf847b57 | 450 | lcd.printNumber(70,21, timeRTC.hour); // write them to the TFT |
raheel123 | 0:0e26bf847b57 | 451 | lcd.printNumber(95,21, timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 452 | // lcd.printNumber(170,21, timeRTC.second); |
raheel123 | 0:0e26bf847b57 | 453 | lcd.printNumber(200,0, timeRTC.day); |
raheel123 | 0:0e26bf847b57 | 454 | lcd.printNumber(230,0, timeRTC.month); |
raheel123 | 0:0e26bf847b57 | 455 | lcd.printNumber(260,0, timeRTC.year); |
raheel123 | 0:0e26bf847b57 | 456 | timestore1 = timeRTC.minute; //store new minute value |
raheel123 | 0:0e26bf847b57 | 457 | } |
raheel123 | 0:0e26bf847b57 | 458 | gsrValue = gsr; //put actual gsr pin input into a variable |
raheel123 | 0:0e26bf847b57 | 459 | gsrdelta = gsrbaseline - gsrValue; |
raheel123 | 0:0e26bf847b57 | 460 | gsrdeltaabs = abs(gsrdelta); |
raheel123 | 0:0e26bf847b57 | 461 | |
raheel123 | 0:0e26bf847b57 | 462 | if (gsrdeltaabs < gsrbaseline) |
raheel123 | 0:0e26bf847b57 | 463 | { |
raheel123 | 0:0e26bf847b57 | 464 | gsrdeltaabs = gsrbaseline + gsrdeltaabs; // make all negative values regarding baseline +ve |
raheel123 | 0:0e26bf847b57 | 465 | } |
raheel123 | 0:0e26bf847b57 | 466 | if((gsrdeltaabs >= gsrbaseline) && (gsrdeltaabs <= gsr1)) // check for being upto 5% of baseline |
raheel123 | 0:0e26bf847b57 | 467 | { |
raheel123 | 0:0e26bf847b57 | 468 | lcd.drawRectangle(100, 180, 140, 215, GREEN, FILL); |
raheel123 | 0:0e26bf847b57 | 469 | // x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 470 | w=1; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 471 | } |
raheel123 | 0:0e26bf847b57 | 472 | else if((gsrdeltaabs > gsr1) && (gsrdeltaabs <= gsr2)) // check for being > 6% to 10% of baseline |
raheel123 | 0:0e26bf847b57 | 473 | { |
raheel123 | 0:0e26bf847b57 | 474 | lcd.drawRectangle(100, 180, 140, 215, YELLOW, FILL); |
raheel123 | 0:0e26bf847b57 | 475 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 476 | w=2; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 477 | } |
raheel123 | 0:0e26bf847b57 | 478 | else if((gsrdeltaabs > gsr2) && (gsrdeltaabs <= gsr3)) // check for being > 11% to 15% of baseline |
raheel123 | 0:0e26bf847b57 | 479 | { |
raheel123 | 0:0e26bf847b57 | 480 | lcd.drawRectangle(100, 180, 140, 215, CYAN, FILL); |
raheel123 | 0:0e26bf847b57 | 481 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 482 | w=3; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 483 | } |
raheel123 | 0:0e26bf847b57 | 484 | else if(gsrdeltaabs > gsr3) // check for being > 16% of baseline |
raheel123 | 0:0e26bf847b57 | 485 | { |
raheel123 | 0:0e26bf847b57 | 486 | lcd.drawRectangle(100, 180, 140, 215, RED, FILL); |
raheel123 | 0:0e26bf847b57 | 487 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 488 | w=4; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 489 | } |
raheel123 | 0:0e26bf847b57 | 490 | |
raheel123 | 0:0e26bf847b57 | 491 | hrmValue = hrm; //Heart Rate Monitor |
raheel123 | 0:0e26bf847b57 | 492 | heartrate.getValue(p16); |
raheel123 | 0:0e26bf847b57 | 493 | rateValue = heartrate.getRate(); |
raheel123 | 0:0e26bf847b57 | 494 | // if(rateValue) { |
raheel123 | 0:0e26bf847b57 | 495 | // printf("\n\r=====BPM==== %d =====\n\r\n\r",rateValue); |
raheel123 | 0:0e26bf847b57 | 496 | // lcd.drawRectangle(110, 102, 300, 150, BLACK, FILL); // |
raheel123 | 0:0e26bf847b57 | 497 | // lcd.printNumber(110,102, rateValue); //Heart rate digital actual calculated value - real time |
raheel123 | 0:0e26bf847b57 | 498 | // lcd.printNumber(110,123, w); // now not used at this point |
raheel123 | 0:0e26bf847b57 | 499 | // w=0; |
raheel123 | 0:0e26bf847b57 | 500 | // } |
raheel123 | 0:0e26bf847b57 | 501 | int d = static_cast<long int>(clock_ms()); |
raheel123 | 0:0e26bf847b57 | 502 | //printf("Print every second : %d\n\r", d); |
raheel123 | 0:0e26bf847b57 | 503 | |
raheel123 | 0:0e26bf847b57 | 504 | //printf("hrmValue = %f\n\r",hrmValue); |
raheel123 | 0:0e26bf847b57 | 505 | // printf("hrm5 = %f\n\r",(hrm5)); |
raheel123 | 0:0e26bf847b57 | 506 | // printf("hrm10 = %f\n\r",(hrm10)); |
raheel123 | 0:0e26bf847b57 | 507 | //hrmdelta = hrmbaseline - hrmValue; |
raheel123 | 0:0e26bf847b57 | 508 | //hrmdeltaabs = abs(hrmdelta); |
raheel123 | 0:0e26bf847b57 | 509 | // if (hrmdeltaabs < hrmbaseline) |
raheel123 | 0:0e26bf847b57 | 510 | // { |
raheel123 | 0:0e26bf847b57 | 511 | // hrmdeltaabs = hrmbaseline + hrmdeltaabs; // make all negative values regarding baseline +ve |
raheel123 | 0:0e26bf847b57 | 512 | // } |
raheel123 | 0:0e26bf847b57 | 513 | if((hrm5) <= hrmValue && hrmValue <= (hrm10)) // check for being in between -5% to 10% of baseline |
raheel123 | 0:0e26bf847b57 | 514 | { |
raheel123 | 0:0e26bf847b57 | 515 | lcd.drawRectangle(180, 180, 220, 215, GREEN, FILL); |
raheel123 | 0:0e26bf847b57 | 516 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 517 | //printf("green"); |
raheel123 | 0:0e26bf847b57 | 518 | w=w+1; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 519 | } |
raheel123 | 0:0e26bf847b57 | 520 | else if((hrm10) < hrmValue && hrmValue< (hrm25)) // check for being > +10% to +25% of baseline |
raheel123 | 0:0e26bf847b57 | 521 | { |
raheel123 | 0:0e26bf847b57 | 522 | lcd.drawRectangle(180, 180, 220, 215, YELLOW, FILL); |
raheel123 | 0:0e26bf847b57 | 523 | //printf("yellow"); |
raheel123 | 0:0e26bf847b57 | 524 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 525 | w=w+2; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 526 | } |
raheel123 | 0:0e26bf847b57 | 527 | else if(hrmValue < (hrm5)) // check for being <45% of baseline |
raheel123 | 0:0e26bf847b57 | 528 | { |
raheel123 | 0:0e26bf847b57 | 529 | lcd.drawRectangle(180, 180, 220, 215, BLUE, FILL); |
raheel123 | 0:0e26bf847b57 | 530 | //printf("blue"); |
raheel123 | 0:0e26bf847b57 | 531 | w=w+3; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 532 | } |
raheel123 | 0:0e26bf847b57 | 533 | else if(hrmValue>=(hrm25)) // check for being > 75% of baseline |
raheel123 | 0:0e26bf847b57 | 534 | { |
raheel123 | 0:0e26bf847b57 | 535 | lcd.drawRectangle(180, 180, 220, 215, RED, FILL); |
raheel123 | 0:0e26bf847b57 | 536 | w=w+4; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 537 | } |
raheel123 | 0:0e26bf847b57 | 538 | /* if((hrm5) <= hrmValue && hrmValue <= (hrm10)) // check for being in between -5% to 10% of baseline |
raheel123 | 0:0e26bf847b57 | 539 | { |
raheel123 | 0:0e26bf847b57 | 540 | lcd.drawRectangle(180, 180, 220, 215, GREEN, FILL); |
raheel123 | 0:0e26bf847b57 | 541 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 542 | //printf("green"); |
raheel123 | 0:0e26bf847b57 | 543 | w=w+1; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 544 | } |
raheel123 | 0:0e26bf847b57 | 545 | else if((hrm10) < hrmValue && hrmValue< (hrm25)) // check for being > +10% to +25% of baseline |
raheel123 | 0:0e26bf847b57 | 546 | { |
raheel123 | 0:0e26bf847b57 | 547 | lcd.drawRectangle(180, 180, 220, 215, YELLOW, FILL); |
raheel123 | 0:0e26bf847b57 | 548 | //printf("yellow"); |
raheel123 | 0:0e26bf847b57 | 549 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 550 | w=w+2; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 551 | } |
raheel123 | 0:0e26bf847b57 | 552 | else if(hrmValue < (hrm5)) // check for being <45% of baseline |
raheel123 | 0:0e26bf847b57 | 553 | { |
raheel123 | 0:0e26bf847b57 | 554 | lcd.drawRectangle(180, 180, 220, 215, BLUE, FILL); |
raheel123 | 0:0e26bf847b57 | 555 | //printf("blue"); |
raheel123 | 0:0e26bf847b57 | 556 | w=w+3; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 557 | } |
raheel123 | 0:0e26bf847b57 | 558 | else if(hrmValue>=(hrm25)) // check for being > 75% of baseline |
raheel123 | 0:0e26bf847b57 | 559 | { |
raheel123 | 0:0e26bf847b57 | 560 | lcd.drawRectangle(180, 180, 220, 215, RED, FILL); |
raheel123 | 0:0e26bf847b57 | 561 | w=w+4; //for overal feeling indication |
raheel123 | 0:0e26bf847b57 | 562 | } |
raheel123 | 0:0e26bf847b57 | 563 | */ |
raheel123 | 0:0e26bf847b57 | 564 | //overal feeling combined box display |
raheel123 | 0:0e26bf847b57 | 565 | if(w < 4) // 1,2or3 |
raheel123 | 0:0e26bf847b57 | 566 | { |
raheel123 | 0:0e26bf847b57 | 567 | lcd.drawRectangle(260, 180, 300, 215, GREEN, FILL); |
raheel123 | 0:0e26bf847b57 | 568 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 569 | //printf("green"); |
raheel123 | 0:0e26bf847b57 | 570 | } |
raheel123 | 0:0e26bf847b57 | 571 | else if(w >= 4 && w < 6) // 4or5 |
raheel123 | 0:0e26bf847b57 | 572 | { |
raheel123 | 0:0e26bf847b57 | 573 | lcd.drawRectangle(260, 180, 300, 215, YELLOW, FILL); |
raheel123 | 0:0e26bf847b57 | 574 | //printf("yellow"); |
raheel123 | 0:0e26bf847b57 | 575 | //x, y, width, height, colour |
raheel123 | 0:0e26bf847b57 | 576 | } |
raheel123 | 0:0e26bf847b57 | 577 | else if(w >= 6 && w < 8) // 6 or 7 |
raheel123 | 0:0e26bf847b57 | 578 | { |
raheel123 | 0:0e26bf847b57 | 579 | lcd.drawRectangle(260, 180, 300, 215, BLUE, FILL); |
raheel123 | 0:0e26bf847b57 | 580 | //printf("blue"); |
raheel123 | 0:0e26bf847b57 | 581 | } |
raheel123 | 0:0e26bf847b57 | 582 | else if(w >= 8) // 8 or above just in case new scheme used later |
raheel123 | 0:0e26bf847b57 | 583 | { |
raheel123 | 0:0e26bf847b57 | 584 | lcd.drawRectangle(260, 180, 300, 215, RED, FILL); |
raheel123 | 0:0e26bf847b57 | 585 | } |
raheel123 | 0:0e26bf847b57 | 586 | //w=0; //reset for next time round |
raheel123 | 0:0e26bf847b57 | 587 | if(rateValue) { |
raheel123 | 0:0e26bf847b57 | 588 | printf("\n\r=====BPM==== %d =====\n\r\n\r",rateValue); |
raheel123 | 0:0e26bf847b57 | 589 | lcd.drawRectangle(110, 102, 300, 150, BLACK, FILL); // |
raheel123 | 0:0e26bf847b57 | 590 | lcd.printNumber(110,102, rateValue); //Heart rate digital actual calculated value - real time |
raheel123 | 0:0e26bf847b57 | 591 | lcd.printNumber(110,123, w); // now not used at this point |
raheel123 | 0:0e26bf847b57 | 592 | w=0; |
raheel123 | 0:0e26bf847b57 | 593 | } |
raheel123 | 0:0e26bf847b57 | 594 | |
raheel123 | 0:0e26bf847b57 | 595 | |
raheel123 | 0:0e26bf847b57 | 596 | |
raheel123 | 0:0e26bf847b57 | 597 | wait(0.1); |
raheel123 | 0:0e26bf847b57 | 598 | // lcd.setTextColour(BLACK); |
raheel123 | 0:0e26bf847b57 | 599 | // lcd.drawRectangle(200, 0, 318, 20, BLACK, FILL); // date refresh |
raheel123 | 0:0e26bf847b57 | 600 | // lcd.drawRectangle(70, 21, 300, 60, BLACK, FILL); //time refresh |
raheel123 | 0:0e26bf847b57 | 601 | // lcd.drawRectangle(101, 31, 300, 150, BLACK, FILL); // 101 clears the area of screen with numbers so not to overwrite causing blurred numbers |
raheel123 | 0:0e26bf847b57 | 602 | lcd.drawRectangle(110, 60, 300, 101, BLACK, FILL); //110,31,300,150 |
raheel123 | 0:0e26bf847b57 | 603 | // lcd.printNumber(110,60, gsrbaseline); //gsr baseline value (doesnt change) |
raheel123 | 0:0e26bf847b57 | 604 | // lcd.printNumber(110,81, gsrValue); //GSR actual value - real time |
raheel123 | 0:0e26bf847b57 | 605 | |
raheel123 | 0:0e26bf847b57 | 606 | if(timestore2 != timeRTC.second) //a second has expired so send heart rate value to screen |
raheel123 | 0:0e26bf847b57 | 607 | { |
raheel123 | 0:0e26bf847b57 | 608 | led_2= !led_2; |
raheel123 | 0:0e26bf847b57 | 609 | // lcd.drawRectangle(110, 102, 300, 150, BLACK, FILL); // |
raheel123 | 0:0e26bf847b57 | 610 | // lcd.printNumber(110,102, rateValue); //Heart rate digital actual calculated value - real time |
raheel123 | 0:0e26bf847b57 | 611 | //lcd.printNumber(110,123, rateValue); // now not used at this point |
raheel123 | 0:0e26bf847b57 | 612 | timestore2 = timeRTC.second; // store new second value |
raheel123 | 0:0e26bf847b57 | 613 | } |
raheel123 | 0:0e26bf847b57 | 614 | if(storetosd>1 && storetosd<5) |
raheel123 | 0:0e26bf847b57 | 615 | { //if data to be captured to sd card do the following |
raheel123 | 0:0e26bf847b57 | 616 | res = lcd.getRTCTimeDate(&timeRTC); |
raheel123 | 0:0e26bf847b57 | 617 | length=snprintf(textday,3,"%d",timeRTC.day); |
raheel123 | 0:0e26bf847b57 | 618 | length=snprintf(textmonth,3,"%d",timeRTC.month); |
raheel123 | 0:0e26bf847b57 | 619 | length=snprintf(texthour,3,"%d",timeRTC.hour); |
raheel123 | 0:0e26bf847b57 | 620 | length=snprintf(textminute,3,"%d",timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 621 | length=snprintf(textsecond,3,"%d",timeRTC.second); |
raheel123 | 0:0e26bf847b57 | 622 | length=snprintf(textStringgsrb,9,"%f",gsrbaseline);// convert gsr baseline float to character string to send to SD card |
raheel123 | 0:0e26bf847b57 | 623 | length=snprintf(textStringgsr,9,"%f",gsrValue);// convert gsr float to character string to send to SD card |
raheel123 | 0:0e26bf847b57 | 624 | length=snprintf(textStringhrm,9,"%f",aHRMvalue);// convert analogue hrm float to character string to send to SD card |
raheel123 | 0:0e26bf847b57 | 625 | |
raheel123 | 0:0e26bf847b57 | 626 | // length=snprintf(textStringgsr,9,"%f",gsrValue);// convert float to character string to send to SD card |
raheel123 | 0:0e26bf847b57 | 627 | char messageft[60]="\0"; |
raheel123 | 0:0e26bf847b57 | 628 | if (candidate <1 || candidate>4) {strcat(messageft,"0,");} |
raheel123 | 0:0e26bf847b57 | 629 | if (candidate==1) {strcat(messageft,"1,");} |
raheel123 | 0:0e26bf847b57 | 630 | if (candidate==2) {strcat(messageft,"2,");} |
raheel123 | 0:0e26bf847b57 | 631 | if (candidate==3) {strcat(messageft,"3,");} |
raheel123 | 0:0e26bf847b57 | 632 | if (candidate==4) {strcat(messageft,"4,");} |
raheel123 | 0:0e26bf847b57 | 633 | if (storetosd==2) {strcat(messageft,"1,");} |
raheel123 | 0:0e26bf847b57 | 634 | if (storetosd==3) {strcat(messageft,"15,");} |
raheel123 | 0:0e26bf847b57 | 635 | if (storetosd==4) {strcat(messageft,"30,");} |
raheel123 | 0:0e26bf847b57 | 636 | strcat(messageft,textStringgsrb); |
raheel123 | 0:0e26bf847b57 | 637 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 638 | strcat(messageft,textStringgsr); |
raheel123 | 0:0e26bf847b57 | 639 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 640 | strcat(messageft,textStringhrm); |
raheel123 | 0:0e26bf847b57 | 641 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 642 | strcat(messageft,textday);// add the hour value |
raheel123 | 0:0e26bf847b57 | 643 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 644 | strcat(messageft,textmonth);// add the hour value |
raheel123 | 0:0e26bf847b57 | 645 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 646 | strcat(messageft,texthour);// add the hour value |
raheel123 | 0:0e26bf847b57 | 647 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 648 | strcat(messageft,textminute);// add the minute value |
raheel123 | 0:0e26bf847b57 | 649 | strcat(messageft,","); |
raheel123 | 0:0e26bf847b57 | 650 | strcat(messageft,textsecond);// add the hour value |
raheel123 | 0:0e26bf847b57 | 651 | strcat(messageft,"\n"); |
raheel123 | 0:0e26bf847b57 | 652 | pc.printf("%s\r\n",messageft); |
raheel123 | 0:0e26bf847b57 | 653 | |
raheel123 | 0:0e26bf847b57 | 654 | lcd.setTextColour(WHITE);//recording notice on screen |
raheel123 | 0:0e26bf847b57 | 655 | lcd.string(15,220,70,238,"Rec", &bytes); |
raheel123 | 0:0e26bf847b57 | 656 | wait(0.1); |
raheel123 | 0:0e26bf847b57 | 657 | int z; |
raheel123 | 0:0e26bf847b57 | 658 | |
raheel123 | 0:0e26bf847b57 | 659 | if(storetosd==2) |
raheel123 | 0:0e26bf847b57 | 660 | { //if data to be captured to sd card every 1 minute do the following |
raheel123 | 0:0e26bf847b57 | 661 | if(k==0) |
raheel123 | 0:0e26bf847b57 | 662 | {// if timer hasnt been started start it |
raheel123 | 0:0e26bf847b57 | 663 | k=1; // start timer once per selected period |
raheel123 | 0:0e26bf847b57 | 664 | j=timeRTC.second;// store second value |
raheel123 | 0:0e26bf847b57 | 665 | timeRTC.second++; //move the timer forward by one to prevent chance of immediate trigger of timer trap |
raheel123 | 0:0e26bf847b57 | 666 | pc.printf("***********************start 1 min timer\r\n"); |
raheel123 | 0:0e26bf847b57 | 667 | } |
raheel123 | 0:0e26bf847b57 | 668 | if(timeRTC.second!=j) |
raheel123 | 0:0e26bf847b57 | 669 | { //if second value is different from previous value assue 1 second has expired |
raheel123 | 0:0e26bf847b57 | 670 | //k=0; |
raheel123 | 0:0e26bf847b57 | 671 | j=timeRTC.second;// store new second value |
raheel123 | 0:0e26bf847b57 | 672 | l++; //increment second timer |
raheel123 | 0:0e26bf847b57 | 673 | pc.printf("************************** %d seconds have elapsed\r\n",l); |
raheel123 | 0:0e26bf847b57 | 674 | if (l==60) |
raheel123 | 0:0e26bf847b57 | 675 | { // 60 seconds have elapsed so lets save data to the SD card |
raheel123 | 0:0e26bf847b57 | 676 | l=0; //reset 1 minute counter |
raheel123 | 0:0e26bf847b57 | 677 | k=0; //reset timer |
raheel123 | 0:0e26bf847b57 | 678 | lcd.setTextColour(RED); |
raheel123 | 0:0e26bf847b57 | 679 | lcd.string(15,220,70,238,"Rec", &bytes); |
raheel123 | 0:0e26bf847b57 | 680 | wait(1); |
raheel123 | 0:0e26bf847b57 | 681 | pc.printf("***********reset 1 min timer\r\n"); |
raheel123 | 0:0e26bf847b57 | 682 | pc.printf("***********saving to file - 1 minute\r\n"); |
raheel123 | 0:0e26bf847b57 | 683 | writtenBytes=0; //, readbytes=0; //i=0; |
raheel123 | 0:0e26bf847b57 | 684 | fres=lcd.SDFwriteFile(messageft, sizeof(messageft), &writtenBytes, WORKSPACE0); //write to the open file in WORKSPACE0 size of message in bytes and store the successfully written Bytes on writtenBytes variable |
raheel123 | 0:0e26bf847b57 | 685 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 686 | lcd.SDFsaveFile(WORKSPACE0); //Save changes in the file contained in WORKSPACE0 |
raheel123 | 0:0e26bf847b57 | 687 | } |
raheel123 | 0:0e26bf847b57 | 688 | } |
raheel123 | 0:0e26bf847b57 | 689 | } |
raheel123 | 0:0e26bf847b57 | 690 | |
raheel123 | 0:0e26bf847b57 | 691 | if(storetosd==3) |
raheel123 | 0:0e26bf847b57 | 692 | { //if data to be captured to sd card every 15 minutes do the following |
raheel123 | 0:0e26bf847b57 | 693 | if(k==0) |
raheel123 | 0:0e26bf847b57 | 694 | {// if timer hasnt been started start it |
raheel123 | 0:0e26bf847b57 | 695 | k=1; // start timer once per selected period |
raheel123 | 0:0e26bf847b57 | 696 | j=timeRTC.minute;// store initial minute value |
raheel123 | 0:0e26bf847b57 | 697 | l=0; //clear minute counter |
raheel123 | 0:0e26bf847b57 | 698 | } |
raheel123 | 0:0e26bf847b57 | 699 | if(k==1) |
raheel123 | 0:0e26bf847b57 | 700 | { //if timer started do the following |
raheel123 | 0:0e26bf847b57 | 701 | //z=j; // save last value for minute |
raheel123 | 0:0e26bf847b57 | 702 | if(timeRTC.minute==j) |
raheel123 | 0:0e26bf847b57 | 703 | { //the minute value has not changed |
raheel123 | 0:0e26bf847b57 | 704 | z=0; |
raheel123 | 0:0e26bf847b57 | 705 | } |
raheel123 | 0:0e26bf847b57 | 706 | else |
raheel123 | 0:0e26bf847b57 | 707 | { //if the minute value has changed |
raheel123 | 0:0e26bf847b57 | 708 | l++; // count how many minutes have passed |
raheel123 | 0:0e26bf847b57 | 709 | j=timeRTC.minute;// store new minute value |
raheel123 | 0:0e26bf847b57 | 710 | pc.printf("*************************** %d minutes have elapsed\r\n",l); |
raheel123 | 0:0e26bf847b57 | 711 | } |
raheel123 | 0:0e26bf847b57 | 712 | if(l==15) |
raheel123 | 0:0e26bf847b57 | 713 | { // 15 minutes have elapsed so lets save data to the SD card |
raheel123 | 0:0e26bf847b57 | 714 | l=0; //reset 15 minute counter |
raheel123 | 0:0e26bf847b57 | 715 | k=0; //reset timer |
raheel123 | 0:0e26bf847b57 | 716 | lcd.setTextColour(RED); |
raheel123 | 0:0e26bf847b57 | 717 | lcd.string(15,220,70,238,"Rec", &bytes); |
raheel123 | 0:0e26bf847b57 | 718 | wait(1); |
raheel123 | 0:0e26bf847b57 | 719 | pc.printf("***********reset 15 min timer\r\n"); |
raheel123 | 0:0e26bf847b57 | 720 | pc.printf("***********saving to file - 15 minute\r\n"); |
raheel123 | 0:0e26bf847b57 | 721 | writtenBytes=0; //, readbytes=0; //i=0; |
raheel123 | 0:0e26bf847b57 | 722 | fres=lcd.SDFwriteFile(messageft, sizeof(messageft), &writtenBytes, WORKSPACE0); //write to the open file in WORKSPACE0 size of message in bytes and store the successfully written Bytes on writtenBytes variable |
raheel123 | 0:0e26bf847b57 | 723 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 724 | lcd.SDFsaveFile(WORKSPACE0); //Save changes in the file contained in WORKSPACE0 |
raheel123 | 0:0e26bf847b57 | 725 | } //end of if 15 mins counted |
raheel123 | 0:0e26bf847b57 | 726 | } //end of if timer has started |
raheel123 | 0:0e26bf847b57 | 727 | } // end of if 15min capture time selected |
raheel123 | 0:0e26bf847b57 | 728 | |
raheel123 | 0:0e26bf847b57 | 729 | |
raheel123 | 0:0e26bf847b57 | 730 | if(storetosd==4) |
raheel123 | 0:0e26bf847b57 | 731 | { //if data to be captured to sd card every 15 minutes do the following |
raheel123 | 0:0e26bf847b57 | 732 | if(k==0) |
raheel123 | 0:0e26bf847b57 | 733 | {// if timer hasnt been started start it |
raheel123 | 0:0e26bf847b57 | 734 | k=1; // start timer once per selected period |
raheel123 | 0:0e26bf847b57 | 735 | j=timeRTC.minute;// store minute value |
raheel123 | 0:0e26bf847b57 | 736 | j++; //move the timer along by one to prevent chance of immediate trigger of timer trap |
raheel123 | 0:0e26bf847b57 | 737 | pc.printf("*****************************start 30 min timer\r\n"); |
raheel123 | 0:0e26bf847b57 | 738 | } |
raheel123 | 0:0e26bf847b57 | 739 | if(timeRTC.minute!=j) |
raheel123 | 0:0e26bf847b57 | 740 | { //if minute value is different from previous value assue 1 minute has expired |
raheel123 | 0:0e26bf847b57 | 741 | //k=0; |
raheel123 | 0:0e26bf847b57 | 742 | j=timeRTC.minute;// store new minute value |
raheel123 | 0:0e26bf847b57 | 743 | l++; //increment minute timer |
raheel123 | 0:0e26bf847b57 | 744 | pc.printf("***************************** %d minutes have elapsed\r\n",l); |
raheel123 | 0:0e26bf847b57 | 745 | if (l==30) |
raheel123 | 0:0e26bf847b57 | 746 | { // 30 minutes have elapsed so lets save data to the SD card |
raheel123 | 0:0e26bf847b57 | 747 | l=0; //reset 30 minute counter |
raheel123 | 0:0e26bf847b57 | 748 | k=0; //reset timer |
raheel123 | 0:0e26bf847b57 | 749 | lcd.setTextColour(RED); |
raheel123 | 0:0e26bf847b57 | 750 | lcd.string(15,220,70,238,"Rec", &bytes); |
raheel123 | 0:0e26bf847b57 | 751 | wait(1); |
raheel123 | 0:0e26bf847b57 | 752 | pc.printf("***********reset 30 min timer\r\n"); |
raheel123 | 0:0e26bf847b57 | 753 | pc.printf("***********saving to file - 30 minute\r\n"); |
raheel123 | 0:0e26bf847b57 | 754 | writtenBytes=0; //, readbytes=0; //i=0; |
raheel123 | 0:0e26bf847b57 | 755 | fres=lcd.SDFwriteFile(messageft, sizeof(messageft), &writtenBytes, WORKSPACE0); //write to the open file in WORKSPACE0 size of message in bytes and store the successfully written Bytes on writtenBytes variable |
raheel123 | 0:0e26bf847b57 | 756 | die(fres); //If any error report it |
raheel123 | 0:0e26bf847b57 | 757 | lcd.SDFsaveFile(WORKSPACE0); //Save changes in the file contained in WORKSPACE0 |
raheel123 | 0:0e26bf847b57 | 758 | } |
raheel123 | 0:0e26bf847b57 | 759 | } |
raheel123 | 0:0e26bf847b57 | 760 | } |
raheel123 | 0:0e26bf847b57 | 761 | |
raheel123 | 0:0e26bf847b57 | 762 | |
raheel123 | 0:0e26bf847b57 | 763 | lcd.setTextColour(WHITE); |
raheel123 | 0:0e26bf847b57 | 764 | res = lcd.getRTCTimeDate(&timeRTC); |
raheel123 | 0:0e26bf847b57 | 765 | pc.printf("%d sec %d min %d \r\n",timeRTC.second, timeRTC.minute, storetosd); |
raheel123 | 0:0e26bf847b57 | 766 | // pc.printf("%d \r\n",timeRTC.minute); |
raheel123 | 0:0e26bf847b57 | 767 | } //end of storetosd if |
raheel123 | 0:0e26bf847b57 | 768 | |
raheel123 | 0:0e26bf847b57 | 769 | |
raheel123 | 0:0e26bf847b57 | 770 | if(lcd.touchScreen(&point)==VALID) |
raheel123 | 0:0e26bf847b57 | 771 | { //if a touch on screen is valid check which button |
raheel123 | 0:0e26bf847b57 | 772 | if(point.y>180 && point.y<215 && point.x<50) |
raheel123 | 0:0e26bf847b57 | 773 | { //if the touch on button1 draw the object button1 as SELECTED |
raheel123 | 0:0e26bf847b57 | 774 | lcd.objButton(10, 180, 50, 215, SELECTED, "EXIT"); |
raheel123 | 0:0e26bf847b57 | 775 | wait_ms(50); |
raheel123 | 0:0e26bf847b57 | 776 | lcd.objButton(10, 180, 50, 215, DESELECTED, "EXIT"); |
raheel123 | 0:0e26bf847b57 | 777 | pc.printf("EXIT\r\n"); //debug |
raheel123 | 0:0e26bf847b57 | 778 | but1=1; |
raheel123 | 0:0e26bf847b57 | 779 | }// end of if button 1 pressed |
raheel123 | 0:0e26bf847b57 | 780 | }// end of if screen touched |
raheel123 | 0:0e26bf847b57 | 781 | } //end of main loop while Exit button |
raheel123 | 0:0e26bf847b57 | 782 | |
raheel123 | 0:0e26bf847b57 | 783 | if(storetosd>1 && storetosd<5) |
raheel123 | 0:0e26bf847b57 | 784 | { //if data to be captured to sd card close the file properly |
raheel123 | 0:0e26bf847b57 | 785 | lcd.SDFsaveFile(WORKSPACE0); //Save changes in the file contained in WORKSPACE0 |
raheel123 | 0:0e26bf847b57 | 786 | //lcd.string(10,row,319,239,"Closing File...",&charsPrinted); row+=15; |
raheel123 | 0:0e26bf847b57 | 787 | lcd.SDFcloseFile(WORKSPACE0); //Close the file -------------------- |
raheel123 | 0:0e26bf847b57 | 788 | } |
raheel123 | 0:0e26bf847b57 | 789 | pc.printf("SD open file now saved and closed properly\r\n"); |
raheel123 | 0:0e26bf847b57 | 790 | wait(3); // wait to show message before starting the program again |
raheel123 | 0:0e26bf847b57 | 791 | pc.printf("re-starting the program again\r\n"); |
raheel123 | 0:0e26bf847b57 | 792 | wait(2); |
raheel123 | 0:0e26bf847b57 | 793 | }// end of total program while statement |
raheel123 | 0:0e26bf847b57 | 794 | }// end of main program |