Finished project.

Dependencies:   X_NUCLEO_COMMON

Fork of ReferredCoursework2016 by Stage-1 Students SoCEM

Committer:
J_Satchell
Date:
Thu Aug 17 06:58:29 2017 +0000
Revision:
91:cd9fcd45ecf6
Parent:
90:38dfa3f350aa
Added mutex

Who changed what in which revision?

UserRevisionLine numberNew contents of line
J_Satchell 90:38dfa3f350aa 1 /*sensor.cpp simply reads in the acceleration measurements
J_Satchell 90:38dfa3f350aa 2 using the NUCLEO board and using the function and struct
J_Satchell 90:38dfa3f350aa 3 from buffer.cpp, stores the values in to the circular buffer*/
J_Satchell 90:38dfa3f350aa 4 #include "mbed.h"
J_Satchell 90:38dfa3f350aa 5 #include "x_nucleo_iks01a1.h"
J_Satchell 90:38dfa3f350aa 6 #include "buffer.h"
J_Satchell 90:38dfa3f350aa 7 #include "sensor.h"
J_Satchell 90:38dfa3f350aa 8
J_Satchell 91:cd9fcd45ecf6 9 Mutex mutex;
J_Satchell 91:cd9fcd45ecf6 10
J_Satchell 90:38dfa3f350aa 11 /* Instantiate the expansion board */
J_Satchell 90:38dfa3f350aa 12 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
J_Satchell 90:38dfa3f350aa 13
J_Satchell 90:38dfa3f350aa 14 /* Retrieve the composing elements of the expansion board */
J_Satchell 90:38dfa3f350aa 15 static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
J_Satchell 90:38dfa3f350aa 16
J_Satchell 90:38dfa3f350aa 17 extern char *printDouble(char* str, double v, int decimalDigits = 2);
J_Satchell 90:38dfa3f350aa 18
J_Satchell 90:38dfa3f350aa 19 int32_t axes[3];
J_Satchell 90:38dfa3f350aa 20
J_Satchell 90:38dfa3f350aa 21 void sensor_run(){
J_Satchell 90:38dfa3f350aa 22 while (1) {
J_Satchell 91:cd9fcd45ecf6 23 mutex.lock();
J_Satchell 91:cd9fcd45ecf6 24
J_Satchell 91:cd9fcd45ecf6 25 accelerometer->Get_X_Axes(axes);
J_Satchell 90:38dfa3f350aa 26
J_Satchell 91:cd9fcd45ecf6 27 AccelData d;
J_Satchell 91:cd9fcd45ecf6 28 d.x = axes[0];
J_Satchell 91:cd9fcd45ecf6 29 d.y = axes[1];
J_Satchell 91:cd9fcd45ecf6 30 d.z = axes[2];
J_Satchell 90:38dfa3f350aa 31
J_Satchell 91:cd9fcd45ecf6 32 log_push(d);
J_Satchell 91:cd9fcd45ecf6 33 mutex.unlock();
J_Satchell 90:38dfa3f350aa 34 }
J_Satchell 90:38dfa3f350aa 35
J_Satchell 90:38dfa3f350aa 36 }