Code to be run for the project Group Fitness
Dependencies: FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAX30101
Fork of final_project_ee119 by
Revision 9:c3f399b835ce, committed 2018-06-17
- Comitter:
- aadithyavenkat
- Date:
- Sun Jun 17 22:01:52 2018 +0000
- Parent:
- 8:f5a21cfd3833
- Commit message:
- Added Comments;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Jun 17 20:54:03 2018 +0000
+++ b/main.cpp Sun Jun 17 22:01:52 2018 +0000
@@ -1,3 +1,5 @@
+// Importing the necessary header files for mbed OS, KW40z, OLED screen and
+// FXOS 8700
#include "mbed.h"
#include "mbed_events.h"
#include "Hexi_KW40Z.h"
@@ -7,6 +9,8 @@
#include "string.h"
#include "FXOS8700.h"
+
+// Utility functions defined below
void StartHaptic(void);
void StopHaptic(void const *n);
float Filter(int s);
@@ -24,6 +28,8 @@
void ButtonUp();
void ButtonLeft(void);
+/* Instantiate the accelerometer */
+
FXOS8700 accel(PTC11, PTC10);
/* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
@@ -39,6 +45,7 @@
Thread bluetoothThread;
Thread dataThread;
+/* Create a Thread to handle displaying */
Thread displayThread;
EventQueue displayEventQueue;
@@ -58,13 +65,14 @@
float old_accx, old_accy, old_accz, old_dot=0.0;
uint8_t StepNum = 0, StepNumber = 0;
+// Buffer for averaging out the Pedometer data
float filter_buf[75];
uint8_t result[1]={0};
// variable to assist with viewing the other users' data
-char user[2];
+char user[2];
char mean[4];
char max[4];
char min[4];
@@ -78,12 +86,15 @@
// main() runs in its own thread in the OS
int main() {
+
+ /* Attaching the different functions to the Haptic Buttons*/
kw40z_device.attach_buttonLeft(&ButtonLeft);
kw40z_device.attach_buttonRight(&ButtonRight);
kw40z_device.attach_buttonDown(&ButtonDown);
kw40z_device.attach_buttonUp(&ButtonUp);
kw40z_device.attach_alert(&AlertReceived);
+ /* Starting the accelerometer values*/
accel.accel_config();
// open up the display queue so that at any point in the program,
@@ -91,12 +102,15 @@
displayThread.start(callback(&displayEventQueue, &EventQueue::dispatch_forever));
displayEventQueue.call(&clearScreen);
+ /*Thread start the thread for Handling Bluetooth Events*/
dataThread.start(BTTask);
bluetoothThread.start(dataTask);
wait(osWaitForever);
}
+// Function for handling Bluetooth toggling advertisement, send Alert flag and
+// Step numbers
void BTTask(void){
while (true)
@@ -115,6 +129,9 @@
}
}
+// Function for setting up the flag to configure different users to different
+// buttons on the Hexiwear and also to compute Pedometer algorithm based on
+// Hexiwear data
void dataTask(void) {
while (true) {
if(flag == 1) {
@@ -185,7 +202,7 @@
}
// Key modification: use the alert functionality enabled by the host-ble interface
-// to define our own command.
+// to define our own command to display different user's data
void AlertReceived(uint8_t *data, uint8_t length) {
processedReceivedData = false;
