Here

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351 nRF24L01 FXOS8700

Committer:
tdh50
Date:
Wed Apr 26 16:41:30 2017 +0000
Revision:
21:6d54edeb2f33
Parent:
19:195a0891e8e9
Changed fall threshold

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Hexiwear-Alert-System 0:6384ad26fe6c 1 #include "mbed.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 2 #include "Hexi_KW40Z.h"
tdh50 5:09837d22b28f 3 #include "FXOS8700.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 4 #include "Hexi_OLED_SSD1351.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 5 #include "OLED_types.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 6 #include "OpenSans_Font.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 7 #include "nRF24L01P.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 8 #include "string.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 9 #include "images.h"
group-Hexiwear-Alert-System 0:6384ad26fe6c 10
tdh50 16:b09f27c2dbe7 11
group-Hexiwear-Alert-System 0:6384ad26fe6c 12 #define NAME "RB"
group-Hexiwear-Alert-System 0:6384ad26fe6c 13
group-Hexiwear-Alert-System 0:6384ad26fe6c 14 #define LED_ON 0
group-Hexiwear-Alert-System 0:6384ad26fe6c 15 #define LED_OFF 1
group-Hexiwear-Alert-System 0:6384ad26fe6c 16 #define TRANSFER_SIZE 4
tdh50 3:065e8a7824d4 17
group-Hexiwear-Alert-System 0:6384ad26fe6c 18 void StartHaptic(void);
group-Hexiwear-Alert-System 0:6384ad26fe6c 19 void StopHaptic(void const *n);
tdh50 12:8db1b8fb5866 20 void txTask(void);
tdh50 5:09837d22b28f 21 void accelero(void);
tdh50 7:46729d931f26 22 void drawAccel(void);
tdh50 3:065e8a7824d4 23 void displayHome();
tdh50 16:b09f27c2dbe7 24
group-Hexiwear-Alert-System 0:6384ad26fe6c 25
tdh50 12:8db1b8fb5866 26
group-Hexiwear-Alert-System 0:6384ad26fe6c 27 DigitalOut redLed(LED1,1);
group-Hexiwear-Alert-System 0:6384ad26fe6c 28 DigitalOut greenLed(LED2,1);
group-Hexiwear-Alert-System 0:6384ad26fe6c 29 DigitalOut blueLed(LED3,1);
group-Hexiwear-Alert-System 0:6384ad26fe6c 30 DigitalOut haptic(PTB9);
group-Hexiwear-Alert-System 0:6384ad26fe6c 31
tdh50 11:deecd2b72129 32 // Define timer for haptic feedback
group-Hexiwear-Alert-System 0:6384ad26fe6c 33 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
tdh50 16:b09f27c2dbe7 34 // Instantiates the FX0S8700 accelerometer driver
tdh50 5:09837d22b28f 35 FXOS8700 accel(PTC11, PTC10);
tdh50 11:deecd2b72129 36 // Instantiate the Hexi KW40Z Driver (UART TX, UART RX)
group-Hexiwear-Alert-System 0:6384ad26fe6c 37 KW40Z kw40z_device(PTE24, PTE25);
tdh50 5:09837d22b28f 38 Serial pc(USBTX, USBRX); // Serial interface
tdh50 11:deecd2b72129 39 // Instantiate the SSD1351 OLED Driver
tdh50 11:deecd2b72129 40 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
group-Hexiwear-Alert-System 0:6384ad26fe6c 41 oled_text_properties_t textProperties = {0};
tdh50 12:8db1b8fb5866 42
tdh50 12:8db1b8fb5866 43
tdh50 12:8db1b8fb5866 44 /*Create a Thread to handle sending BLE Sensor Data */
tdh50 12:8db1b8fb5866 45 Thread txThread;
tdh50 12:8db1b8fb5866 46
tdh50 11:deecd2b72129 47 // Text Buffer
tdh50 5:09837d22b28f 48 char text1[20]; // Text Buffer for dynamic value displayed
tdh50 5:09837d22b28f 49 char text2[20]; // Text Buffer for dynamic value displayed
tdh50 5:09837d22b28f 50 char text3[20]; // Text Buffer for dynamic value displayed
tdh50 16:b09f27c2dbe7 51 char pass [20]; // Passcode
group-Hexiwear-Alert-System 0:6384ad26fe6c 52
tdh50 19:195a0891e8e9 53 bool power = 1; // Contol for oled Power
tdh50 5:09837d22b28f 54 float accel_data[3]; // Storage for the data from the sensor
tdh50 18:9e23169b297a 55 double accel_rms=0.0; // RMS value from the sensor
group-Hexiwear-Alert-System 0:6384ad26fe6c 56 uint8_t screenNum=0;
tdh50 16:b09f27c2dbe7 57 bool alert = false; //Sets alarm to zero
tdh50 16:b09f27c2dbe7 58 uint8_t previous; //Keeps track of previous screen
tdh50 16:b09f27c2dbe7 59 bool trigger = false;
group-Hexiwear-Alert-System 0:6384ad26fe6c 60 bool sentMessageDisplayedFlag=0;
group-Hexiwear-Alert-System 0:6384ad26fe6c 61 char rxData[TRANSFER_SIZE];
tdh50 16:b09f27c2dbe7 62 char txData[TRANSFER_SIZE];//Data send via BLE
tdh50 19:195a0891e8e9 63 int16_t x=0,y=0,z=0;
group-Hexiwear-Alert-System 0:6384ad26fe6c 64
tdh50 11:deecd2b72129 65 // Pointer for the image to be displayed
tdh50 3:065e8a7824d4 66 const uint8_t *HeartBMP = HeartRate_bmp;
tdh50 3:065e8a7824d4 67 const uint8_t *FallBMP = FallDet_bmp;
tdh50 3:065e8a7824d4 68 const uint8_t *FallPageBMP = FallDetPage_bmp;
tdh50 3:065e8a7824d4 69 const uint8_t *HomeBMP = Home_bmp;
tdh50 3:065e8a7824d4 70 const uint8_t *HeartPageBMP = HeartRatePage_bmp;
DeanBritt 8:5532a9c895be 71 const uint8_t *AlertBMP = Alert_bmp;
DeanBritt 2:172492c41c48 72
tdh50 11:deecd2b72129 73 //***************************Call Back Functions******************************
tdh50 11:deecd2b72129 74 //Enter Button
group-Hexiwear-Alert-System 0:6384ad26fe6c 75 void ButtonRight(void)
group-Hexiwear-Alert-System 0:6384ad26fe6c 76 {
tdh50 7:46729d931f26 77 // All screens other than 1 have either and enter button
tdh50 7:46729d931f26 78 // or a home buttom.
tdh50 19:195a0891e8e9 79 if(screenNum != 0 && power) {
group-Hexiwear-Alert-System 0:6384ad26fe6c 80 StartHaptic();
tdh50 3:065e8a7824d4 81 switch(screenNum) {
DeanBritt 14:9e6b87e322a2 82 case 1: {
tdh50 16:b09f27c2dbe7 83 screenNum = screenNum + 2;
tdh50 3:065e8a7824d4 84 break;
tdh50 3:065e8a7824d4 85 }
tdh50 3:065e8a7824d4 86 case 2: {
tdh50 3:065e8a7824d4 87 screenNum = screenNum + 2;
tdh50 16:b09f27c2dbe7 88 trigger = true;
tdh50 3:065e8a7824d4 89 break;
tdh50 3:065e8a7824d4 90 }
DeanBritt 14:9e6b87e322a2 91 case 3:
DeanBritt 14:9e6b87e322a2 92 case 4: {
tdh50 3:065e8a7824d4 93 screenNum = 0;
tdh50 3:065e8a7824d4 94 break;
tdh50 3:065e8a7824d4 95 }
DeanBritt 14:9e6b87e322a2 96 case 5: {
tdh50 16:b09f27c2dbe7 97 screenNum = previous;
tdh50 16:b09f27c2dbe7 98 alert = false;
tdh50 11:deecd2b72129 99 break;
tdh50 11:deecd2b72129 100 }
tdh50 3:065e8a7824d4 101 default: {
tdh50 3:065e8a7824d4 102 break;
tdh50 3:065e8a7824d4 103 }
tdh50 3:065e8a7824d4 104 }
tdh50 19:195a0891e8e9 105 } else if(screenNum == 0 && power) {
tdh50 19:195a0891e8e9 106 power = 0;
tdh50 19:195a0891e8e9 107 oled.PowerOFF();
tdh50 19:195a0891e8e9 108 } else {
tdh50 19:195a0891e8e9 109 oled.PowerON();
tdh50 19:195a0891e8e9 110 power = 1;
group-Hexiwear-Alert-System 0:6384ad26fe6c 111 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 112 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 113
tdh50 11:deecd2b72129 114 //Back Button
group-Hexiwear-Alert-System 0:6384ad26fe6c 115 void ButtonLeft(void)
group-Hexiwear-Alert-System 0:6384ad26fe6c 116 {
tdh50 19:195a0891e8e9 117 if(power) {
tdh50 19:195a0891e8e9 118 if(screenNum > 0 && screenNum != 5) {
tdh50 19:195a0891e8e9 119 StartHaptic();
tdh50 19:195a0891e8e9 120 //Allow user to go back to correct screen based on srceen number
tdh50 19:195a0891e8e9 121 if(screenNum == 2 || screenNum == 3 || screenNum == 4) {
tdh50 19:195a0891e8e9 122 screenNum = screenNum - 2;
tdh50 19:195a0891e8e9 123 } else {
tdh50 19:195a0891e8e9 124 screenNum--;
tdh50 19:195a0891e8e9 125 }
tdh50 21:6d54edeb2f33 126 } else if(alert == false) {
tdh50 19:195a0891e8e9 127 screenNum = 5;
tdh50 11:deecd2b72129 128 }
tdh50 21:6d54edeb2f33 129 StartHaptic();
DeanBritt 8:5532a9c895be 130 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 131 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 132
tdh50 7:46729d931f26 133 //Advances to Heartrate only when user
tdh50 11:deecd2b72129 134 //is on Hexisafe screen
group-Hexiwear-Alert-System 0:6384ad26fe6c 135 void ButtonUp(void)
group-Hexiwear-Alert-System 0:6384ad26fe6c 136 {
tdh50 19:195a0891e8e9 137 if (screenNum == 0 && power) {
group-Hexiwear-Alert-System 0:6384ad26fe6c 138 StartHaptic();
tdh50 3:065e8a7824d4 139 screenNum++;
tdh50 3:065e8a7824d4 140 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 141
tdh50 3:065e8a7824d4 142
group-Hexiwear-Alert-System 0:6384ad26fe6c 143 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 144
tdh50 7:46729d931f26 145 //Advances to Fall Detection only when user
tdh50 11:deecd2b72129 146 //is on Hexisafe screen
group-Hexiwear-Alert-System 0:6384ad26fe6c 147 void ButtonDown(void)
group-Hexiwear-Alert-System 0:6384ad26fe6c 148 {
tdh50 19:195a0891e8e9 149 if (screenNum == 0 && power) {
tdh50 3:065e8a7824d4 150 StartHaptic();
tdh50 3:065e8a7824d4 151 screenNum= screenNum + 2;
tdh50 16:b09f27c2dbe7 152
group-Hexiwear-Alert-System 0:6384ad26fe6c 153 }
tdh50 3:065e8a7824d4 154
group-Hexiwear-Alert-System 0:6384ad26fe6c 155 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 156
tdh50 12:8db1b8fb5866 157 void PassKey(void)
tdh50 12:8db1b8fb5866 158 {
tdh50 12:8db1b8fb5866 159 StartHaptic();
tdh50 16:b09f27c2dbe7 160 strcpy((char *) pass,"PAIR CODE");
tdh50 16:b09f27c2dbe7 161 oled.TextBox((uint8_t *)pass,0,25,95,18);
tdh50 12:8db1b8fb5866 162
tdh50 12:8db1b8fb5866 163 /* Display Bond Pass Key in a 95px by 18px textbox at x=0,y=40 */
tdh50 16:b09f27c2dbe7 164 sprintf(pass,"%d", kw40z_device.GetPassKey());
tdh50 16:b09f27c2dbe7 165 oled.TextBox((uint8_t *)pass,0,40,95,18);
tdh50 12:8db1b8fb5866 166 }
tdh50 12:8db1b8fb5866 167
group-Hexiwear-Alert-System 0:6384ad26fe6c 168
tdh50 11:deecd2b72129 169 //**********************End of Call Back Functions****************************
group-Hexiwear-Alert-System 0:6384ad26fe6c 170
tdh50 11:deecd2b72129 171 //*******************************Main*****************************************
group-Hexiwear-Alert-System 0:6384ad26fe6c 172
group-Hexiwear-Alert-System 0:6384ad26fe6c 173 int main()
tdh50 3:065e8a7824d4 174 {
tdh50 11:deecd2b72129 175 accel.accel_config();
tdh50 21:6d54edeb2f33 176
tdh50 21:6d54edeb2f33 177 oled.FillScreen(COLOR_BLACK);
tdh50 21:6d54edeb2f33 178
tdh50 3:065e8a7824d4 179
tdh50 16:b09f27c2dbe7 180 // Get & set OLED Class Default Text Properties
tdh50 3:065e8a7824d4 181 oled.GetTextProperties(&textProperties);
tdh50 16:b09f27c2dbe7 182 oled_text_properties_t textProperties = {0};
tdh50 16:b09f27c2dbe7 183 oled.SetTextProperties(&textProperties);
tdh50 19:195a0891e8e9 184
tdh50 11:deecd2b72129 185 // Register callbacks to application functions
group-Hexiwear-Alert-System 0:6384ad26fe6c 186 kw40z_device.attach_buttonLeft(&ButtonLeft);
group-Hexiwear-Alert-System 0:6384ad26fe6c 187 kw40z_device.attach_buttonRight(&ButtonRight);
group-Hexiwear-Alert-System 0:6384ad26fe6c 188 kw40z_device.attach_buttonUp(&ButtonUp);
group-Hexiwear-Alert-System 0:6384ad26fe6c 189 kw40z_device.attach_buttonDown(&ButtonDown);
tdh50 19:195a0891e8e9 190
tdh50 16:b09f27c2dbe7 191 uint8_t num = 0;
tdh50 16:b09f27c2dbe7 192 displayHome();
tdh50 12:8db1b8fb5866 193
tdh50 12:8db1b8fb5866 194 //Passcode
tdh50 12:8db1b8fb5866 195 kw40z_device.attach_passkey(&PassKey);
tdh50 3:065e8a7824d4 196
tdh50 16:b09f27c2dbe7 197 //Change font color to white
group-Hexiwear-Alert-System 0:6384ad26fe6c 198 textProperties.fontColor = COLOR_WHITE;
tdh50 21:6d54edeb2f33 199 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
tdh50 12:8db1b8fb5866 200
tdh50 19:195a0891e8e9 201 txThread.start(txTask); //Start transmitting Sensor Tag Data
tdh50 3:065e8a7824d4 202
tdh50 21:6d54edeb2f33 203
tdh50 3:065e8a7824d4 204 while (true) {
tdh50 11:deecd2b72129 205 accel.acquire_accel_data_g(accel_data);
tdh50 11:deecd2b72129 206 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
tdh50 12:8db1b8fb5866 207 x = accel_data[0] *10000;
tdh50 12:8db1b8fb5866 208 y = accel_data[1] *10000;
tdh50 12:8db1b8fb5866 209 z = accel_data[2] *10000;
tdh50 18:9e23169b297a 210
tdh50 21:6d54edeb2f33 211
tdh50 21:6d54edeb2f33 212
tdh50 18:9e23169b297a 213 // Check screen, alert and num values
tdh50 18:9e23169b297a 214 //printf("Screen = %i Num = %i alert = %d\n\r",screenNum,num,alert);
tdh50 18:9e23169b297a 215 // Check Fall Data
tdh50 16:b09f27c2dbe7 216 //printf("%4.4f\n\r",accel_rms);
tdh50 21:6d54edeb2f33 217 if(accel_rms*10 > 14.0 && alert == false) { //Triggers AlertBMP if fall is detected
tdh50 16:b09f27c2dbe7 218 oled.DrawImage(AlertBMP,0,0);
tdh50 16:b09f27c2dbe7 219 previous = screenNum;//Allows to return to previous screen.
tdh50 16:b09f27c2dbe7 220 num = screenNum - 1;//^
tdh50 16:b09f27c2dbe7 221 screenNum = 5;
tdh50 16:b09f27c2dbe7 222 alert = true;
tdh50 19:195a0891e8e9 223 trigger = true;
tdh50 19:195a0891e8e9 224
tdh50 18:9e23169b297a 225 }
tdh50 18:9e23169b297a 226 //Trigger Blinking Red LED when alarm is set off
tdh50 19:195a0891e8e9 227 if(alert == true) {
tdh50 19:195a0891e8e9 228 redLed = !redLed;
tdh50 21:6d54edeb2f33 229 hapticTimer.start(30);
tdh50 21:6d54edeb2f33 230 haptic = 1;
tdh50 11:deecd2b72129 231 }
tdh50 16:b09f27c2dbe7 232 if((screenNum != num && alert == false) || screenNum == 4) {
tdh50 19:195a0891e8e9 233 redLed = 1;
tdh50 16:b09f27c2dbe7 234 switch(screenNum) {
tdh50 16:b09f27c2dbe7 235 case 0: {
tdh50 16:b09f27c2dbe7 236 displayHome();
tdh50 16:b09f27c2dbe7 237 num = screenNum;
tdh50 16:b09f27c2dbe7 238 break;
tdh50 16:b09f27c2dbe7 239 }
tdh50 16:b09f27c2dbe7 240 case 1: {
tdh50 16:b09f27c2dbe7 241 //Switching to HeartBMP
tdh50 16:b09f27c2dbe7 242 oled.DrawImage(HeartBMP,0,0);
tdh50 16:b09f27c2dbe7 243 num = screenNum;
tdh50 16:b09f27c2dbe7 244 break;
tdh50 16:b09f27c2dbe7 245 }
tdh50 16:b09f27c2dbe7 246 case 2: {
tdh50 16:b09f27c2dbe7 247 //Switching to FallBMP
tdh50 16:b09f27c2dbe7 248 oled.DrawImage(FallBMP,0,0);
tdh50 16:b09f27c2dbe7 249 num = screenNum;
tdh50 16:b09f27c2dbe7 250 break;
tdh50 16:b09f27c2dbe7 251 }
tdh50 16:b09f27c2dbe7 252 case 3: {
tdh50 16:b09f27c2dbe7 253 //Switching to HeartPageBMP
tdh50 16:b09f27c2dbe7 254 oled.DrawImage(HeartPageBMP,0,0);
tdh50 16:b09f27c2dbe7 255 num = screenNum;
tdh50 16:b09f27c2dbe7 256 break;
tdh50 16:b09f27c2dbe7 257 }
tdh50 16:b09f27c2dbe7 258 case 4: {
tdh50 16:b09f27c2dbe7 259 //Switching to FallPageBMP
tdh50 16:b09f27c2dbe7 260 if(trigger == true) {
tdh50 18:9e23169b297a 261 oled.DrawImage(FallPageBMP,0,0);
tdh50 18:9e23169b297a 262 //Only allows draw image to occur once
tdh50 16:b09f27c2dbe7 263 trigger = false;
tdh50 16:b09f27c2dbe7 264 }
tdh50 18:9e23169b297a 265 num = screenNum;
tdh50 16:b09f27c2dbe7 266 drawAccel();
tdh50 16:b09f27c2dbe7 267 break;
tdh50 16:b09f27c2dbe7 268 }
tdh50 16:b09f27c2dbe7 269 case 5: {
tdh50 16:b09f27c2dbe7 270 //Switching to alarm
tdh50 16:b09f27c2dbe7 271 oled.DrawImage(AlertBMP,0,0);
tdh50 16:b09f27c2dbe7 272 num = screenNum;
tdh50 16:b09f27c2dbe7 273 break;
tdh50 16:b09f27c2dbe7 274 }
tdh50 16:b09f27c2dbe7 275 default: {
tdh50 16:b09f27c2dbe7 276 break;
tdh50 16:b09f27c2dbe7 277 }
tdh50 16:b09f27c2dbe7 278 }
tdh50 16:b09f27c2dbe7 279 }
tdh50 16:b09f27c2dbe7 280 Thread::wait(100);
group-Hexiwear-Alert-System 0:6384ad26fe6c 281 }
tdh50 12:8db1b8fb5866 282
tdh50 12:8db1b8fb5866 283
group-Hexiwear-Alert-System 0:6384ad26fe6c 284 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 285
tdh50 11:deecd2b72129 286 //*****************************End of Main************************************
tdh50 3:065e8a7824d4 287 //Intiates Vibration
tdh50 3:065e8a7824d4 288 void StartHaptic(void)
tdh50 3:065e8a7824d4 289 {
group-Hexiwear-Alert-System 0:6384ad26fe6c 290 hapticTimer.start(50);
group-Hexiwear-Alert-System 0:6384ad26fe6c 291 haptic = 1;
group-Hexiwear-Alert-System 0:6384ad26fe6c 292 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 293
tdh50 3:065e8a7824d4 294 void StopHaptic(void const *n)
tdh50 3:065e8a7824d4 295 {
group-Hexiwear-Alert-System 0:6384ad26fe6c 296 haptic = 0;
group-Hexiwear-Alert-System 0:6384ad26fe6c 297 hapticTimer.stop();
group-Hexiwear-Alert-System 0:6384ad26fe6c 298 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 299
tdh50 18:9e23169b297a 300
tdh50 3:065e8a7824d4 301 void displayHome(void)
group-Hexiwear-Alert-System 0:6384ad26fe6c 302 {
tdh50 3:065e8a7824d4 303 oled.DrawImage(HomeBMP,0,0);
tdh50 3:065e8a7824d4 304 }
group-Hexiwear-Alert-System 0:6384ad26fe6c 305
tdh50 18:9e23169b297a 306 // drawAccel() Draws the accelerometer values to screen
tdh50 11:deecd2b72129 307 void drawAccel(void)
tdh50 11:deecd2b72129 308 {
tdh50 5:09837d22b28f 309
tdh50 12:8db1b8fb5866 310 textProperties.fontColor = COLOR_GREEN;
tdh50 11:deecd2b72129 311 textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
tdh50 11:deecd2b72129 312 oled.SetTextProperties(&textProperties);
tdh50 5:09837d22b28f 313
tdh50 11:deecd2b72129 314 // Display Legends
tdh50 11:deecd2b72129 315 strcpy((char *) text1,"X-Axis (g):");
tdh50 11:deecd2b72129 316 oled.Label((uint8_t *)text1,5,26);
tdh50 11:deecd2b72129 317 strcpy((char *) text2,"Y-Axis (g):");
tdh50 11:deecd2b72129 318 oled.Label((uint8_t *)text2,5,43);
tdh50 11:deecd2b72129 319 strcpy((char *) text3,"Z-Axis (g):");
tdh50 11:deecd2b72129 320 oled.Label((uint8_t *)text3,5,60);
tdh50 7:46729d931f26 321
tdh50 11:deecd2b72129 322 // Format the value
tdh50 12:8db1b8fb5866 323 sprintf(text1,"%4.2f", accel_data[0]);
tdh50 12:8db1b8fb5866 324 // Display time reading in 35px by 15px textbox at(x=55, y=40)
tdh50 12:8db1b8fb5866 325 oled.TextBox((uint8_t *)text1,70,26,20,15); //Increase textbox for more digits
tdh50 12:8db1b8fb5866 326
tdh50 12:8db1b8fb5866 327 // Format the value
tdh50 12:8db1b8fb5866 328 sprintf(text2,"%4.2f",accel_data[1]);
tdh50 12:8db1b8fb5866 329 // Display time reading in 35px by 15px textbox at(x=55, y=40)
tdh50 12:8db1b8fb5866 330 oled.TextBox((uint8_t *)text2,70,43,20,15); //Increase textbox for more digits
tdh50 12:8db1b8fb5866 331
tdh50 12:8db1b8fb5866 332
tdh50 12:8db1b8fb5866 333 // Format the value
tdh50 12:8db1b8fb5866 334 sprintf(text3,"%4.2f", accel_data[2]);
tdh50 11:deecd2b72129 335 // Display time reading in 35px by 15px textbox at(x=55, y=40)
tdh50 11:deecd2b72129 336 oled.TextBox((uint8_t *)text3,70,60,20,15); //Increase textbox for more digits
tdh50 7:46729d931f26 337
tdh50 11:deecd2b72129 338 }
tdh50 12:8db1b8fb5866 339
tdh50 12:8db1b8fb5866 340 // txTask() transmits the sensor data
tdh50 12:8db1b8fb5866 341 void txTask(void)
tdh50 11:deecd2b72129 342 {
tdh50 12:8db1b8fb5866 343 while (true) {
tdh50 12:8db1b8fb5866 344 //UpdateSensorData();
tdh50 12:8db1b8fb5866 345 kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
tdh50 12:8db1b8fb5866 346 //Send Accel Data.
tdh50 12:8db1b8fb5866 347 kw40z_device.SendAccel(x,y,z);
tdh50 16:b09f27c2dbe7 348 Thread::wait(1000);
tdh50 7:46729d931f26 349 }
tdh50 16:b09f27c2dbe7 350 }