Here

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351 nRF24L01 FXOS8700

Revision:
10:3a13cb84e64f
Parent:
7:46729d931f26
--- a/main.cpp	Mon Mar 13 17:44:15 2017 +0000
+++ b/main.cpp	Mon Mar 13 19:25:19 2017 +0000
@@ -18,8 +18,6 @@
 void StartHaptic(void);
 void StopHaptic(void const *n);
 void txTask(void);
-void accelero(void);
-void drawAccel(void);
 void displayHome();
 void screenHandler(uint8_t screen);
 
@@ -28,20 +26,20 @@
 DigitalOut blueLed(LED3,1);
 DigitalOut haptic(PTB9);
 
-// Define timer for haptic feedback  
+// Define timer for haptic feedback
 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
-//   
+//
 FXOS8700 accel(PTC11, PTC10);
-// Instantiate the Hexi KW40Z Driver (UART TX, UART RX)  
+// Instantiate the Hexi KW40Z Driver (UART TX, UART RX)
 KW40Z kw40z_device(PTE24, PTE25);
 Serial pc(USBTX, USBRX); // Serial interface
-// Instantiate the SSD1351 OLED Driver  
-SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)  
+// Instantiate the SSD1351 OLED Driver
+SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
 oled_text_properties_t textProperties = {0};
-// Instantiate the nRF24L01P Driver  
+// Instantiate the nRF24L01P Driver
 nRF24L01P my_nrf24l01p(PTC6,PTC7,PTC5,PTC4,PTB2,NC);    // mosi, miso, sck, csn, ce, irq
 
-// Text Buffer  
+// Text Buffer
 char text1[20]; // Text Buffer for dynamic value displayed
 char text2[20]; // Text Buffer for dynamic value displayed
 char text3[20]; // Text Buffer for dynamic value displayed
@@ -56,7 +54,7 @@
 char rxData[TRANSFER_SIZE];
 char txData[TRANSFER_SIZE];
 
-// Pointer for the image to be displayed   
+// Pointer for the image to be displayed
 const uint8_t *SafeBMP = HexiSafe96_bmp;
 const uint8_t *HeartBMP = HeartRate_bmp;
 const uint8_t *FallBMP = FallDet_bmp;
@@ -65,8 +63,8 @@
 const uint8_t *HeartPageBMP = HeartRatePage_bmp;
 
 
-//***************************Call Back Functions****************************** 
-//Enter Button  
+//***************************Call Back Functions******************************
+//Enter Button
 void ButtonRight(void)
 {
     // All screens other than 1 have either and enter button
@@ -103,7 +101,7 @@
     }
 }
 
-//Back Button  
+//Back Button
 void ButtonLeft(void)
 {
     if(screenNum > 0) {
@@ -122,7 +120,7 @@
 }
 
 //Advances to Heartrate only when user
-//is on Hexisafe screen  
+//is on Hexisafe screen
 void ButtonUp(void)
 {
     if (screenNum == 1) {
@@ -135,7 +133,7 @@
 }
 
 //Advances to Fall Detection only when user
-//is on Hexisafe screen  
+//is on Hexisafe screen
 void ButtonDown(void)
 {
     if (screenNum == 1) {
@@ -147,42 +145,105 @@
 }
 
 
-//**********************End of Call Back Functions**************************** 
+//**********************End of Call Back Functions****************************
 
-//*******************************Main***************************************** 
+//*******************************Main*****************************************
 
 int main()
 {
-    // Wait Sequence in the beginning for board to be reset then placed in mini docking station 
+    // Wait Sequence in the beginning for board to be reset then placed in mini docking station
     blueLed=1;
 
+    accel.accel_config();
+    //oled.DrawImage(FallPageBMP,0,0);
+    int count = 0;// count data reading for accelerometer
+    // Fill 96px by 96px Screen with 96px by 96px Image starting at x=0,y=
 
 
-    // Get OLED Class Default Text Properties  
+    // Get OLED Class Default Text Properties
     oled.GetTextProperties(&textProperties);
 
-    // Register callbacks to application functions  
+    // Register callbacks to application functions
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
     kw40z_device.attach_buttonUp(&ButtonUp);
     kw40z_device.attach_buttonDown(&ButtonDown);
 
-    // Change font color to white  
+    // Change font color to white
     textProperties.fontColor   = COLOR_WHITE;
     textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
     oled.SetTextProperties(&textProperties);
 
-    //Displays the Home Screen 
+    //Displays the Home Screen
     displayHome();
 
     while (true) {
-        accelero();
-        redLed = 1 ;
-        Thread::wait(50);
+        accel.acquire_accel_data_g(accel_data);
+        accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
+        printf("%4.2f\n\r",accel_rms);
+        wait(0.01);
+        greenLed = !greenLed ;
+        if(screenNum == 5) {
+            oled.DrawImage(FallPageBMP,0,0);
+            while(screenNum == 5) {
+                ax = accel_data[0];
+                ay = accel_data[1];
+                az = accel_data[2];
+                // Get OLED Class Default Text Properties
+                oled_text_properties_t textProperties = {0};
+                oled.GetTextProperties(&textProperties);
+
+                // Set text properties to white and right aligned for the dynamic text
+                textProperties.fontColor = COLOR_BLUE;
+                textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
+                oled.SetTextProperties(&textProperties);
+
+                // Display Legends
+                strcpy((char *) text1,"X-Axis (g):");
+                oled.Label((uint8_t *)text1,5,26);
+
+                // Format the value
+                sprintf(text1,"%4.2f",ax);
+                // Display time reading in 35px by 15px textbox at(x=55, y=40)
+                oled.TextBox((uint8_t *)text1,70,26,20,15); //Increase textbox for more digits
+
+                // Set text properties to white and right aligned for the dynamic text
+                textProperties.fontColor = COLOR_GREEN;
+                textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
+                oled.SetTextProperties(&textProperties);
+
+                // Display Legends
+                strcpy((char *) text2,"Y-Axis (g):");
+                oled.Label((uint8_t *)text2,5,43);
+
+                // Format the value
+                sprintf(text2,"%4.2f",ay);
+                // Display time reading in 35px by 15px textbox at(x=55, y=40)
+                oled.TextBox((uint8_t *)text2,70,43,20,15); //Increase textbox for more digits
+
+                // Set text properties to white and right aligned for the dynamic text
+                textProperties.fontColor = COLOR_RED;
+                textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
+                oled.SetTextProperties(&textProperties);
+
+                // Display Legends
+                strcpy((char *) text3,"Z-Axis (g):");
+                oled.Label((uint8_t *)text3,5,60);
+
+                // Format the value
+                sprintf(text3,"%4.2f",az);
+                // Display time reading in 35px by 15px textbox at(x=55, y=40)
+                oled.TextBox((uint8_t *)text3,70,60,20,15); //Increase textbox for more digits
+
+            }
+        }
+        //accelero(screenNum);
+        printf("Here\n");
+        Thread::wait(100);
     }
 }
 
-//*****************************End of Main************************************ 
+//*****************************End of Main************************************
 //Intiates Vibration
 void StartHaptic(void)
 {
@@ -232,7 +293,8 @@
         }
         case 5: {
             //Switching to FallPageBMP
-            drawAccel();
+            //oled.DrawImage(FallPageBMP,0,0);
+
             break;
         }
         default: {
@@ -246,83 +308,4 @@
 
 }
 
-void accelero(void)
-{
-    // Configure Accelerometer FXOS8700, Magnetometer FXOS8700
-    accel.accel_config();
-    //oled.DrawImage(FallPageBMP,0,0);
-    int count = 0;// count data reading for accelerometer
-    // Fill 96px by 96px Screen with 96px by 96px Image starting at x=0,y=0
-    while (1) {
 
-        accel.acquire_accel_data_g(accel_data);
-        accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
-        printf("%i %4.2f\n\r",count,accel_rms);
-        count++;
-        wait(0.01);
-        greenLed = !greenLed ;
-        Thread::wait(200);
-    }
-}
-
-void drawAccel(void){
-            
-            
-             oled.DrawImage(FallPageBMP,0,0); 
-             while(true){   
-             ax = accel_data[0];
-             ay = accel_data[1];
-             az = accel_data[2];
-                   // Get OLED Class Default Text Properties
-             oled_text_properties_t textProperties = {0};
-             oled.GetTextProperties(&textProperties);
-
-             // Set text properties to white and right aligned for the dynamic text
-             textProperties.fontColor = COLOR_BLUE;
-             textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
-             oled.SetTextProperties(&textProperties);
-
-             // Display Legends
-             strcpy((char *) text1,"X-Axis (g):");
-             oled.Label((uint8_t *)text1,5,26);
-
-             // Format the value
-             sprintf(text1,"%4.2f",ax);
-             // Display time reading in 35px by 15px textbox at(x=55, y=40)
-             oled.TextBox((uint8_t *)text1,70,26,20,15); //Increase textbox for more digits
-
-             // Set text properties to white and right aligned for the dynamic text
-             textProperties.fontColor = COLOR_GREEN;
-             textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
-             oled.SetTextProperties(&textProperties);
-
-             // Display Legends
-             strcpy((char *) text2,"Y-Axis (g):");
-             oled.Label((uint8_t *)text2,5,43);
-
-             // Format the value
-             sprintf(text2,"%4.2f",ay);
-             // Display time reading in 35px by 15px textbox at(x=55, y=40)
-             oled.TextBox((uint8_t *)text2,70,43,20,15); //Increase textbox for more digits
-
-             // Set text properties to white and right aligned for the dynamic text
-             textProperties.fontColor = COLOR_RED;
-             textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
-             oled.SetTextProperties(&textProperties);
-
-             // Display Legends
-             strcpy((char *) text3,"Z-Axis (g):");
-             oled.Label((uint8_t *)text3,5,60);
-
-             // Format the value
-             sprintf(text3,"%4.2f",az);
-             // Display time reading in 35px by 15px textbox at(x=55, y=40)
-             oled.TextBox((uint8_t *)text3,70,60,20,15); //Increase textbox for more digits
-
-     Thread::wait(200);  
-       
-    }
-    
-    
-}
-