mdot UDK & STMicro MEMS Shield Sensor packet example

Dependencies:   libmDot-mbed5 DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B X_NUCLEO_IKS01A1 Senet_Packet

Fork of MTDOT-UDKDemo_Senet by canuck lehead

Branch:
develop
Revision:
27:1753a44fa9ec
Child:
28:4fd8a894a403
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/board/udk/board_udk.cpp	Thu Aug 24 17:56:53 2017 -0400
@@ -0,0 +1,119 @@
+/***
+ *       _____                         _   
+#if defined MTDOT_UDK
+ *      / ____|                       | |  
+ *     | (___     ___   _ __     ___  | |_ 
+ *      \___ \   / _ \ | '_ \   / _ \ | __|
+ *      ____) | |  __/ | | | | |  __/ | |_ 
+ *     |_____/   \___| |_| |_|  \___|  \__|
+ *         (C) 2016 Senet, Inc                                
+ *                                         
+ */
+#if defined MTDOT_UDK
+
+#include "board.h"
+#include "x_nucleo_iks01a1.h"
+
+extern void mDotInit();
+
+Serial debugUART(USBTX, USBRX);
+static X_NUCLEO_IKS01A1 *mems_shield;
+
+
+void BoardInit()
+{
+	mems_shield = X_NUCLEO_IKS01A1::Instance(NULL, NC);
+}
+
+void BoardStart() { }
+void BoardStop()  { }
+
+void BoardReadSensors(BoardSensorData &data)
+{
+    uint32_t ret = 0;
+    int32_t  accel_data[3];
+
+   // Temperature
+   ret |= (!CALL_METH(mems_shield->pt_sensor, GetTemperature, &data.temperature, 0.0f) ? 0x0 : 0x1);
+
+   // Pressure
+   ret |= (!CALL_METH(mems_shield->pt_sensor, GetPressure, &data.pressure, 0.0f) ? 0x0 : 0x1);
+
+   // Accelerometer
+   MotionSensor *motionSensor = mems_shield->GetAccelerometer();
+   if( motionSensor != NULL)
+   {
+       motionSensor->Get_X_Axes(accel_data);
+
+       data.accel_x = accel_data[0];
+       data.accel_y = accel_data[1];
+       data.accel_z = accel_data[2];
+       /*  z-axis : > 0 = rightside up, < 0 upside down
+        *  x-axis: com LED to the left x < 0, x > 0 on the right
+        *  y-axis: y > 0 COM LED down, y < 0  COM LED up
+        */
+       data.orientation.init();
+
+       // rightside up
+       if(data.accel_z >= 750)
+       {
+           data.orientation.horizontal = true;
+       }
+       // upside down
+       else if(data.accel_z <= -750)
+       {
+           data.orientation.horizontal  = true;
+           data.orientation.down        = true;
+           // position_value = (2 << 12) | (1 << 8);
+       }
+       // vertical down
+       else if(data.accel_y >= 900 )
+       {
+           data.orientation.down = true;
+       }
+       // vertical up
+       else if(data.accel_y <= -900 )
+       {
+           data.orientation.up = true;
+       }
+       // side right
+       else if(data.accel_x > 900)
+       {
+           data.orientation.right = true;
+       }
+       // side left
+       else
+       {
+           data.orientation.left = true;
+       }
+
+       /*
+       if(horizontal)
+       {
+           next_value = (2 << 12) | (upsidedown << 8);
+       }
+       else
+       {
+           next_value = (up << 12) | (left << 8) | (down << 4) | right;
+       }
+
+       if(next_value != position_value)
+       {
+           position_value = next_value;
+           position_changed = true;
+
+           // Set reflected_value to an out of range value to stay
+           // in fast transmit mode until server responds
+           reflected_value = 0;
+
+            // Turn LED off to indicate server is not in agreement
+            SYNC_LED=SYNC_LED_OOS;
+       }
+       */
+   }
+}
+
+
+bool BoardCheckForExit( bool exit ) { return false; }
+
+#endif