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