IKS01A1 Demo
Dependencies: X_NUCLEO_IKS01A1
Revision 12:504236c45846, committed 2019-09-11
- Comitter:
- noutram
- Date:
- Wed Sep 11 13:07:56 2019 +0000
- Parent:
- 11:c613d631c1e9
- Commit message:
- Now works with F429
Changed in this revision
--- a/main.cpp Wed Sep 11 09:58:59 2019 +0000
+++ b/main.cpp Wed Sep 11 13:07:56 2019 +0000
@@ -39,8 +39,8 @@
/* Includes */
#include "mbed.h"
#include "x_nucleo_iks01a1.h"
-
-Ticker t;
+void doSample();
+void samplerThread();
/* Instantiate the expansion board */
static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
@@ -54,83 +54,27 @@
static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
-/* Helper function for printing floats & doubles */
-static char *printDouble(char* str, double v, int decimalDigits=2)
-{
- int i = 1;
- int intPart, fractPart;
- int len;
- char *ptr;
-
- /* prepare decimal digits multiplicator */
- for (;decimalDigits!=0; i*=10, decimalDigits--);
-
- /* calculate integer & fractinal parts */
- intPart = (int)v;
- fractPart = (int)((v-(double)(int)v)*i);
-
- /* fill in integer part */
- sprintf(str, "%i.", intPart);
-
- /* prepare fill in of fractional part */
- len = strlen(str);
- ptr = &str[len];
-
- /* fill in leading fractional zeros */
- for (i/=10;i>1; i/=10, ptr++) {
- if(fractPart >= i) break;
- *ptr = '0';
- }
-
- /* fill in (rest of) fractional part */
- sprintf(ptr, "%i", fractPart);
-
- return str;
-}
+Serial pc(USBTX, USBRX);
+Thread sampler(osPriorityRealtime);
+EventQueue queue;
DigitalIn sw1(USER_BUTTON);
int32_t m_axes[3];
int32_t a_axes[3];
int32_t g_axes[3];
-
+uint8_t id;
+
+const unsigned Fs = 100;
+const double T = 1.0 / (double)Fs;
+const unsigned Tms = (unsigned)(T*1000.0);
+unsigned long tt = 0;
+
+void samplerThread()
+{
+ queue.dispatch();
+}
void doSample()
{
-}
-
-/* Simple main function */
-int main() {
- uint8_t id;
- float value1, value2;
- char buffer1[32], buffer2[32];
-
-
- Serial pc(USBTX, USBRX);
- pc.baud(926100);
-
-
- humidity_sensor->read_id(&id);
- pressure_sensor->read_id(&id);
- magnetometer->read_id(&id);
- gyroscope->read_id(&id);
-
- pc.printf("Press the blue button to start\n\r");
- unsigned long tt = 0;
- while (sw1 == 0);
- wait_ms(250.0);
- while (sw1 == 1);
- wait_ms(250.0);
-
- pc.printf("time[ms],x[mag/mgauss],y[mag/mgauss],z[mag/mgauss],x[acc/mg],y[acc/mg],z[acc/mg],x[gyro/mdps],y[gyro/mdps],z[gyro/mdps]\n\r");
-
- const unsigned Fs = 100;
- const double T = 1.0 / (double)Fs;
- const unsigned Tms = (unsigned)(T*1000.0);
- t.attach(doSample, T);
-
- while(sw1 == 1) {
-
- sleep();
-
magnetometer->get_m_axes(m_axes);
accelerometer->get_x_axes(a_axes);
gyroscope->get_g_axes(g_axes);
@@ -139,11 +83,36 @@
pc.printf("%d,%d,%d,", m_axes[0], m_axes[1], m_axes[2]);
pc.printf("%d,%d,%d,", a_axes[0], a_axes[1], a_axes[2]);
pc.printf("%d,%d,%d\r\n", g_axes[0], g_axes[1], g_axes[2]);
+}
+/* Simple main function */
+int main() {
+
+ pc.baud(926100);
+
+ humidity_sensor->read_id(&id);
+ pressure_sensor->read_id(&id);
+ magnetometer->read_id(&id);
+ gyroscope->read_id(&id);
+
+ pc.printf("Press the blue button to start\n\rThen press the black reset button to stop\n\r");
+
+ while (sw1 == 0);
+ wait_ms(250.0);
+ while (sw1 == 1);
+ wait_ms(250.0);
+
+ pc.printf("time[ms],x[mag/mgauss],y[mag/mgauss],z[mag/mgauss],x[acc/mg],y[acc/mg],z[acc/mg],x[gyro/mdps],y[gyro/mdps],z[gyro/mdps]\n\r");
+
+ sampler.start(samplerThread);
+ queue.call_every(Tms, doSample);
+ sampler.join();
+
+ while(true) {
+ pc.printf("Should never get here!\n\r");
+ wait(1.0);
}
- pc.printf("Press Reset Button to Restart\n\r");
- while(1);
}
--- a/mbed-os.lib Wed Sep 11 09:58:59 2019 +0000 +++ b/mbed-os.lib Wed Sep 11 13:07:56 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/armmbed/mbed-os/#73f096399b4cda1f780b140c87afad9446047432 +https://github.com/armmbed/mbed-os/#1bf6b20df9d3cd5f29f001ffc6f0d0fcbbb96118
--- a/mbed_app.json Wed Sep 11 09:58:59 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-{
- "requires": ["bare-metal"]
-}
\ No newline at end of file