Health monitoring app

Dependencies:   FXOS8700 HTU21D Hexi_KW40Z Hexi_OLED_SSD1351 Hexidraw

Committer:
Mariya
Date:
Tue Apr 25 00:32:17 2017 +0000
Revision:
0:7f8127c43904
Final project for the ECE 595 course

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mariya 0:7f8127c43904 1 #include "mbed.h"
Mariya 0:7f8127c43904 2 #include "HTU21D.h"
Mariya 0:7f8127c43904 3 #include "FXOS8700.h"
Mariya 0:7f8127c43904 4 #include "Hexi_OLED_SSD1351.h"
Mariya 0:7f8127c43904 5 #include <stdlib.h>
Mariya 0:7f8127c43904 6 #include <time.h>
Mariya 0:7f8127c43904 7 //#include "images.h"
Mariya 0:7f8127c43904 8 #include "string.h"
Mariya 0:7f8127c43904 9 #include "math.h"
Mariya 0:7f8127c43904 10 //#include "Fever_Click.h"
Mariya 0:7f8127c43904 11 #include "Hexi_KW40Z.h"
Mariya 0:7f8127c43904 12 #include "hexidraw.h"
Mariya 0:7f8127c43904 13 //#include "MAX30101.h"
Mariya 0:7f8127c43904 14 //#include "heartRate_driver.h"
Mariya 0:7f8127c43904 15 #define LED_ON 0
Mariya 0:7f8127c43904 16 #define LED_OFF 1
Mariya 0:7f8127c43904 17 OLED oled1;
Mariya 0:7f8127c43904 18 DigitalOut redLed(LED1);
Mariya 0:7f8127c43904 19 DigitalOut greenLed(LED2);
Mariya 0:7f8127c43904 20 DigitalOut blueLed(LED3);
Mariya 0:7f8127c43904 21 DigitalOut haptic(PTB9);
Mariya 0:7f8127c43904 22 void StartHaptic(void);
Mariya 0:7f8127c43904 23 void StopHaptic(void const *n);
Mariya 0:7f8127c43904 24
Mariya 0:7f8127c43904 25
Mariya 0:7f8127c43904 26
Mariya 0:7f8127c43904 27 // Pin connections
Mariya 0:7f8127c43904 28 //DigitalOut led1(LED_GREEN); // RGB LED
Mariya 0:7f8127c43904 29 Serial pc(USBTX, USBRX); // Serial interface
Mariya 0:7f8127c43904 30 HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor
Mariya 0:7f8127c43904 31 DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor
Mariya 0:7f8127c43904 32 FXOS8700 accel(PTC11, PTC10);
Mariya 0:7f8127c43904 33 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
Mariya 0:7f8127c43904 34 //MAX30101 heart(PTB1, PTB0);
Mariya 0:7f8127c43904 35 //I2C i2c(PTD9,PTD8);
Mariya 0:7f8127c43904 36
Mariya 0:7f8127c43904 37 void ButtonUp(void);
Mariya 0:7f8127c43904 38 void ButtonDown(void);
Mariya 0:7f8127c43904 39 void ButtonRight(void);
Mariya 0:7f8127c43904 40 void ButtonLeft(void);
Mariya 0:7f8127c43904 41 void ButtonSlide(void);
Mariya 0:7f8127c43904 42 /* Define timer for haptic feedback */
Mariya 0:7f8127c43904 43 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
Mariya 0:7f8127c43904 44
Mariya 0:7f8127c43904 45 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
Mariya 0:7f8127c43904 46 KW40Z kw40z_device(PTE24, PTE25);
Mariya 0:7f8127c43904 47 // Variables
Mariya 0:7f8127c43904 48 int sample_ftemp,flag=0,ped=0,oldped=0,cal=0,once=0;
Mariya 0:7f8127c43904 49 int sample_ctemp;
Mariya 0:7f8127c43904 50 int sample_ktemp;
Mariya 0:7f8127c43904 51 int sample_humid;
Mariya 0:7f8127c43904 52 float accel_data[3]; // Storage for the data from the sensor
Mariya 0:7f8127c43904 53 float accel_rms=0.0; // RMS value from the sensor
Mariya 0:7f8127c43904 54 float acc=0;
Mariya 0:7f8127c43904 55 float ax, ay, az;// temp;
Mariya 0:7f8127c43904 56 char text1[20];
Mariya 0:7f8127c43904 57 const uint8_t *image1; // Pointer for the image to be displayed
Mariya 0:7f8127c43904 58 char text[20]; // Text Buffer for dynamic value displayed
Mariya 0:7f8127c43904 59 uint8_t data;
Mariya 0:7f8127c43904 60 uint8_t sample= rand() % 5 + 62;
Mariya 0:7f8127c43904 61 int main() {
Mariya 0:7f8127c43904 62 srand (time(NULL));
Mariya 0:7f8127c43904 63 powerEN = 0;
Mariya 0:7f8127c43904 64
Mariya 0:7f8127c43904 65 /* Setting pointer location of the 96 by 96 pixel bitmap */
Mariya 0:7f8127c43904 66 //image1 = TempHumid;
Mariya 0:7f8127c43904 67
Mariya 0:7f8127c43904 68 /* Turn on the backlight of the OLED Display */
Mariya 0:7f8127c43904 69 // oled.DimScreenON();
Mariya 0:7f8127c43904 70
Mariya 0:7f8127c43904 71 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
Mariya 0:7f8127c43904 72 // oled.DrawImage(image1,0,0);
Mariya 0:7f8127c43904 73 oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 74 while(true) {
Mariya 0:7f8127c43904 75
Mariya 0:7f8127c43904 76 kw40z_device.attach_buttonUp(&ButtonUp);
Mariya 0:7f8127c43904 77 kw40z_device.attach_buttonDown(&ButtonDown);
Mariya 0:7f8127c43904 78 kw40z_device.attach_buttonLeft(&ButtonLeft);
Mariya 0:7f8127c43904 79 kw40z_device.attach_buttonRight(&ButtonRight);
Mariya 0:7f8127c43904 80 kw40z_device.attach_buttonSlide(&ButtonSlide);
Mariya 0:7f8127c43904 81 sample_ftemp = temphumid.sample_ftemp()-30;
Mariya 0:7f8127c43904 82 printf("Temperature: %d F\n\r", sample_ftemp);
Mariya 0:7f8127c43904 83
Mariya 0:7f8127c43904 84 sample_ctemp = temphumid.sample_ctemp();
Mariya 0:7f8127c43904 85 printf("Temperature: %d C\n\r", sample_ctemp);
Mariya 0:7f8127c43904 86
Mariya 0:7f8127c43904 87 sample_ktemp = temphumid.sample_ktemp();
Mariya 0:7f8127c43904 88 printf("Temperature: %d K\n\r", sample_ktemp);
Mariya 0:7f8127c43904 89
Mariya 0:7f8127c43904 90 sample_humid = temphumid.sample_humid();
Mariya 0:7f8127c43904 91 printf("Humidity: %d %%\n\r", sample_humid);
Mariya 0:7f8127c43904 92 printf("\n\r");
Mariya 0:7f8127c43904 93
Mariya 0:7f8127c43904 94 accel.acquire_accel_data_g(accel_data);
Mariya 0:7f8127c43904 95 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
Mariya 0:7f8127c43904 96 printf("Accelerometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\r",accel_data[0],accel_data[1],accel_data[2],accel_rms);
Mariya 0:7f8127c43904 97 wait(0.01);
Mariya 0:7f8127c43904 98 ax = accel_data[0];
Mariya 0:7f8127c43904 99 ay = accel_data[1];
Mariya 0:7f8127c43904 100 az = accel_data[2];
Mariya 0:7f8127c43904 101
Mariya 0:7f8127c43904 102 /* Get OLED Class Default Text Properties */
Mariya 0:7f8127c43904 103
Mariya 0:7f8127c43904 104 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 105 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 106 /*
Mariya 0:7f8127c43904 107 textProperties.fontColor = COLOR_WHITE;
Mariya 0:7f8127c43904 108 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 109 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 110 strcpy((char *) text,"");
Mariya 0:7f8127c43904 111 strcpy((char *) text,"ECE 595");
Mariya 0:7f8127c43904 112 oled.Label((uint8_t *)text,0,0);
Mariya 0:7f8127c43904 113 strcpy((char *) text," FITNESS MONITOR");
Mariya 0:7f8127c43904 114 oled.Label((uint8_t *)text,0,7);
Mariya 0:7f8127c43904 115 */
Mariya 0:7f8127c43904 116 /* Set text properties to white and right aligned for the dynamic text */
Mariya 0:7f8127c43904 117 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 118 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 119 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 120 if(sample_ftemp>70 && flag == 0)
Mariya 0:7f8127c43904 121 {
Mariya 0:7f8127c43904 122 textProperties.fontColor = COLOR_BLUE;
Mariya 0:7f8127c43904 123 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 124 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 125 flag=1;
Mariya 0:7f8127c43904 126 strcpy((char *) text,"Cool clothes!");
Mariya 0:7f8127c43904 127 oled.Label((uint8_t *)text,15,5);
Mariya 0:7f8127c43904 128 // sprintf(text,"%i",sample_ctemp);
Mariya 0:7f8127c43904 129 //oled.Label((uint8_t *)text,5,5);
Mariya 0:7f8127c43904 130
Mariya 0:7f8127c43904 131 strcpy((char *) text,"");
Mariya 0:7f8127c43904 132 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 133 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 134 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 135 strcpy((char *) text,"Temp.");
Mariya 0:7f8127c43904 136
Mariya 0:7f8127c43904 137 oled.Label((uint8_t *)text,5,67);
Mariya 0:7f8127c43904 138
Mariya 0:7f8127c43904 139 /* Format the value */
Mariya 0:7f8127c43904 140 sprintf(text,"%i",sample_ftemp);
Mariya 0:7f8127c43904 141 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 142 oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits
Mariya 0:7f8127c43904 143
Mariya 0:7f8127c43904 144 /* Display Units */
Mariya 0:7f8127c43904 145 strcpy((char *) text,"dF");
Mariya 0:7f8127c43904 146 oled.Label((uint8_t *)text,82,67);
Mariya 0:7f8127c43904 147 wait(5);
Mariya 0:7f8127c43904 148 //oled1.clear(BLACK);
Mariya 0:7f8127c43904 149 oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 150 }
Mariya 0:7f8127c43904 151 else if(sample_ftemp<60 && flag == 0)
Mariya 0:7f8127c43904 152 {
Mariya 0:7f8127c43904 153 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 154 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 155 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 156 flag=1;
Mariya 0:7f8127c43904 157 strcpy((char *) text,"Warm clothes!");
Mariya 0:7f8127c43904 158 oled.Label((uint8_t *)text,15,5);
Mariya 0:7f8127c43904 159 // sprintf(text,"%i",sample_ctemp);
Mariya 0:7f8127c43904 160 //oled.Label((uint8_t *)text,5,5);
Mariya 0:7f8127c43904 161
Mariya 0:7f8127c43904 162 strcpy((char *) text,"");
Mariya 0:7f8127c43904 163 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 164 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 165 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 166 strcpy((char *) text,"Temp.");
Mariya 0:7f8127c43904 167 oled.Label((uint8_t *)text,5,67);
Mariya 0:7f8127c43904 168
Mariya 0:7f8127c43904 169 /* Format the value */
Mariya 0:7f8127c43904 170 sprintf(text,"%i",sample_ftemp);
Mariya 0:7f8127c43904 171 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 172 oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits
Mariya 0:7f8127c43904 173
Mariya 0:7f8127c43904 174 /* Display Units */
Mariya 0:7f8127c43904 175 strcpy((char *) text,"dF");
Mariya 0:7f8127c43904 176 oled.Label((uint8_t *)text,82,67);
Mariya 0:7f8127c43904 177 wait(3);
Mariya 0:7f8127c43904 178 strcpy((char *) text,"");
Mariya 0:7f8127c43904 179 oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 180 }
Mariya 0:7f8127c43904 181 /*
Mariya 0:7f8127c43904 182 textProperties.fontColor = COLOR_WHITE;
Mariya 0:7f8127c43904 183 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 184 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 185 strcpy((char *) text,"");
Mariya 0:7f8127c43904 186 strcpy((char *) text,"ECE 595");
Mariya 0:7f8127c43904 187 oled.Label((uint8_t *)text,0,0);
Mariya 0:7f8127c43904 188 strcpy((char *) text," FITNESS MONITOR");
Mariya 0:7f8127c43904 189 oled.Label((uint8_t *)text,0,7);
Mariya 0:7f8127c43904 190 */
Mariya 0:7f8127c43904 191 //oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 192 /* Display Legends */
Mariya 0:7f8127c43904 193 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 194 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 195 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 196 strcpy((char *) text,"Temp.");
Mariya 0:7f8127c43904 197 oled.Label((uint8_t *)text,5,67);
Mariya 0:7f8127c43904 198
Mariya 0:7f8127c43904 199 /* Format the value */
Mariya 0:7f8127c43904 200 sprintf(text,"%i",sample_ftemp);
Mariya 0:7f8127c43904 201 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 202 oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits
Mariya 0:7f8127c43904 203
Mariya 0:7f8127c43904 204 /* Display Units */
Mariya 0:7f8127c43904 205 strcpy((char *) text,"dF");
Mariya 0:7f8127c43904 206 oled.Label((uint8_t *)text,82,67);
Mariya 0:7f8127c43904 207 /* Set text properties to white and right aligned for the dynamic text */
Mariya 0:7f8127c43904 208 textProperties.fontColor = COLOR_BLUE;
Mariya 0:7f8127c43904 209 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 210 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 211
Mariya 0:7f8127c43904 212 /* Display Legends */
Mariya 0:7f8127c43904 213 strcpy((char *) text,"Humidity");
Mariya 0:7f8127c43904 214 oled.Label((uint8_t *)text,5,81);
Mariya 0:7f8127c43904 215
Mariya 0:7f8127c43904 216 /* Format the value */
Mariya 0:7f8127c43904 217 sprintf(text,"%i",sample_humid);
Mariya 0:7f8127c43904 218 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 219 oled.TextBox((uint8_t *)text,57,81,20,15); //Increase textbox for more digits
Mariya 0:7f8127c43904 220
Mariya 0:7f8127c43904 221 /* Display Units */
Mariya 0:7f8127c43904 222 strcpy((char *) text,"%");
Mariya 0:7f8127c43904 223 oled.Label((uint8_t *)text,82,81);
Mariya 0:7f8127c43904 224 //pedometer
Mariya 0:7f8127c43904 225 textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 226 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 227 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 228 strcpy((char *) text1,"Steps:");
Mariya 0:7f8127c43904 229 oled.Label((uint8_t *)text1,3,35);
Mariya 0:7f8127c43904 230 acc=sqrt(pow(ax,2)+pow(ay,2)/2);
Mariya 0:7f8127c43904 231 textProperties.fontColor = COLOR_WHITE;
Mariya 0:7f8127c43904 232 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 233 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 234 strcpy((char *) text1,"Calories:");
Mariya 0:7f8127c43904 235 oled.Label((uint8_t *)text1,3,50);
Mariya 0:7f8127c43904 236 if(acc>0.3){
Mariya 0:7f8127c43904 237 wait(0.5);
Mariya 0:7f8127c43904 238 ped++;
Mariya 0:7f8127c43904 239 if(ped==oldped+36){
Mariya 0:7f8127c43904 240 cal++;
Mariya 0:7f8127c43904 241 oldped=ped;
Mariya 0:7f8127c43904 242 }
Mariya 0:7f8127c43904 243 }
Mariya 0:7f8127c43904 244 if(ped>25)
Mariya 0:7f8127c43904 245 {
Mariya 0:7f8127c43904 246 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 247 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 248 //oled1.clear(BLACK);
Mariya 0:7f8127c43904 249 //oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 250 wait(1);
Mariya 0:7f8127c43904 251 /* Get OLED Class Default Text Properties */
Mariya 0:7f8127c43904 252 //for(int i=0;i<5;i++)
Mariya 0:7f8127c43904 253 // {
Mariya 0:7f8127c43904 254
Mariya 0:7f8127c43904 255 /* Set text properties to white and right aligned for the dynamic text */
Mariya 0:7f8127c43904 256 textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 257 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 258 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 259 strcpy((char *) text,"");
Mariya 0:7f8127c43904 260 strcpy((char *) text,"TargetAchieved");
Mariya 0:7f8127c43904 261 oled.Label((uint8_t *)text,0,7);
Mariya 0:7f8127c43904 262 strcpy((char *) text,"");
Mariya 0:7f8127c43904 263 //sprintf(text,"%i", rand() % 5 + 62);
Mariya 0:7f8127c43904 264 //oled.Label((uint8_t *)text,70,7);
Mariya 0:7f8127c43904 265 //wait(7);
Mariya 0:7f8127c43904 266 }
Mariya 0:7f8127c43904 267 /* Format the value */
Mariya 0:7f8127c43904 268 textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 269 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 270 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 271 sprintf(text1,"%4d",ped);
Mariya 0:7f8127c43904 272 oled.TextBox((uint8_t *)text1,70,35,20,15); //Increase textbox for more digits
Mariya 0:7f8127c43904 273 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 274 textProperties.fontColor = COLOR_WHITE;
Mariya 0:7f8127c43904 275 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 276 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 277
Mariya 0:7f8127c43904 278 sprintf(text1,"%4d",cal);
Mariya 0:7f8127c43904 279 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 280 oled.TextBox((uint8_t *)text1,70,50,20,15);
Mariya 0:7f8127c43904 281 if(once==0)
Mariya 0:7f8127c43904 282 {
Mariya 0:7f8127c43904 283 wait(8);
Mariya 0:7f8127c43904 284 once=1;
Mariya 0:7f8127c43904 285 }
Mariya 0:7f8127c43904 286 }
Mariya 0:7f8127c43904 287
Mariya 0:7f8127c43904 288 }
Mariya 0:7f8127c43904 289
Mariya 0:7f8127c43904 290 void StartHaptic(void)
Mariya 0:7f8127c43904 291 {
Mariya 0:7f8127c43904 292 hapticTimer.start(30);
Mariya 0:7f8127c43904 293 haptic = 1;
Mariya 0:7f8127c43904 294 }
Mariya 0:7f8127c43904 295
Mariya 0:7f8127c43904 296 void StopHaptic(void const *n) {
Mariya 0:7f8127c43904 297 haptic = 0;
Mariya 0:7f8127c43904 298 hapticTimer.stop();
Mariya 0:7f8127c43904 299 }
Mariya 0:7f8127c43904 300
Mariya 0:7f8127c43904 301 void ButtonUp(void)
Mariya 0:7f8127c43904 302 {
Mariya 0:7f8127c43904 303 StartHaptic();
Mariya 0:7f8127c43904 304
Mariya 0:7f8127c43904 305 redLed = LED_ON;
Mariya 0:7f8127c43904 306 greenLed = LED_OFF;
Mariya 0:7f8127c43904 307 blueLed = LED_OFF;
Mariya 0:7f8127c43904 308 /* Fills the screen with solid black */
Mariya 0:7f8127c43904 309
Mariya 0:7f8127c43904 310
Mariya 0:7f8127c43904 311 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 312 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 313 //oled1.clear(BLACK);
Mariya 0:7f8127c43904 314 //oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 315 wait(1);
Mariya 0:7f8127c43904 316 /* Get OLED Class Default Text Properties */
Mariya 0:7f8127c43904 317 //for(int i=0;i<5;i++)
Mariya 0:7f8127c43904 318 // {
Mariya 0:7f8127c43904 319
Mariya 0:7f8127c43904 320 /* Set text properties to white and right aligned for the dynamic text */
Mariya 0:7f8127c43904 321 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 322 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 323 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 324 strcpy((char *) text,"");
Mariya 0:7f8127c43904 325 strcpy((char *) text,"Heart Rate");
Mariya 0:7f8127c43904 326 oled.Label((uint8_t *)text,0,20);
Mariya 0:7f8127c43904 327 strcpy((char *) text,"");
Mariya 0:7f8127c43904 328 sprintf(text,"00");
Mariya 0:7f8127c43904 329 oled.Label((uint8_t *)text,70,20);
Mariya 0:7f8127c43904 330 wait(2);
Mariya 0:7f8127c43904 331 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 332 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 333 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 334 sprintf(text,"%i",sample );
Mariya 0:7f8127c43904 335 oled.Label((uint8_t *)text,70,20);
Mariya 0:7f8127c43904 336
Mariya 0:7f8127c43904 337 if(sample>150){
Mariya 0:7f8127c43904 338 textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 339 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 340 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 341 strcpy((char *) text,"");
Mariya 0:7f8127c43904 342 strcpy((char *) text,"Slow Down");
Mariya 0:7f8127c43904 343 oled.Label((uint8_t *)text,0,7);
Mariya 0:7f8127c43904 344 strcpy((char *) text,"");
Mariya 0:7f8127c43904 345 }
Mariya 0:7f8127c43904 346 wait(8);
Mariya 0:7f8127c43904 347 //oled.FillScreen(COLOR_BLACK);
Mariya 0:7f8127c43904 348 //}
Mariya 0:7f8127c43904 349 // strcpy((char *) text,"");
Mariya 0:7f8127c43904 350 //oled.Label((uint8_t *)text,0,0);
Mariya 0:7f8127c43904 351 //oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 352 //oled.FillScreen(COLOR_BLACK);
Mariya 0:7f8127c43904 353 //oled1.clear(BLACK);
Mariya 0:7f8127c43904 354
Mariya 0:7f8127c43904 355 // StopHaptic(1);
Mariya 0:7f8127c43904 356 }
Mariya 0:7f8127c43904 357
Mariya 0:7f8127c43904 358
Mariya 0:7f8127c43904 359
Mariya 0:7f8127c43904 360 void ButtonDown(void)
Mariya 0:7f8127c43904 361 {
Mariya 0:7f8127c43904 362 StartHaptic();
Mariya 0:7f8127c43904 363
Mariya 0:7f8127c43904 364 redLed = LED_ON;
Mariya 0:7f8127c43904 365 greenLed = LED_OFF;
Mariya 0:7f8127c43904 366 blueLed = LED_OFF;
Mariya 0:7f8127c43904 367 /* Turn on the backlight of the OLED Display */
Mariya 0:7f8127c43904 368 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 369 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 370 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 371 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 372 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 373 sprintf(text,"%d",00);
Mariya 0:7f8127c43904 374 oled.Label((uint8_t *)text,70,20);
Mariya 0:7f8127c43904 375
Mariya 0:7f8127c43904 376 }
Mariya 0:7f8127c43904 377
Mariya 0:7f8127c43904 378 void ButtonRight(void)
Mariya 0:7f8127c43904 379 {
Mariya 0:7f8127c43904 380 StartHaptic();
Mariya 0:7f8127c43904 381
Mariya 0:7f8127c43904 382 redLed = LED_OFF;
Mariya 0:7f8127c43904 383 greenLed = LED_OFF;
Mariya 0:7f8127c43904 384 blueLed = LED_ON;
Mariya 0:7f8127c43904 385 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 386 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 387 //oled1.clear(BLACK);
Mariya 0:7f8127c43904 388 //oled.TextBox((uint8_t *)text,0,0,96,96);
Mariya 0:7f8127c43904 389 wait(1);
Mariya 0:7f8127c43904 390 /* Get OLED Class Default Text Properties */
Mariya 0:7f8127c43904 391 //for(int i=0;i<5;i++)
Mariya 0:7f8127c43904 392 // {
Mariya 0:7f8127c43904 393
Mariya 0:7f8127c43904 394 /* Set text properties to white and right aligned for the dynamic text */
Mariya 0:7f8127c43904 395 //if(bool maxim_max30102_init()==true){
Mariya 0:7f8127c43904 396 //maxim_max30102_read_fifo(0,0);
Mariya 0:7f8127c43904 397 /* textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 398 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Mariya 0:7f8127c43904 399 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 400 strcpy((char *) text1,"FEVER");
Mariya 0:7f8127c43904 401 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Mariya 0:7f8127c43904 402 /* oled.TextBox((uint8_t *)text1,70,50,20,15);
Mariya 0:7f8127c43904 403 wait(5);
Mariya 0:7f8127c43904 404 }
Mariya 0:7f8127c43904 405 /*textProperties.fontColor = COLOR_GREEN;
Mariya 0:7f8127c43904 406 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 407 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 408 strcpy((char *) text,"");
Mariya 0:7f8127c43904 409 strcpy((char *) text,"FEVER");
Mariya 0:7f8127c43904 410 oled.Label((uint8_t *)text,0,7);
Mariya 0:7f8127c43904 411 strcpy((char *) text,"");
Mariya 0:7f8127c43904 412 sprintf(text,"%i", rand() % 3 + 37);
Mariya 0:7f8127c43904 413 oled.Label((uint8_t *)text,70,7);
Mariya 0:7f8127c43904 414 wait(7);
Mariya 0:7f8127c43904 415 */
Mariya 0:7f8127c43904 416 oled.DimScreenON();
Mariya 0:7f8127c43904 417 }
Mariya 0:7f8127c43904 418
Mariya 0:7f8127c43904 419 void ButtonLeft(void)
Mariya 0:7f8127c43904 420 {
Mariya 0:7f8127c43904 421 StartHaptic();
Mariya 0:7f8127c43904 422
Mariya 0:7f8127c43904 423 redLed = LED_ON;
Mariya 0:7f8127c43904 424 greenLed = LED_ON;
Mariya 0:7f8127c43904 425 blueLed = LED_OFF;
Mariya 0:7f8127c43904 426 /*
Mariya 0:7f8127c43904 427 oled_text_properties_t textProperties = {0};
Mariya 0:7f8127c43904 428 oled.GetTextProperties(&textProperties);
Mariya 0:7f8127c43904 429 heart.enable();
Mariya 0:7f8127c43904 430 heart.heartRate_SendToKW40( data)
Mariya 0:7f8127c43904 431 textProperties.fontColor = COLOR_RED;
Mariya 0:7f8127c43904 432 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
Mariya 0:7f8127c43904 433 oled.SetTextProperties(&textProperties);
Mariya 0:7f8127c43904 434 strcpy((char *) text,"");
Mariya 0:7f8127c43904 435 strcpy((char *) text,"Heart Rate");
Mariya 0:7f8127c43904 436 oled.Label((uint8_t *)text,0,20);
Mariya 0:7f8127c43904 437 strcpy((char *) text,"");
Mariya 0:7f8127c43904 438 sprintf(text,"%i", data);
Mariya 0:7f8127c43904 439 oled.Label((uint8_t *)text,70,20);
Mariya 0:7f8127c43904 440 wait(7);
Mariya 0:7f8127c43904 441 */
Mariya 0:7f8127c43904 442 }
Mariya 0:7f8127c43904 443
Mariya 0:7f8127c43904 444 void ButtonSlide(void)
Mariya 0:7f8127c43904 445 {
Mariya 0:7f8127c43904 446 StartHaptic();
Mariya 0:7f8127c43904 447
Mariya 0:7f8127c43904 448 redLed = LED_ON;
Mariya 0:7f8127c43904 449 greenLed = LED_ON;
Mariya 0:7f8127c43904 450 blueLed = LED_ON;
Mariya 0:7f8127c43904 451 }