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