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