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@43:55e7bb4d9b60, 2017-08-30 (annotated)
- Committer:
- Shaun Nelson
- Date:
- Wed Aug 30 12:35:33 2017 -0400
- Revision:
- 43:55e7bb4d9b60
- Parent:
- 42:ebb58fea302b
Simplified orientation change detection
Implement button press events
EVB Button1(left) for backend enabled state status (2 sblink = disabled, 3 = enabled)
EVB Button2(right) toggle bacend enabled status
LED Behavior
- LED solid when backend out of sync
- LED blinks on downlink
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 |
28:4fd8a894a403 | 14 | #include "board_udk.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 |
39:022b327d6bf0 | 20 | DigitalOut led1(PA_0); |
Shaun Nelson |
27:1753a44fa9ec | 21 | static X_NUCLEO_IKS01A1 *mems_shield; |
Shaun Nelson |
27:1753a44fa9ec | 22 | |
Shaun Nelson |
27:1753a44fa9ec | 23 | |
Shaun Nelson |
28:4fd8a894a403 | 24 | CBoardUDK::CBoardUDK() |
Shaun Nelson |
27:1753a44fa9ec | 25 | { |
Shaun Nelson |
28:4fd8a894a403 | 26 | boardPtr = this; |
Shaun Nelson |
27:1753a44fa9ec | 27 | } |
Shaun Nelson |
27:1753a44fa9ec | 28 | |
Shaun Nelson |
28:4fd8a894a403 | 29 | EBoardStatus CBoardUDK::init() |
Shaun Nelson |
28:4fd8a894a403 | 30 | { |
Shaun Nelson |
28:4fd8a894a403 | 31 | CBoard::init(); |
Shaun Nelson |
28:4fd8a894a403 | 32 | mems_shield = X_NUCLEO_IKS01A1::Instance(NULL, NC); |
Shaun Nelson |
27:1753a44fa9ec | 33 | |
Shaun Nelson |
28:4fd8a894a403 | 34 | return Board_Ok; |
Shaun Nelson |
28:4fd8a894a403 | 35 | } |
Shaun Nelson |
28:4fd8a894a403 | 36 | |
Shaun Nelson |
28:4fd8a894a403 | 37 | EBoardStatus CBoardUDK::readSensors ( BoardSensorData &data ) |
Shaun Nelson |
27:1753a44fa9ec | 38 | { |
Shaun Nelson |
27:1753a44fa9ec | 39 | uint32_t ret = 0; |
Shaun Nelson |
27:1753a44fa9ec | 40 | int32_t accel_data[3]; |
Shaun Nelson |
27:1753a44fa9ec | 41 | |
Shaun Nelson |
27:1753a44fa9ec | 42 | // Temperature |
Shaun Nelson |
27:1753a44fa9ec | 43 | ret |= (!CALL_METH(mems_shield->pt_sensor, GetTemperature, &data.temperature, 0.0f) ? 0x0 : 0x1); |
Shaun Nelson |
27:1753a44fa9ec | 44 | |
Shaun Nelson |
27:1753a44fa9ec | 45 | // Pressure |
Shaun Nelson |
27:1753a44fa9ec | 46 | ret |= (!CALL_METH(mems_shield->pt_sensor, GetPressure, &data.pressure, 0.0f) ? 0x0 : 0x1); |
Shaun Nelson |
27:1753a44fa9ec | 47 | |
Shaun Nelson |
27:1753a44fa9ec | 48 | // Accelerometer |
Shaun Nelson |
27:1753a44fa9ec | 49 | MotionSensor *motionSensor = mems_shield->GetAccelerometer(); |
Shaun Nelson |
27:1753a44fa9ec | 50 | if( motionSensor != NULL) |
Shaun Nelson |
27:1753a44fa9ec | 51 | { |
Shaun Nelson |
27:1753a44fa9ec | 52 | motionSensor->Get_X_Axes(accel_data); |
Shaun Nelson |
27:1753a44fa9ec | 53 | |
Shaun Nelson |
27:1753a44fa9ec | 54 | data.accel_x = accel_data[0]; |
Shaun Nelson |
27:1753a44fa9ec | 55 | data.accel_y = accel_data[1]; |
Shaun Nelson |
27:1753a44fa9ec | 56 | data.accel_z = accel_data[2]; |
Shaun Nelson |
27:1753a44fa9ec | 57 | /* z-axis : > 0 = rightside up, < 0 upside down |
Shaun Nelson |
27:1753a44fa9ec | 58 | * x-axis: com LED to the left x < 0, x > 0 on the right |
Shaun Nelson |
27:1753a44fa9ec | 59 | * y-axis: y > 0 COM LED down, y < 0 COM LED up |
Shaun Nelson |
27:1753a44fa9ec | 60 | */ |
Shaun Nelson |
27:1753a44fa9ec | 61 | data.orientation.init(); |
Shaun Nelson |
27:1753a44fa9ec | 62 | |
Shaun Nelson |
27:1753a44fa9ec | 63 | // rightside up |
Shaun Nelson |
27:1753a44fa9ec | 64 | if(data.accel_z >= 750) |
Shaun Nelson |
27:1753a44fa9ec | 65 | { |
Shaun Nelson |
28:4fd8a894a403 | 66 | // data.orientation.horizontal = true; |
Shaun Nelson |
27:1753a44fa9ec | 67 | } |
Shaun Nelson |
27:1753a44fa9ec | 68 | // upside down |
Shaun Nelson |
27:1753a44fa9ec | 69 | else if(data.accel_z <= -750) |
Shaun Nelson |
27:1753a44fa9ec | 70 | { |
Shaun Nelson |
28:4fd8a894a403 | 71 | data.orientation.down = true; |
Shaun Nelson |
27:1753a44fa9ec | 72 | // position_value = (2 << 12) | (1 << 8); |
Shaun Nelson |
27:1753a44fa9ec | 73 | } |
Shaun Nelson |
27:1753a44fa9ec | 74 | // vertical down |
Shaun Nelson |
27:1753a44fa9ec | 75 | else if(data.accel_y >= 900 ) |
Shaun Nelson |
27:1753a44fa9ec | 76 | { |
Shaun Nelson |
28:4fd8a894a403 | 77 | data.orientation.vertical = true; |
Shaun Nelson |
28:4fd8a894a403 | 78 | data.orientation.down = true; |
Shaun Nelson |
27:1753a44fa9ec | 79 | } |
Shaun Nelson |
27:1753a44fa9ec | 80 | // vertical up |
Shaun Nelson |
27:1753a44fa9ec | 81 | else if(data.accel_y <= -900 ) |
Shaun Nelson |
27:1753a44fa9ec | 82 | { |
Shaun Nelson |
28:4fd8a894a403 | 83 | data.orientation.vertical = true; |
Shaun Nelson |
28:4fd8a894a403 | 84 | data.orientation.up = true; |
Shaun Nelson |
27:1753a44fa9ec | 85 | } |
Shaun Nelson |
27:1753a44fa9ec | 86 | // side right |
Shaun Nelson |
27:1753a44fa9ec | 87 | else if(data.accel_x > 900) |
Shaun Nelson |
27:1753a44fa9ec | 88 | { |
Shaun Nelson |
27:1753a44fa9ec | 89 | data.orientation.right = true; |
Shaun Nelson |
27:1753a44fa9ec | 90 | } |
Shaun Nelson |
27:1753a44fa9ec | 91 | // side left |
Shaun Nelson |
27:1753a44fa9ec | 92 | else |
Shaun Nelson |
27:1753a44fa9ec | 93 | { |
Shaun Nelson |
27:1753a44fa9ec | 94 | data.orientation.left = true; |
Shaun Nelson |
27:1753a44fa9ec | 95 | } |
Shaun Nelson |
28:4fd8a894a403 | 96 | } |
Shaun Nelson |
27:1753a44fa9ec | 97 | |
Shaun Nelson |
28:4fd8a894a403 | 98 | return Board_Ok; |
Shaun Nelson |
27:1753a44fa9ec | 99 | } |
Shaun Nelson |
27:1753a44fa9ec | 100 | |
Shaun Nelson |
42:ebb58fea302b | 101 | EBoardStatus CBoardUDK::setLED(uint8_t ledNum, bool on) |
Shaun Nelson |
39:022b327d6bf0 | 102 | { |
Shaun Nelson |
39:022b327d6bf0 | 103 | if(ledNum == 1) |
Shaun Nelson |
39:022b327d6bf0 | 104 | { |
Shaun Nelson |
39:022b327d6bf0 | 105 | led1 = on ? 0 : 1; |
Shaun Nelson |
39:022b327d6bf0 | 106 | return Board_Ok; |
Shaun Nelson |
39:022b327d6bf0 | 107 | } |
Shaun Nelson |
39:022b327d6bf0 | 108 | return Board_Invalid; |
Shaun Nelson |
39:022b327d6bf0 | 109 | } |
Shaun Nelson |
39:022b327d6bf0 | 110 | |
Shaun Nelson |
42:ebb58fea302b | 111 | EBoardStatus CBoardUDK::toggleLED(uint8_t ledNum) |
Shaun Nelson |
39:022b327d6bf0 | 112 | { |
Shaun Nelson |
39:022b327d6bf0 | 113 | if(ledNum == 1) |
Shaun Nelson |
39:022b327d6bf0 | 114 | { |
Shaun Nelson |
39:022b327d6bf0 | 115 | led1 = !led1; |
Shaun Nelson |
39:022b327d6bf0 | 116 | return Board_Ok; |
Shaun Nelson |
39:022b327d6bf0 | 117 | } |
Shaun Nelson |
39:022b327d6bf0 | 118 | return Board_Invalid; |
Shaun Nelson |
39:022b327d6bf0 | 119 | } |
Shaun Nelson |
39:022b327d6bf0 | 120 | |
Shaun Nelson |
27:1753a44fa9ec | 121 | #endif |