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/board_udk.cpp@27:1753a44fa9ec, 2017-08-24 (annotated)
- Committer:
- Shaun Nelson
- Date:
- Thu Aug 24 17:56:53 2017 -0400
- Branch:
- develop
- Revision:
- 27:1753a44fa9ec
- Child:
- 28:4fd8a894a403
Reimplement for mbed 5
Move bsp to board files
UDK implemented
EVB in progress
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Shaun Nelson |
27:1753a44fa9ec | 1 | /*** |
Shaun Nelson |
27:1753a44fa9ec | 2 | * _____ _ |
Shaun Nelson |
27:1753a44fa9ec | 3 | #if defined MTDOT_UDK |
Shaun Nelson |
27:1753a44fa9ec | 4 | * / ____| | | |
Shaun Nelson |
27:1753a44fa9ec | 5 | * | (___ ___ _ __ ___ | |_ |
Shaun Nelson |
27:1753a44fa9ec | 6 | * \___ \ / _ \ | '_ \ / _ \ | __| |
Shaun Nelson |
27:1753a44fa9ec | 7 | * ____) | | __/ | | | | | __/ | |_ |
Shaun Nelson |
27:1753a44fa9ec | 8 | * |_____/ \___| |_| |_| \___| \__| |
Shaun Nelson |
27:1753a44fa9ec | 9 | * (C) 2016 Senet, Inc |
Shaun Nelson |
27:1753a44fa9ec | 10 | * |
Shaun Nelson |
27:1753a44fa9ec | 11 | */ |
Shaun Nelson |
27:1753a44fa9ec | 12 | #if defined MTDOT_UDK |
Shaun Nelson |
27:1753a44fa9ec | 13 | |
Shaun Nelson |
27:1753a44fa9ec | 14 | #include "board.h" |
Shaun Nelson |
27:1753a44fa9ec | 15 | #include "x_nucleo_iks01a1.h" |
Shaun Nelson |
27:1753a44fa9ec | 16 | |
Shaun Nelson |
27:1753a44fa9ec | 17 | extern void mDotInit(); |
Shaun Nelson |
27:1753a44fa9ec | 18 | |
Shaun Nelson |
27:1753a44fa9ec | 19 | Serial debugUART(USBTX, USBRX); |
Shaun Nelson |
27:1753a44fa9ec | 20 | static X_NUCLEO_IKS01A1 *mems_shield; |
Shaun Nelson |
27:1753a44fa9ec | 21 | |
Shaun Nelson |
27:1753a44fa9ec | 22 | |
Shaun Nelson |
27:1753a44fa9ec | 23 | void BoardInit() |
Shaun Nelson |
27:1753a44fa9ec | 24 | { |
Shaun Nelson |
27:1753a44fa9ec | 25 | mems_shield = X_NUCLEO_IKS01A1::Instance(NULL, NC); |
Shaun Nelson |
27:1753a44fa9ec | 26 | } |
Shaun Nelson |
27:1753a44fa9ec | 27 | |
Shaun Nelson |
27:1753a44fa9ec | 28 | void BoardStart() { } |
Shaun Nelson |
27:1753a44fa9ec | 29 | void BoardStop() { } |
Shaun Nelson |
27:1753a44fa9ec | 30 | |
Shaun Nelson |
27:1753a44fa9ec | 31 | void BoardReadSensors(BoardSensorData &data) |
Shaun Nelson |
27:1753a44fa9ec | 32 | { |
Shaun Nelson |
27:1753a44fa9ec | 33 | uint32_t ret = 0; |
Shaun Nelson |
27:1753a44fa9ec | 34 | int32_t accel_data[3]; |
Shaun Nelson |
27:1753a44fa9ec | 35 | |
Shaun Nelson |
27:1753a44fa9ec | 36 | // Temperature |
Shaun Nelson |
27:1753a44fa9ec | 37 | ret |= (!CALL_METH(mems_shield->pt_sensor, GetTemperature, &data.temperature, 0.0f) ? 0x0 : 0x1); |
Shaun Nelson |
27:1753a44fa9ec | 38 | |
Shaun Nelson |
27:1753a44fa9ec | 39 | // Pressure |
Shaun Nelson |
27:1753a44fa9ec | 40 | ret |= (!CALL_METH(mems_shield->pt_sensor, GetPressure, &data.pressure, 0.0f) ? 0x0 : 0x1); |
Shaun Nelson |
27:1753a44fa9ec | 41 | |
Shaun Nelson |
27:1753a44fa9ec | 42 | // Accelerometer |
Shaun Nelson |
27:1753a44fa9ec | 43 | MotionSensor *motionSensor = mems_shield->GetAccelerometer(); |
Shaun Nelson |
27:1753a44fa9ec | 44 | if( motionSensor != NULL) |
Shaun Nelson |
27:1753a44fa9ec | 45 | { |
Shaun Nelson |
27:1753a44fa9ec | 46 | motionSensor->Get_X_Axes(accel_data); |
Shaun Nelson |
27:1753a44fa9ec | 47 | |
Shaun Nelson |
27:1753a44fa9ec | 48 | data.accel_x = accel_data[0]; |
Shaun Nelson |
27:1753a44fa9ec | 49 | data.accel_y = accel_data[1]; |
Shaun Nelson |
27:1753a44fa9ec | 50 | data.accel_z = accel_data[2]; |
Shaun Nelson |
27:1753a44fa9ec | 51 | /* z-axis : > 0 = rightside up, < 0 upside down |
Shaun Nelson |
27:1753a44fa9ec | 52 | * x-axis: com LED to the left x < 0, x > 0 on the right |
Shaun Nelson |
27:1753a44fa9ec | 53 | * y-axis: y > 0 COM LED down, y < 0 COM LED up |
Shaun Nelson |
27:1753a44fa9ec | 54 | */ |
Shaun Nelson |
27:1753a44fa9ec | 55 | data.orientation.init(); |
Shaun Nelson |
27:1753a44fa9ec | 56 | |
Shaun Nelson |
27:1753a44fa9ec | 57 | // rightside up |
Shaun Nelson |
27:1753a44fa9ec | 58 | if(data.accel_z >= 750) |
Shaun Nelson |
27:1753a44fa9ec | 59 | { |
Shaun Nelson |
27:1753a44fa9ec | 60 | data.orientation.horizontal = true; |
Shaun Nelson |
27:1753a44fa9ec | 61 | } |
Shaun Nelson |
27:1753a44fa9ec | 62 | // upside down |
Shaun Nelson |
27:1753a44fa9ec | 63 | else if(data.accel_z <= -750) |
Shaun Nelson |
27:1753a44fa9ec | 64 | { |
Shaun Nelson |
27:1753a44fa9ec | 65 | data.orientation.horizontal = true; |
Shaun Nelson |
27:1753a44fa9ec | 66 | data.orientation.down = true; |
Shaun Nelson |
27:1753a44fa9ec | 67 | // position_value = (2 << 12) | (1 << 8); |
Shaun Nelson |
27:1753a44fa9ec | 68 | } |
Shaun Nelson |
27:1753a44fa9ec | 69 | // vertical down |
Shaun Nelson |
27:1753a44fa9ec | 70 | else if(data.accel_y >= 900 ) |
Shaun Nelson |
27:1753a44fa9ec | 71 | { |
Shaun Nelson |
27:1753a44fa9ec | 72 | data.orientation.down = true; |
Shaun Nelson |
27:1753a44fa9ec | 73 | } |
Shaun Nelson |
27:1753a44fa9ec | 74 | // vertical up |
Shaun Nelson |
27:1753a44fa9ec | 75 | else if(data.accel_y <= -900 ) |
Shaun Nelson |
27:1753a44fa9ec | 76 | { |
Shaun Nelson |
27:1753a44fa9ec | 77 | data.orientation.up = true; |
Shaun Nelson |
27:1753a44fa9ec | 78 | } |
Shaun Nelson |
27:1753a44fa9ec | 79 | // side right |
Shaun Nelson |
27:1753a44fa9ec | 80 | else if(data.accel_x > 900) |
Shaun Nelson |
27:1753a44fa9ec | 81 | { |
Shaun Nelson |
27:1753a44fa9ec | 82 | data.orientation.right = true; |
Shaun Nelson |
27:1753a44fa9ec | 83 | } |
Shaun Nelson |
27:1753a44fa9ec | 84 | // side left |
Shaun Nelson |
27:1753a44fa9ec | 85 | else |
Shaun Nelson |
27:1753a44fa9ec | 86 | { |
Shaun Nelson |
27:1753a44fa9ec | 87 | data.orientation.left = true; |
Shaun Nelson |
27:1753a44fa9ec | 88 | } |
Shaun Nelson |
27:1753a44fa9ec | 89 | |
Shaun Nelson |
27:1753a44fa9ec | 90 | /* |
Shaun Nelson |
27:1753a44fa9ec | 91 | if(horizontal) |
Shaun Nelson |
27:1753a44fa9ec | 92 | { |
Shaun Nelson |
27:1753a44fa9ec | 93 | next_value = (2 << 12) | (upsidedown << 8); |
Shaun Nelson |
27:1753a44fa9ec | 94 | } |
Shaun Nelson |
27:1753a44fa9ec | 95 | else |
Shaun Nelson |
27:1753a44fa9ec | 96 | { |
Shaun Nelson |
27:1753a44fa9ec | 97 | next_value = (up << 12) | (left << 8) | (down << 4) | right; |
Shaun Nelson |
27:1753a44fa9ec | 98 | } |
Shaun Nelson |
27:1753a44fa9ec | 99 | |
Shaun Nelson |
27:1753a44fa9ec | 100 | if(next_value != position_value) |
Shaun Nelson |
27:1753a44fa9ec | 101 | { |
Shaun Nelson |
27:1753a44fa9ec | 102 | position_value = next_value; |
Shaun Nelson |
27:1753a44fa9ec | 103 | position_changed = true; |
Shaun Nelson |
27:1753a44fa9ec | 104 | |
Shaun Nelson |
27:1753a44fa9ec | 105 | // Set reflected_value to an out of range value to stay |
Shaun Nelson |
27:1753a44fa9ec | 106 | // in fast transmit mode until server responds |
Shaun Nelson |
27:1753a44fa9ec | 107 | reflected_value = 0; |
Shaun Nelson |
27:1753a44fa9ec | 108 | |
Shaun Nelson |
27:1753a44fa9ec | 109 | // Turn LED off to indicate server is not in agreement |
Shaun Nelson |
27:1753a44fa9ec | 110 | SYNC_LED=SYNC_LED_OOS; |
Shaun Nelson |
27:1753a44fa9ec | 111 | } |
Shaun Nelson |
27:1753a44fa9ec | 112 | */ |
Shaun Nelson |
27:1753a44fa9ec | 113 | } |
Shaun Nelson |
27:1753a44fa9ec | 114 | } |
Shaun Nelson |
27:1753a44fa9ec | 115 | |
Shaun Nelson |
27:1753a44fa9ec | 116 | |
Shaun Nelson |
27:1753a44fa9ec | 117 | bool BoardCheckForExit( bool exit ) { return false; } |
Shaun Nelson |
27:1753a44fa9ec | 118 | |
Shaun Nelson |
27:1753a44fa9ec | 119 | #endif |