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
board_udk.cpp
00001 /*** 00002 * _____ _ 00003 #if defined MTDOT_UDK 00004 * / ____| | | 00005 * | (___ ___ _ __ ___ | |_ 00006 * \___ \ / _ \ | '_ \ / _ \ | __| 00007 * ____) | | __/ | | | | | __/ | |_ 00008 * |_____/ \___| |_| |_| \___| \__| 00009 * (C) 2016 Senet, Inc 00010 * 00011 */ 00012 #if defined MTDOT_UDK 00013 00014 #include "board_udk.h" 00015 #include "x_nucleo_iks01a1.h" 00016 00017 extern void mDotInit(); 00018 00019 Serial debugUART(USBTX, USBRX); 00020 DigitalOut led1(PA_0); 00021 static X_NUCLEO_IKS01A1 *mems_shield; 00022 00023 00024 CBoardUDK::CBoardUDK() 00025 { 00026 boardPtr = this; 00027 } 00028 00029 EBoardStatus CBoardUDK::init() 00030 { 00031 CBoard::init(); 00032 mems_shield = X_NUCLEO_IKS01A1::Instance(NULL, NC); 00033 00034 return Board_Ok; 00035 } 00036 00037 EBoardStatus CBoardUDK::readSensors ( BoardSensorData &data ) 00038 { 00039 uint32_t ret = 0; 00040 int32_t accel_data[3]; 00041 00042 // Temperature 00043 ret |= (!CALL_METH(mems_shield->pt_sensor, GetTemperature, &data.temperature, 0.0f) ? 0x0 : 0x1); 00044 00045 // Pressure 00046 ret |= (!CALL_METH(mems_shield->pt_sensor, GetPressure, &data.pressure, 0.0f) ? 0x0 : 0x1); 00047 00048 // Accelerometer 00049 MotionSensor *motionSensor = mems_shield->GetAccelerometer(); 00050 if( motionSensor != NULL) 00051 { 00052 motionSensor->Get_X_Axes(accel_data); 00053 00054 data.accel_x = accel_data[0]; 00055 data.accel_y = accel_data[1]; 00056 data.accel_z = accel_data[2]; 00057 /* z-axis : > 0 = rightside up, < 0 upside down 00058 * x-axis: com LED to the left x < 0, x > 0 on the right 00059 * y-axis: y > 0 COM LED down, y < 0 COM LED up 00060 */ 00061 data.orientation.init(); 00062 00063 // rightside up 00064 if(data.accel_z >= 750) 00065 { 00066 // data.orientation.horizontal = true; 00067 } 00068 // upside down 00069 else if(data.accel_z <= -750) 00070 { 00071 data.orientation.down = true; 00072 // position_value = (2 << 12) | (1 << 8); 00073 } 00074 // vertical down 00075 else if(data.accel_y >= 900 ) 00076 { 00077 data.orientation.vertical = true; 00078 data.orientation.down = true; 00079 } 00080 // vertical up 00081 else if(data.accel_y <= -900 ) 00082 { 00083 data.orientation.vertical = true; 00084 data.orientation.up = true; 00085 } 00086 // side right 00087 else if(data.accel_x > 900) 00088 { 00089 data.orientation.right = true; 00090 } 00091 // side left 00092 else 00093 { 00094 data.orientation.left = true; 00095 } 00096 } 00097 00098 return Board_Ok; 00099 } 00100 00101 EBoardStatus CBoardUDK::setLED(uint8_t ledNum, bool on) 00102 { 00103 if(ledNum == 1) 00104 { 00105 led1 = on ? 0 : 1; 00106 return Board_Ok; 00107 } 00108 return Board_Invalid; 00109 } 00110 00111 EBoardStatus CBoardUDK::toggleLED(uint8_t ledNum) 00112 { 00113 if(ledNum == 1) 00114 { 00115 led1 = !led1; 00116 return Board_Ok; 00117 } 00118 return Board_Invalid; 00119 } 00120 00121 #endif
Generated on Sun Jul 24 2022 22:57:48 by
1.7.2
