Here
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351 nRF24L01 FXOS8700
Diff: main.cpp
- Revision:
- 12:8db1b8fb5866
- Parent:
- 11:deecd2b72129
- Child:
- 14:9e6b87e322a2
- Child:
- 15:77b6655d401b
diff -r deecd2b72129 -r 8db1b8fb5866 main.cpp --- a/main.cpp Tue Mar 14 17:44:20 2017 +0000 +++ b/main.cpp Mon Apr 10 16:45:37 2017 +0000 @@ -17,13 +17,13 @@ void StartHaptic(void); void StopHaptic(void const *n); -void txTask(void);//? +void txTask(void); void accelero(void); void drawAccel(void); void displayHome(); -void displayTimer(); void screenHandler(uint8_t screen); + DigitalOut redLed(LED1,1); DigitalOut greenLed(LED2,1); DigitalOut blueLed(LED3,1); @@ -39,13 +39,17 @@ // 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 -nRF24L01P my_nrf24l01p(PTC6,PTC7,PTC5,PTC4,PTB2,NC); // mosi, miso, sck, csn, ce, irq + + +/*Create a Thread to handle sending BLE Sensor Data */ +Thread txThread; + // 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 +char text [20]; float accel_data[3]; // Storage for the data from the sensor float accel_rms=0.0; // RMS value from the sensor @@ -57,6 +61,7 @@ bool sentMessageDisplayedFlag=0; char rxData[TRANSFER_SIZE]; char txData[TRANSFER_SIZE]; +int16_t x=0,y=0,z=0; // Pointer for the image to be displayed const uint8_t *SafeBMP = HexiSafe96_bmp; @@ -67,7 +72,6 @@ const uint8_t *HeartPageBMP = HeartRatePage_bmp; const uint8_t *AlertBMP = Alert_bmp; - //***************************Call Back Functions****************************** //Enter Button void ButtonRight(void) @@ -154,6 +158,17 @@ } +void PassKey(void) +{ + StartHaptic(); + strcpy((char *) text,"PAIR CODE"); + oled.TextBox((uint8_t *)text,0,25,95,18); + + /* Display Bond Pass Key in a 95px by 18px textbox at x=0,y=40 */ + sprintf(text,"%d", kw40z_device.GetPassKey()); + oled.TextBox((uint8_t *)text,0,40,95,18); +} + //**********************End of Call Back Functions**************************** @@ -162,11 +177,7 @@ int main() { // 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 - // Get OLED Class Default Text Properties oled.GetTextProperties(&textProperties); @@ -176,26 +187,36 @@ kw40z_device.attach_buttonRight(&ButtonRight); kw40z_device.attach_buttonUp(&ButtonUp); kw40z_device.attach_buttonDown(&ButtonDown); + oled_text_properties_t textProperties = {0}; + oled.SetTextProperties(&textProperties); + + //Passcode + kw40z_device.attach_passkey(&PassKey); // Change font color to white textProperties.fontColor = COLOR_WHITE; textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; - oled.SetTextProperties(&textProperties); + + //txThread.start(txTask); /*Start transmitting Sensor Tag Data */ //Displays the Home Screen displayHome(); + //bool trigger = 0; while (true) { 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); + x = accel_data[0] *10000; + y = accel_data[1] *10000; + z = accel_data[2] *10000; + printf("x = %4.4f y = %4.4f z = %4.4f\n\rx = %i y = %i z = %i\n\r",accel_data[0],accel_data[1],accel_data[2],x,y,z); if(screenNum == 5) { - //drawAccel(); need to fix timing issue + drawAccel(); } Thread::wait(300); } + + } //*****************************End of Main************************************ @@ -248,14 +269,12 @@ } case 5: { //Switching to FallPageBMP - oled.DrawImage(FallPageBMP,0,0); + oled.DrawBox (23,18,50 ,50 , COLOR_BLACK); break; } case 6: { - //AlertNotification + //Switching to alarm oled.DrawImage(AlertBMP,0,0); - wait(5); - displayTimer(); break; } default: { @@ -271,73 +290,49 @@ void drawAccel(void) { - 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.fontColor = COLOR_GREEN; 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); + sprintf(text1,"%4.2f", accel_data[0]); + // 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 + + // Format the value + sprintf(text2,"%4.2f",accel_data[1]); + // 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 + + + // Format the value + sprintf(text3,"%4.2f", accel_data[2]); // 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 } -void displayTimer() + +// txTask() transmits the sensor data +void txTask(void) { - timer = 30; - while(timer>0) { - oled.FillScreen(COLOR_BLACK); - // Set text properties to white and right aligned for the dynamic text - textProperties.fontColor = COLOR_RED; - textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; - oled.SetTextProperties(&textProperties); + + while (true) { - // Format the value - sprintf(text3,"%i",timer); - // Display time reading in 35px by 15px textbox at(x=55, y=40) - oled.TextBox((uint8_t *)text3,48,48,20,15); //Increase textbox for more digits - timer--; - wait(1); + //UpdateSensorData(); + kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); + + //Send Accel Data. + kw40z_device.SendAccel(x,y,z); } - displayHome(); - screenNum = 0; } + +