![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Here
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351 nRF24L01 FXOS8700
main.cpp@11:deecd2b72129, 2017-03-14 (annotated)
- Committer:
- tdh50
- Date:
- Tue Mar 14 17:44:20 2017 +0000
- Revision:
- 11:deecd2b72129
- Parent:
- 9:5e63a3928e43
- Child:
- 12:8db1b8fb5866
Fixed;
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 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 11 | #define NAME "RB" |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 12 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 13 | #define LED_ON 0 |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 14 | #define LED_OFF 1 |
tdh50 | 3:065e8a7824d4 | 15 | #define NUM_OF_SCREENS 4 |
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 | 11:deecd2b72129 | 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 | 11:deecd2b72129 | 24 | void displayTimer(); |
tdh50 | 3:065e8a7824d4 | 25 | void screenHandler(uint8_t screen); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 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 | 11:deecd2b72129 | 34 | // |
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 | 11:deecd2b72129 | 42 | // Instantiate the nRF24L01P Driver |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 43 | nRF24L01P my_nrf24l01p(PTC6,PTC7,PTC5,PTC4,PTB2,NC); // mosi, miso, sck, csn, ce, irq |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 44 | |
tdh50 | 11:deecd2b72129 | 45 | // Text Buffer |
tdh50 | 5:09837d22b28f | 46 | char text1[20]; // Text Buffer for dynamic value displayed |
tdh50 | 5:09837d22b28f | 47 | char text2[20]; // Text Buffer for dynamic value displayed |
tdh50 | 5:09837d22b28f | 48 | char text3[20]; // Text Buffer for dynamic value displayed |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 49 | |
tdh50 | 5:09837d22b28f | 50 | float accel_data[3]; // Storage for the data from the sensor |
tdh50 | 5:09837d22b28f | 51 | float accel_rms=0.0; // RMS value from the sensor |
tdh50 | 5:09837d22b28f | 52 | float ax, ay, az; // Integer value from the sensor to be displayed |
tdh50 | 11:deecd2b72129 | 53 | uint8_t timer = 30; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 54 | uint8_t screenNum=0; |
tdh50 | 3:065e8a7824d4 | 55 | bool prefix=0; |
tdh50 | 5:09837d22b28f | 56 | bool accelerometer = false; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 57 | bool sentMessageDisplayedFlag=0; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 58 | char rxData[TRANSFER_SIZE]; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 59 | char txData[TRANSFER_SIZE]; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 60 | |
tdh50 | 11:deecd2b72129 | 61 | // Pointer for the image to be displayed |
DeanBritt | 2:172492c41c48 | 62 | const uint8_t *SafeBMP = HexiSafe96_bmp; |
tdh50 | 3:065e8a7824d4 | 63 | const uint8_t *HeartBMP = HeartRate_bmp; |
tdh50 | 3:065e8a7824d4 | 64 | const uint8_t *FallBMP = FallDet_bmp; |
tdh50 | 3:065e8a7824d4 | 65 | const uint8_t *FallPageBMP = FallDetPage_bmp; |
tdh50 | 3:065e8a7824d4 | 66 | const uint8_t *HomeBMP = Home_bmp; |
tdh50 | 3:065e8a7824d4 | 67 | const uint8_t *HeartPageBMP = HeartRatePage_bmp; |
DeanBritt | 8:5532a9c895be | 68 | const uint8_t *AlertBMP = Alert_bmp; |
DeanBritt | 2:172492c41c48 | 69 | |
tdh50 | 3:065e8a7824d4 | 70 | |
tdh50 | 11:deecd2b72129 | 71 | //***************************Call Back Functions****************************** |
tdh50 | 11:deecd2b72129 | 72 | //Enter Button |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 73 | void ButtonRight(void) |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 74 | { |
tdh50 | 7:46729d931f26 | 75 | // All screens other than 1 have either and enter button |
tdh50 | 7:46729d931f26 | 76 | // or a home buttom. |
tdh50 | 3:065e8a7824d4 | 77 | if(screenNum != 1) { |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 78 | StartHaptic(); |
tdh50 | 3:065e8a7824d4 | 79 | switch(screenNum) { |
tdh50 | 3:065e8a7824d4 | 80 | case 0: { |
tdh50 | 3:065e8a7824d4 | 81 | screenNum++; |
tdh50 | 3:065e8a7824d4 | 82 | screenHandler(screenNum); |
tdh50 | 3:065e8a7824d4 | 83 | break; |
tdh50 | 3:065e8a7824d4 | 84 | } |
tdh50 | 3:065e8a7824d4 | 85 | case 2: { |
tdh50 | 3:065e8a7824d4 | 86 | screenNum = screenNum + 2; |
tdh50 | 3:065e8a7824d4 | 87 | screenHandler(screenNum); |
tdh50 | 3:065e8a7824d4 | 88 | break; |
tdh50 | 3:065e8a7824d4 | 89 | } |
tdh50 | 3:065e8a7824d4 | 90 | case 3: { |
tdh50 | 3:065e8a7824d4 | 91 | screenNum = screenNum + 2; |
tdh50 | 3:065e8a7824d4 | 92 | screenHandler(screenNum); |
tdh50 | 3:065e8a7824d4 | 93 | break; |
tdh50 | 3:065e8a7824d4 | 94 | } |
tdh50 | 3:065e8a7824d4 | 95 | case 4: |
tdh50 | 3:065e8a7824d4 | 96 | case 5: { |
tdh50 | 5:09837d22b28f | 97 | accelerometer = false; |
tdh50 | 3:065e8a7824d4 | 98 | screenNum = 0; |
tdh50 | 3:065e8a7824d4 | 99 | break; |
tdh50 | 3:065e8a7824d4 | 100 | } |
tdh50 | 11:deecd2b72129 | 101 | case 6: { |
tdh50 | 11:deecd2b72129 | 102 | screenNum = 0; |
tdh50 | 11:deecd2b72129 | 103 | break; |
tdh50 | 11:deecd2b72129 | 104 | } |
tdh50 | 3:065e8a7824d4 | 105 | default: { |
tdh50 | 3:065e8a7824d4 | 106 | break; |
tdh50 | 3:065e8a7824d4 | 107 | } |
tdh50 | 3:065e8a7824d4 | 108 | } |
tdh50 | 5:09837d22b28f | 109 | screenHandler(screenNum); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 110 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 111 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 112 | |
tdh50 | 11:deecd2b72129 | 113 | //Back Button |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 114 | void ButtonLeft(void) |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 115 | { |
tdh50 | 11:deecd2b72129 | 116 | StartHaptic(); |
tdh50 | 3:065e8a7824d4 | 117 | if(screenNum > 0) { |
tdh50 | 3:065e8a7824d4 | 118 | //Allow user to go back to correct screen based on srceen number |
tdh50 | 3:065e8a7824d4 | 119 | //Refer to screenHandler for screen numbers |
tdh50 | 3:065e8a7824d4 | 120 | if(screenNum == 3 || screenNum == 4 || screenNum == 5) { |
tdh50 | 3:065e8a7824d4 | 121 | screenNum = screenNum - 2; |
tdh50 | 5:09837d22b28f | 122 | accelerometer = false; |
tdh50 | 7:46729d931f26 | 123 | } else { |
tdh50 | 3:065e8a7824d4 | 124 | screenNum--; |
tdh50 | 11:deecd2b72129 | 125 | } |
tdh50 | 11:deecd2b72129 | 126 | } else { |
tdh50 | 11:deecd2b72129 | 127 | screenNum = 6; |
DeanBritt | 8:5532a9c895be | 128 | } |
tdh50 | 11:deecd2b72129 | 129 | screenHandler(screenNum); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 130 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 131 | |
tdh50 | 7:46729d931f26 | 132 | //Advances to Heartrate only when user |
tdh50 | 11:deecd2b72129 | 133 | //is on Hexisafe screen |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 134 | void ButtonUp(void) |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 135 | { |
tdh50 | 3:065e8a7824d4 | 136 | if (screenNum == 1) { |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 137 | StartHaptic(); |
tdh50 | 3:065e8a7824d4 | 138 | screenNum++; |
tdh50 | 3:065e8a7824d4 | 139 | screenHandler(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 | 3:065e8a7824d4 | 149 | if (screenNum == 1) { |
tdh50 | 3:065e8a7824d4 | 150 | StartHaptic(); |
tdh50 | 3:065e8a7824d4 | 151 | screenNum= screenNum + 2; |
tdh50 | 3:065e8a7824d4 | 152 | screenHandler(screenNum); |
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 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 157 | |
tdh50 | 11:deecd2b72129 | 158 | //**********************End of Call Back Functions**************************** |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 159 | |
tdh50 | 11:deecd2b72129 | 160 | //*******************************Main***************************************** |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 161 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 162 | int main() |
tdh50 | 3:065e8a7824d4 | 163 | { |
tdh50 | 11:deecd2b72129 | 164 | // Wait Sequence in the beginning for board to be reset then placed in mini docking station |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 165 | blueLed=1; |
tdh50 | 11:deecd2b72129 | 166 | accel.accel_config(); |
tdh50 | 11:deecd2b72129 | 167 | //oled.DrawImage(FallPageBMP,0,0); |
tdh50 | 11:deecd2b72129 | 168 | int count = 0;// count data reading for accelerometer |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 169 | |
tdh50 | 3:065e8a7824d4 | 170 | |
tdh50 | 11:deecd2b72129 | 171 | // Get OLED Class Default Text Properties |
tdh50 | 3:065e8a7824d4 | 172 | oled.GetTextProperties(&textProperties); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 173 | |
tdh50 | 11:deecd2b72129 | 174 | // Register callbacks to application functions |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 175 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 176 | kw40z_device.attach_buttonRight(&ButtonRight); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 177 | kw40z_device.attach_buttonUp(&ButtonUp); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 178 | kw40z_device.attach_buttonDown(&ButtonDown); |
tdh50 | 3:065e8a7824d4 | 179 | |
tdh50 | 11:deecd2b72129 | 180 | // Change font color to white |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 181 | textProperties.fontColor = COLOR_WHITE; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 182 | textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 183 | oled.SetTextProperties(&textProperties); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 184 | |
tdh50 | 11:deecd2b72129 | 185 | //Displays the Home Screen |
tdh50 | 3:065e8a7824d4 | 186 | displayHome(); |
tdh50 | 3:065e8a7824d4 | 187 | |
tdh50 | 3:065e8a7824d4 | 188 | while (true) { |
tdh50 | 11:deecd2b72129 | 189 | accel.acquire_accel_data_g(accel_data); |
tdh50 | 11:deecd2b72129 | 190 | accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); |
tdh50 | 11:deecd2b72129 | 191 | printf("%i %4.2f\n\r",count,accel_rms); |
tdh50 | 11:deecd2b72129 | 192 | count++; |
tdh50 | 11:deecd2b72129 | 193 | wait(0.01); |
tdh50 | 11:deecd2b72129 | 194 | if(screenNum == 5) { |
tdh50 | 11:deecd2b72129 | 195 | //drawAccel(); need to fix timing issue |
tdh50 | 11:deecd2b72129 | 196 | } |
tdh50 | 11:deecd2b72129 | 197 | Thread::wait(300); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 198 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 199 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 200 | |
tdh50 | 11:deecd2b72129 | 201 | //*****************************End of Main************************************ |
tdh50 | 3:065e8a7824d4 | 202 | //Intiates Vibration |
tdh50 | 3:065e8a7824d4 | 203 | void StartHaptic(void) |
tdh50 | 3:065e8a7824d4 | 204 | { |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 205 | hapticTimer.start(50); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 206 | haptic = 1; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 207 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 208 | |
tdh50 | 3:065e8a7824d4 | 209 | void StopHaptic(void const *n) |
tdh50 | 3:065e8a7824d4 | 210 | { |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 211 | haptic = 0; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 212 | hapticTimer.stop(); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 213 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 214 | |
tdh50 | 3:065e8a7824d4 | 215 | void displayHome(void) |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 216 | { |
tdh50 | 3:065e8a7824d4 | 217 | oled.DrawImage(HomeBMP,0,0); |
tdh50 | 3:065e8a7824d4 | 218 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 219 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 220 | |
tdh50 | 3:065e8a7824d4 | 221 | void screenHandler(uint8_t screen) |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 222 | { |
tdh50 | 3:065e8a7824d4 | 223 | //Switching screens |
tdh50 | 3:065e8a7824d4 | 224 | switch(screen) { |
tdh50 | 3:065e8a7824d4 | 225 | case 0: { |
tdh50 | 3:065e8a7824d4 | 226 | displayHome(); |
tdh50 | 3:065e8a7824d4 | 227 | break; |
tdh50 | 3:065e8a7824d4 | 228 | } |
tdh50 | 3:065e8a7824d4 | 229 | case 1: { |
tdh50 | 3:065e8a7824d4 | 230 | //Switching to SafeBMP |
tdh50 | 3:065e8a7824d4 | 231 | oled.DrawImage(SafeBMP,0,0); |
tdh50 | 3:065e8a7824d4 | 232 | break; |
tdh50 | 3:065e8a7824d4 | 233 | } |
tdh50 | 3:065e8a7824d4 | 234 | case 2: { |
tdh50 | 3:065e8a7824d4 | 235 | //Switching to HeartBMP |
tdh50 | 3:065e8a7824d4 | 236 | oled.DrawImage(HeartBMP,0,0); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 237 | break; |
tdh50 | 3:065e8a7824d4 | 238 | } |
tdh50 | 3:065e8a7824d4 | 239 | case 3: { |
tdh50 | 3:065e8a7824d4 | 240 | //Switching to FallBMP |
tdh50 | 3:065e8a7824d4 | 241 | oled.DrawImage(FallBMP,0,0); |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 242 | break; |
tdh50 | 3:065e8a7824d4 | 243 | } |
tdh50 | 3:065e8a7824d4 | 244 | case 4: { |
tdh50 | 3:065e8a7824d4 | 245 | //Switching to HeartPageBMP |
tdh50 | 3:065e8a7824d4 | 246 | oled.DrawImage(HeartPageBMP,0,0); |
tdh50 | 3:065e8a7824d4 | 247 | break; |
tdh50 | 3:065e8a7824d4 | 248 | } |
tdh50 | 3:065e8a7824d4 | 249 | case 5: { |
tdh50 | 3:065e8a7824d4 | 250 | //Switching to FallPageBMP |
tdh50 | 11:deecd2b72129 | 251 | oled.DrawImage(FallPageBMP,0,0); |
tdh50 | 3:065e8a7824d4 | 252 | break; |
tdh50 | 3:065e8a7824d4 | 253 | } |
DeanBritt | 8:5532a9c895be | 254 | case 6: { |
DeanBritt | 8:5532a9c895be | 255 | //AlertNotification |
DeanBritt | 9:5e63a3928e43 | 256 | oled.DrawImage(AlertBMP,0,0); |
tdh50 | 11:deecd2b72129 | 257 | wait(5); |
tdh50 | 11:deecd2b72129 | 258 | displayTimer(); |
tdh50 | 11:deecd2b72129 | 259 | break; |
tdh50 | 11:deecd2b72129 | 260 | } |
tdh50 | 3:065e8a7824d4 | 261 | default: { |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 262 | break; |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 263 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 264 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 265 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 266 | |
tdh50 | 3:065e8a7824d4 | 267 | //Append Initials to txData[2:3]. |
tdh50 | 3:065e8a7824d4 | 268 | //strcat(txData,NAME); |
tdh50 | 3:065e8a7824d4 | 269 | |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 270 | } |
group-Hexiwear-Alert-System | 0:6384ad26fe6c | 271 | |
tdh50 | 11:deecd2b72129 | 272 | void drawAccel(void) |
tdh50 | 11:deecd2b72129 | 273 | { |
tdh50 | 11:deecd2b72129 | 274 | ax = accel_data[0]; |
tdh50 | 11:deecd2b72129 | 275 | ay = accel_data[1]; |
tdh50 | 11:deecd2b72129 | 276 | az = accel_data[2]; |
tdh50 | 11:deecd2b72129 | 277 | // Get OLED Class Default Text Properties |
tdh50 | 11:deecd2b72129 | 278 | oled_text_properties_t textProperties = {0}; |
tdh50 | 11:deecd2b72129 | 279 | oled.GetTextProperties(&textProperties); |
tdh50 | 5:09837d22b28f | 280 | |
tdh50 | 11:deecd2b72129 | 281 | // Set text properties to white and right aligned for the dynamic text |
tdh50 | 11:deecd2b72129 | 282 | textProperties.fontColor = COLOR_BLUE; |
tdh50 | 11:deecd2b72129 | 283 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
tdh50 | 11:deecd2b72129 | 284 | oled.SetTextProperties(&textProperties); |
tdh50 | 5:09837d22b28f | 285 | |
tdh50 | 11:deecd2b72129 | 286 | // Display Legends |
tdh50 | 11:deecd2b72129 | 287 | strcpy((char *) text1,"X-Axis (g):"); |
tdh50 | 11:deecd2b72129 | 288 | oled.Label((uint8_t *)text1,5,26); |
tdh50 | 11:deecd2b72129 | 289 | |
tdh50 | 11:deecd2b72129 | 290 | // Format the value |
tdh50 | 11:deecd2b72129 | 291 | sprintf(text1,"%4.2f",ax); |
tdh50 | 11:deecd2b72129 | 292 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
tdh50 | 11:deecd2b72129 | 293 | oled.TextBox((uint8_t *)text1,70,26,20,15); //Increase textbox for more digits |
tdh50 | 7:46729d931f26 | 294 | |
tdh50 | 11:deecd2b72129 | 295 | // Set text properties to white and right aligned for the dynamic text |
tdh50 | 11:deecd2b72129 | 296 | textProperties.fontColor = COLOR_GREEN; |
tdh50 | 11:deecd2b72129 | 297 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
tdh50 | 11:deecd2b72129 | 298 | oled.SetTextProperties(&textProperties); |
tdh50 | 7:46729d931f26 | 299 | |
tdh50 | 11:deecd2b72129 | 300 | // Display Legends |
tdh50 | 11:deecd2b72129 | 301 | strcpy((char *) text2,"Y-Axis (g):"); |
tdh50 | 11:deecd2b72129 | 302 | oled.Label((uint8_t *)text2,5,43); |
tdh50 | 7:46729d931f26 | 303 | |
tdh50 | 11:deecd2b72129 | 304 | // Format the value |
tdh50 | 11:deecd2b72129 | 305 | sprintf(text2,"%4.2f",ay); |
tdh50 | 11:deecd2b72129 | 306 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
tdh50 | 11:deecd2b72129 | 307 | oled.TextBox((uint8_t *)text2,70,43,20,15); //Increase textbox for more digits |
tdh50 | 7:46729d931f26 | 308 | |
tdh50 | 11:deecd2b72129 | 309 | // Set text properties to white and right aligned for the dynamic text |
tdh50 | 11:deecd2b72129 | 310 | textProperties.fontColor = COLOR_RED; |
tdh50 | 11:deecd2b72129 | 311 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
tdh50 | 11:deecd2b72129 | 312 | oled.SetTextProperties(&textProperties); |
tdh50 | 7:46729d931f26 | 313 | |
tdh50 | 11:deecd2b72129 | 314 | // Display Legends |
tdh50 | 11:deecd2b72129 | 315 | strcpy((char *) text3,"Z-Axis (g):"); |
tdh50 | 11:deecd2b72129 | 316 | oled.Label((uint8_t *)text3,5,60); |
tdh50 | 7:46729d931f26 | 317 | |
tdh50 | 11:deecd2b72129 | 318 | // Format the value |
tdh50 | 11:deecd2b72129 | 319 | sprintf(text3,"%4.2f",az); |
tdh50 | 11:deecd2b72129 | 320 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
tdh50 | 11:deecd2b72129 | 321 | oled.TextBox((uint8_t *)text3,70,60,20,15); //Increase textbox for more digits |
tdh50 | 7:46729d931f26 | 322 | |
tdh50 | 11:deecd2b72129 | 323 | } |
tdh50 | 11:deecd2b72129 | 324 | void displayTimer() |
tdh50 | 11:deecd2b72129 | 325 | { |
tdh50 | 11:deecd2b72129 | 326 | timer = 30; |
tdh50 | 11:deecd2b72129 | 327 | while(timer>0) { |
tdh50 | 11:deecd2b72129 | 328 | oled.FillScreen(COLOR_BLACK); |
tdh50 | 11:deecd2b72129 | 329 | // Set text properties to white and right aligned for the dynamic text |
tdh50 | 11:deecd2b72129 | 330 | textProperties.fontColor = COLOR_RED; |
tdh50 | 11:deecd2b72129 | 331 | textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; |
tdh50 | 11:deecd2b72129 | 332 | oled.SetTextProperties(&textProperties); |
tdh50 | 7:46729d931f26 | 333 | |
tdh50 | 11:deecd2b72129 | 334 | // Format the value |
tdh50 | 11:deecd2b72129 | 335 | sprintf(text3,"%i",timer); |
tdh50 | 11:deecd2b72129 | 336 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
tdh50 | 11:deecd2b72129 | 337 | oled.TextBox((uint8_t *)text3,48,48,20,15); //Increase textbox for more digits |
tdh50 | 11:deecd2b72129 | 338 | timer--; |
tdh50 | 11:deecd2b72129 | 339 | wait(1); |
tdh50 | 7:46729d931f26 | 340 | } |
tdh50 | 11:deecd2b72129 | 341 | displayHome(); |
tdh50 | 11:deecd2b72129 | 342 | screenNum = 0; |
tdh50 | 7:46729d931f26 | 343 | } |