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/evb/board_evb.cpp@43:55e7bb4d9b60, 2017-08-30 (annotated)
- Committer:
- Shaun Nelson
- Date:
- Wed Aug 30 12:35:33 2017 -0400
- Revision:
- 43:55e7bb4d9b60
- Parent:
- 41:208af6be1869
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 | * / ____| | | |
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 | * (C) 2016 Senet, Inc |
Shaun Nelson |
27:1753a44fa9ec | 9 | * |
Shaun Nelson |
27:1753a44fa9ec | 10 | */ |
Shaun Nelson |
38:1e6370074fdc | 11 | |
Shaun Nelson |
27:1753a44fa9ec | 12 | #ifdef MTDOT_EVB |
Shaun Nelson |
38:1e6370074fdc | 13 | #include "board_evb.h" |
Shaun Nelson |
27:1753a44fa9ec | 14 | #include "MMA845x.h" |
Shaun Nelson |
27:1753a44fa9ec | 15 | #include "MPL3115A2.h" |
Shaun Nelson |
27:1753a44fa9ec | 16 | #include "ISL29011.h" |
Shaun Nelson |
27:1753a44fa9ec | 17 | #include "NCP5623B.h" |
Shaun Nelson |
27:1753a44fa9ec | 18 | #include "DOGS102.h" |
Shaun Nelson |
27:1753a44fa9ec | 19 | #include "font_6x8.h" |
Shaun Nelson |
27:1753a44fa9ec | 20 | #include "MultiTech_Logo.h" |
Shaun Nelson |
27:1753a44fa9ec | 21 | |
Shaun Nelson |
41:208af6be1869 | 22 | Serial debugUART(PA_9, PA_10); // mDot debug UART |
Shaun Nelson |
27:1753a44fa9ec | 23 | |
Shaun Nelson |
41:208af6be1869 | 24 | static InterruptIn mDot08(PA_12); // GPIO/USB PB S1 on EVB |
Shaun Nelson |
41:208af6be1869 | 25 | static InterruptIn mDot09(PA_11); // GPIO/USB PB S2 on EVB |
Shaun Nelson |
41:208af6be1869 | 26 | static InterruptIn mDot12(PA_0); // GPIO/UART_CTS PRESSURE_INT2 on EVB |
Shaun Nelson |
41:208af6be1869 | 27 | static DigitalOut mDot13(PC_13,1); // GPIO LCD_C/D |
Shaun Nelson |
41:208af6be1869 | 28 | static InterruptIn mDot15(PC_1); // GPIO LIGHT_PROX_INT on EVB |
Shaun Nelson |
41:208af6be1869 | 29 | static InterruptIn mDot16(PA_1); // GPIO/UART_RTS ACCEL_INT2 on EVB |
Shaun Nelson |
41:208af6be1869 | 30 | static DigitalOut mDot17(PA_4,1); // GPIO/SPI_NCS LCD_CS on EVB |
Shaun Nelson |
41:208af6be1869 | 31 | static AnalogIn mDot20(PB_1); // GPIO Current Sense Analog in on EVB |
Shaun Nelson |
41:208af6be1869 | 32 | static I2C mDoti2c(PC_9,PA_8); // mDot External I2C mDot6 and mDot7 |
Shaun Nelson |
41:208af6be1869 | 33 | static SPI mDotspi(PA_7,PA_6,PA_5); // mDot external SPI mDot11, mDot4, and mDot18 |
Shaun Nelson |
27:1753a44fa9ec | 34 | static MMA845x_DATA accel_data = 0; |
Shaun Nelson |
27:1753a44fa9ec | 35 | static MPL3115A2_DATA baro_data = 0; |
Shaun Nelson |
27:1753a44fa9ec | 36 | static MMA845x* evbAccel = 0; |
Shaun Nelson |
27:1753a44fa9ec | 37 | static MPL3115A2* evbBaro = 0; |
Shaun Nelson |
27:1753a44fa9ec | 38 | static ISL29011* evbAmbLight = 0; |
Shaun Nelson |
27:1753a44fa9ec | 39 | static NCP5623B* evbBackLight = 0; |
Shaun Nelson |
27:1753a44fa9ec | 40 | static DOGS102* evbLCD = 0; |
Shaun Nelson |
38:1e6370074fdc | 41 | static Thread thread_1; |
Shaun Nelson |
38:1e6370074fdc | 42 | static Thread thread_2; |
Shaun Nelson |
38:1e6370074fdc | 43 | static char txtstr[17]; |
Shaun Nelson |
27:1753a44fa9ec | 44 | // flags for pushbutton debounce code |
Shaun Nelson |
41:208af6be1869 | 45 | static bool pb1_low = false; |
Shaun Nelson |
41:208af6be1869 | 46 | static bool pb2_low = false; |
Shaun Nelson |
41:208af6be1869 | 47 | static bool evbLedState = false; |
Shaun Nelson |
27:1753a44fa9ec | 48 | |
Shaun Nelson |
28:4fd8a894a403 | 49 | CBoardEVB::CBoardEVB() |
Shaun Nelson |
28:4fd8a894a403 | 50 | { |
Shaun Nelson |
28:4fd8a894a403 | 51 | boardPtr = this; |
Shaun Nelson |
28:4fd8a894a403 | 52 | } |
Shaun Nelson |
27:1753a44fa9ec | 53 | |
Shaun Nelson |
27:1753a44fa9ec | 54 | |
Shaun Nelson |
28:4fd8a894a403 | 55 | EBoardStatus CBoardEVB::init() |
Shaun Nelson |
27:1753a44fa9ec | 56 | { |
Shaun Nelson |
28:4fd8a894a403 | 57 | CBoard::init(); |
Shaun Nelson |
28:4fd8a894a403 | 58 | |
Shaun Nelson |
27:1753a44fa9ec | 59 | // Setting up LED1 as activity LED |
Shaun Nelson |
27:1753a44fa9ec | 60 | mDotPtr->setActivityLedPin(PB_0); |
Shaun Nelson |
27:1753a44fa9ec | 61 | mDotPtr->setActivityLedEnable(true); |
Shaun Nelson |
27:1753a44fa9ec | 62 | |
Shaun Nelson |
27:1753a44fa9ec | 63 | // threads for de-bouncing pushbutton switches |
Shaun Nelson |
41:208af6be1869 | 64 | thread_1.start(callback(this, &CBoardEVB::pb1_debounce)); |
Shaun Nelson |
41:208af6be1869 | 65 | thread_2.start(callback(this, &CBoardEVB::pb2_debounce)); |
Shaun Nelson |
27:1753a44fa9ec | 66 | |
Shaun Nelson |
27:1753a44fa9ec | 67 | evbAccel = new MMA845x(mDoti2c,MMA845x::SA0_VSS); // setup Accelerometer |
Shaun Nelson |
27:1753a44fa9ec | 68 | evbBaro = new MPL3115A2(mDoti2c); // setup Barometric sensor |
Shaun Nelson |
27:1753a44fa9ec | 69 | evbAmbLight = new ISL29011(mDoti2c); // Setup Ambient Light Sensor |
Shaun Nelson |
27:1753a44fa9ec | 70 | evbBackLight = new NCP5623B(mDoti2c); // setup backlight and LED 2 driver chip |
Shaun Nelson |
27:1753a44fa9ec | 71 | evbLCD = new DOGS102(mDotspi, mDot17, mDot13); // setup LCD |
Shaun Nelson |
27:1753a44fa9ec | 72 | |
Shaun Nelson |
27:1753a44fa9ec | 73 | /* |
Shaun Nelson |
27:1753a44fa9ec | 74 | * Setup SW1 as program stop function |
Shaun Nelson |
27:1753a44fa9ec | 75 | */ |
Shaun Nelson |
27:1753a44fa9ec | 76 | mDot08.disable_irq(); |
Shaun Nelson |
41:208af6be1869 | 77 | mDot08.fall(callback(this, &CBoardEVB::pb1ISR)); |
Shaun Nelson |
27:1753a44fa9ec | 78 | |
Shaun Nelson |
27:1753a44fa9ec | 79 | /* |
Shaun Nelson |
27:1753a44fa9ec | 80 | * need to call this function after rise or fall because rise/fall sets |
Shaun Nelson |
27:1753a44fa9ec | 81 | * mode to PullNone |
Shaun Nelson |
27:1753a44fa9ec | 82 | */ |
Shaun Nelson |
27:1753a44fa9ec | 83 | mDot08.mode(PullUp); |
Shaun Nelson |
27:1753a44fa9ec | 84 | |
Shaun Nelson |
27:1753a44fa9ec | 85 | mDot08.enable_irq(); |
Shaun Nelson |
27:1753a44fa9ec | 86 | |
Shaun Nelson |
27:1753a44fa9ec | 87 | /* |
Shaun Nelson |
27:1753a44fa9ec | 88 | * Setup SW2 as packet time change |
Shaun Nelson |
27:1753a44fa9ec | 89 | */ |
Shaun Nelson |
27:1753a44fa9ec | 90 | mDot09.disable_irq(); |
Shaun Nelson |
41:208af6be1869 | 91 | mDot09.fall(callback(this, &CBoardEVB::pb2ISR)); |
Shaun Nelson |
27:1753a44fa9ec | 92 | |
Shaun Nelson |
27:1753a44fa9ec | 93 | /* |
Shaun Nelson |
27:1753a44fa9ec | 94 | * need to call this function after rise or fall because rise/fall sets |
Shaun Nelson |
27:1753a44fa9ec | 95 | * mode to PullNone |
Shaun Nelson |
27:1753a44fa9ec | 96 | */ |
Shaun Nelson |
27:1753a44fa9ec | 97 | mDot09.mode(PullUp); |
Shaun Nelson |
27:1753a44fa9ec | 98 | |
Shaun Nelson |
27:1753a44fa9ec | 99 | mDot09.enable_irq(); |
Shaun Nelson |
27:1753a44fa9ec | 100 | |
Shaun Nelson |
27:1753a44fa9ec | 101 | /* |
Shaun Nelson |
27:1753a44fa9ec | 102 | * Setting other InterruptIn pins with Pull Ups |
Shaun Nelson |
27:1753a44fa9ec | 103 | */ |
Shaun Nelson |
27:1753a44fa9ec | 104 | mDot12.mode(PullUp); |
Shaun Nelson |
27:1753a44fa9ec | 105 | mDot15.mode(PullUp); |
Shaun Nelson |
27:1753a44fa9ec | 106 | mDot16.mode(PullUp); |
Shaun Nelson |
27:1753a44fa9ec | 107 | |
Shaun Nelson |
27:1753a44fa9ec | 108 | printf("font table address %p\n\r",&font_6x8); |
Shaun Nelson |
27:1753a44fa9ec | 109 | printf("bitmap address %p\n\r",&MultiTech_Logo); |
Shaun Nelson |
27:1753a44fa9ec | 110 | |
Shaun Nelson |
27:1753a44fa9ec | 111 | // Setup and display logo on LCD |
Shaun Nelson |
27:1753a44fa9ec | 112 | evbLCD->startUpdate(); |
Shaun Nelson |
27:1753a44fa9ec | 113 | |
Shaun Nelson |
27:1753a44fa9ec | 114 | evbLCD->writeBitmap(0,0,MultiTech_Logo); |
Shaun Nelson |
27:1753a44fa9ec | 115 | |
Shaun Nelson |
27:1753a44fa9ec | 116 | sprintf(txtstr,"MTDOT"); |
Shaun Nelson |
27:1753a44fa9ec | 117 | evbLCD->writeText(24,3,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
27:1753a44fa9ec | 118 | sprintf(txtstr,"Evaluation"); |
Shaun Nelson |
27:1753a44fa9ec | 119 | evbLCD->writeText(24,4,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
27:1753a44fa9ec | 120 | sprintf(txtstr,"Board"); |
Shaun Nelson |
27:1753a44fa9ec | 121 | evbLCD->writeText(24,5,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
27:1753a44fa9ec | 122 | |
Shaun Nelson |
27:1753a44fa9ec | 123 | evbLCD->endUpdate(); |
Shaun Nelson |
27:1753a44fa9ec | 124 | |
Shaun Nelson |
28:4fd8a894a403 | 125 | return Board_Ok; |
Shaun Nelson |
27:1753a44fa9ec | 126 | } |
Shaun Nelson |
27:1753a44fa9ec | 127 | |
Shaun Nelson |
28:4fd8a894a403 | 128 | EBoardStatus CBoardEVB::start() |
Shaun Nelson |
27:1753a44fa9ec | 129 | { |
Shaun Nelson |
27:1753a44fa9ec | 130 | osDelay(200); |
Shaun Nelson |
27:1753a44fa9ec | 131 | evbBackLight->setPWM(NCP5623B::LED_3,16); // enable LED2 on EVB and set to 50% PWM |
Shaun Nelson |
27:1753a44fa9ec | 132 | |
Shaun Nelson |
27:1753a44fa9ec | 133 | // sets LED2 to 50% max current |
Shaun Nelson |
27:1753a44fa9ec | 134 | evbBackLight->setLEDCurrent(16); |
Shaun Nelson |
27:1753a44fa9ec | 135 | |
Shaun Nelson |
27:1753a44fa9ec | 136 | printf("Start of Test\n\r"); |
Shaun Nelson |
27:1753a44fa9ec | 137 | |
Shaun Nelson |
27:1753a44fa9ec | 138 | osDelay (500); // allows other threads to process |
Shaun Nelson |
27:1753a44fa9ec | 139 | printf("shutdown LED:\n\r"); |
Shaun Nelson |
27:1753a44fa9ec | 140 | evbBackLight->shutdown(); |
Shaun Nelson |
27:1753a44fa9ec | 141 | |
Shaun Nelson |
27:1753a44fa9ec | 142 | osDelay (500); // allows other threads to process |
Shaun Nelson |
27:1753a44fa9ec | 143 | printf("Turn on LED2\n\r"); |
Shaun Nelson |
27:1753a44fa9ec | 144 | evbBackLight->setLEDCurrent(16); |
Shaun Nelson |
27:1753a44fa9ec | 145 | |
Shaun Nelson |
38:1e6370074fdc | 146 | char data = evbAccel->getWhoAmI(); |
Shaun Nelson |
27:1753a44fa9ec | 147 | printf("Accelerometer who_am_i value = %x \n\r", data); |
Shaun Nelson |
27:1753a44fa9ec | 148 | |
Shaun Nelson |
38:1e6370074fdc | 149 | uint8_t result = evbAccel->getStatus(); |
Shaun Nelson |
27:1753a44fa9ec | 150 | printf("status byte = %x \n\r", result); |
Shaun Nelson |
27:1753a44fa9ec | 151 | |
Shaun Nelson |
27:1753a44fa9ec | 152 | printf("Barometer who_am_i check = %s \n\r", evbBaro->testWhoAmI() ? "TRUE" : "FALSE"); |
Shaun Nelson |
27:1753a44fa9ec | 153 | |
Shaun Nelson |
27:1753a44fa9ec | 154 | result = evbBaro->getStatus(); |
Shaun Nelson |
27:1753a44fa9ec | 155 | printf("status byte = %x \n\r", result); |
Shaun Nelson |
27:1753a44fa9ec | 156 | |
Shaun Nelson |
27:1753a44fa9ec | 157 | /* |
Shaun Nelson |
27:1753a44fa9ec | 158 | * Setup the Accelerometer for 8g range, 14 bit resolution, Noise reduction off, sample rate 1.56 Hz |
Shaun Nelson |
27:1753a44fa9ec | 159 | * normal oversample mode, High pass filter off |
Shaun Nelson |
27:1753a44fa9ec | 160 | */ |
Shaun Nelson |
27:1753a44fa9ec | 161 | evbAccel->setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF, |
Shaun Nelson |
27:1753a44fa9ec | 162 | MMA845x::DR_1_56,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); |
Shaun Nelson |
27:1753a44fa9ec | 163 | |
Shaun Nelson |
27:1753a44fa9ec | 164 | /* |
Shaun Nelson |
27:1753a44fa9ec | 165 | * Setup the Barometric sensor for post processed Ambient pressure, 4 samples per data acquisition. |
Shaun Nelson |
27:1753a44fa9ec | 166 | * and a sample taken every second when in active mode |
Shaun Nelson |
27:1753a44fa9ec | 167 | */ |
Shaun Nelson |
27:1753a44fa9ec | 168 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, MPL3115A2::AT_1); |
Shaun Nelson |
27:1753a44fa9ec | 169 | |
Shaun Nelson |
27:1753a44fa9ec | 170 | /* |
Shaun Nelson |
27:1753a44fa9ec | 171 | * Setup the Ambient Light Sensor for continuous Ambient Light Sensing, 16 bit resolution, |
Shaun Nelson |
27:1753a44fa9ec | 172 | * and 16000 lux range |
Shaun Nelson |
27:1753a44fa9ec | 173 | */ |
Shaun Nelson |
27:1753a44fa9ec | 174 | evbAmbLight->setMode(ISL29011::ALS_CONT); |
Shaun Nelson |
27:1753a44fa9ec | 175 | evbAmbLight->setResolution(ISL29011::ADC_16BIT); |
Shaun Nelson |
27:1753a44fa9ec | 176 | evbAmbLight->setRange(ISL29011::RNG_16000); |
Shaun Nelson |
27:1753a44fa9ec | 177 | |
Shaun Nelson |
27:1753a44fa9ec | 178 | /* |
Shaun Nelson |
27:1753a44fa9ec | 179 | * Set the accelerometer for active mode |
Shaun Nelson |
27:1753a44fa9ec | 180 | */ |
Shaun Nelson |
27:1753a44fa9ec | 181 | evbAccel->activeMode(); |
Shaun Nelson |
27:1753a44fa9ec | 182 | |
Shaun Nelson |
27:1753a44fa9ec | 183 | /* |
Shaun Nelson |
27:1753a44fa9ec | 184 | * Clear the min-max registers in the Barometric Sensor |
Shaun Nelson |
27:1753a44fa9ec | 185 | */ |
Shaun Nelson |
27:1753a44fa9ec | 186 | evbBaro->clearMinMaxRegs(); |
Shaun Nelson |
27:1753a44fa9ec | 187 | |
Shaun Nelson |
27:1753a44fa9ec | 188 | evbBackLight->setLEDCurrent(0); |
Shaun Nelson |
28:4fd8a894a403 | 189 | |
Shaun Nelson |
28:4fd8a894a403 | 190 | return Board_Ok; |
Shaun Nelson |
27:1753a44fa9ec | 191 | } |
Shaun Nelson |
27:1753a44fa9ec | 192 | |
Shaun Nelson |
38:1e6370074fdc | 193 | EBoardStatus CBoardEVB::readSensors ( BoardSensorData &sensorData ) |
Shaun Nelson |
28:4fd8a894a403 | 194 | { |
Shaun Nelson |
28:4fd8a894a403 | 195 | MMA845x_DATA accel_data; |
Shaun Nelson |
38:1e6370074fdc | 196 | uint8_t result; |
Shaun Nelson |
38:1e6370074fdc | 197 | int32_t num_whole; |
Shaun Nelson |
38:1e6370074fdc | 198 | uint32_t pressure; |
Shaun Nelson |
38:1e6370074fdc | 199 | int16_t num_frac; |
Shaun Nelson |
28:4fd8a894a403 | 200 | |
Shaun Nelson |
38:1e6370074fdc | 201 | sensorData.init(); |
Shaun Nelson |
28:4fd8a894a403 | 202 | |
Shaun Nelson |
28:4fd8a894a403 | 203 | // Update accelerometer state |
Shaun Nelson |
28:4fd8a894a403 | 204 | evbLCD->startUpdate(); |
Shaun Nelson |
28:4fd8a894a403 | 205 | evbLCD->clearBuffer(); |
Shaun Nelson |
28:4fd8a894a403 | 206 | |
Shaun Nelson |
38:1e6370074fdc | 207 | /* |
Shaun Nelson |
38:1e6370074fdc | 208 | * Retrieve and print out accelerometer data |
Shaun Nelson |
38:1e6370074fdc | 209 | */ |
Shaun Nelson |
38:1e6370074fdc | 210 | for(uint32_t i = 0; i < 10; i++) |
Shaun Nelson |
28:4fd8a894a403 | 211 | { |
Shaun Nelson |
38:1e6370074fdc | 212 | osDelay(100); // allows other threads to process |
Shaun Nelson |
38:1e6370074fdc | 213 | |
Shaun Nelson |
38:1e6370074fdc | 214 | result = evbAccel->getStatus(); |
Shaun Nelson |
38:1e6370074fdc | 215 | |
Shaun Nelson |
38:1e6370074fdc | 216 | if( result & MMA845x::XYZDR ) |
Shaun Nelson |
38:1e6370074fdc | 217 | { |
Shaun Nelson |
38:1e6370074fdc | 218 | accel_data = evbAccel->getXYZ(); |
Shaun Nelson |
38:1e6370074fdc | 219 | |
Shaun Nelson |
38:1e6370074fdc | 220 | sprintf(txtstr,"Accelerometer"); |
Shaun Nelson |
38:1e6370074fdc | 221 | evbLCD->writeText(0,0,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 222 | sprintf(txtstr, "x = %d", accel_data._x); |
Shaun Nelson |
38:1e6370074fdc | 223 | evbLCD->writeText(20,1,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 224 | sprintf(txtstr, "y = %d", accel_data._y); |
Shaun Nelson |
38:1e6370074fdc | 225 | evbLCD->writeText(20,2,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 226 | sprintf(txtstr, "z = %d", accel_data._z ); |
Shaun Nelson |
38:1e6370074fdc | 227 | evbLCD->writeText(20,3,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 228 | |
Shaun Nelson |
38:1e6370074fdc | 229 | sensorData.accel_x = accel_data._x; |
Shaun Nelson |
38:1e6370074fdc | 230 | sensorData.accel_y = accel_data._y; |
Shaun Nelson |
38:1e6370074fdc | 231 | sensorData.accel_z = accel_data._z; |
Shaun Nelson |
38:1e6370074fdc | 232 | |
Shaun Nelson |
38:1e6370074fdc | 233 | sensorData.orientation.vertical = abs(accel_data._x > 600); |
Shaun Nelson |
38:1e6370074fdc | 234 | |
Shaun Nelson |
38:1e6370074fdc | 235 | break; |
Shaun Nelson |
38:1e6370074fdc | 236 | } |
Shaun Nelson |
28:4fd8a894a403 | 237 | } |
Shaun Nelson |
28:4fd8a894a403 | 238 | |
Shaun Nelson |
38:1e6370074fdc | 239 | /* |
Shaun Nelson |
28:4fd8a894a403 | 240 | * Trigger a Pressure reading |
Shaun Nelson |
28:4fd8a894a403 | 241 | */ |
Shaun Nelson |
28:4fd8a894a403 | 242 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, |
Shaun Nelson |
28:4fd8a894a403 | 243 | MPL3115A2::AT_1); |
Shaun Nelson |
38:1e6370074fdc | 244 | |
Shaun Nelson |
28:4fd8a894a403 | 245 | evbBaro->triggerOneShot(); |
Shaun Nelson |
28:4fd8a894a403 | 246 | |
Shaun Nelson |
28:4fd8a894a403 | 247 | /* |
Shaun Nelson |
28:4fd8a894a403 | 248 | * Retrieve and print out barometric pressure |
Shaun Nelson |
28:4fd8a894a403 | 249 | */ |
Shaun Nelson |
38:1e6370074fdc | 250 | for(uint32_t i = 0; i < 10; i++) |
Shaun Nelson |
38:1e6370074fdc | 251 | { |
Shaun Nelson |
38:1e6370074fdc | 252 | osDelay(100); // allows other threads to process |
Shaun Nelson |
38:1e6370074fdc | 253 | result = evbBaro->getStatus(); |
Shaun Nelson |
38:1e6370074fdc | 254 | if( result & MPL3115A2::PTDR) |
Shaun Nelson |
38:1e6370074fdc | 255 | { |
Shaun Nelson |
38:1e6370074fdc | 256 | pressure = evbBaro->getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value |
Shaun Nelson |
38:1e6370074fdc | 257 | num_whole = pressure >> 2; // 18 bit integer significant |
Shaun Nelson |
38:1e6370074fdc | 258 | num_frac = (pressure & 0x3) * 25; // 2 bit fractional 0.25 per bit |
Shaun Nelson |
38:1e6370074fdc | 259 | sensorData.pressure = pressure + (.25 * num_frac); |
Shaun Nelson |
28:4fd8a894a403 | 260 | |
Shaun Nelson |
38:1e6370074fdc | 261 | sprintf(txtstr,"Press=%ld.%02d Pa", num_whole, num_frac); |
Shaun Nelson |
38:1e6370074fdc | 262 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 263 | |
Shaun Nelson |
38:1e6370074fdc | 264 | break; |
Shaun Nelson |
38:1e6370074fdc | 265 | } |
Shaun Nelson |
38:1e6370074fdc | 266 | } |
Shaun Nelson |
38:1e6370074fdc | 267 | |
Shaun Nelson |
28:4fd8a894a403 | 268 | |
Shaun Nelson |
28:4fd8a894a403 | 269 | /* |
Shaun Nelson |
28:4fd8a894a403 | 270 | * Trigger a Altitude reading |
Shaun Nelson |
28:4fd8a894a403 | 271 | */ |
Shaun Nelson |
28:4fd8a894a403 | 272 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_ALTIMETER, MPL3115A2::OR_16, |
Shaun Nelson |
28:4fd8a894a403 | 273 | MPL3115A2::AT_1); |
Shaun Nelson |
28:4fd8a894a403 | 274 | evbBaro->triggerOneShot(); |
Shaun Nelson |
28:4fd8a894a403 | 275 | |
Shaun Nelson |
28:4fd8a894a403 | 276 | |
Shaun Nelson |
28:4fd8a894a403 | 277 | /* |
Shaun Nelson |
28:4fd8a894a403 | 278 | * Retrieve and print out altitude and temperature |
Shaun Nelson |
28:4fd8a894a403 | 279 | */ |
Shaun Nelson |
38:1e6370074fdc | 280 | for(uint32_t i = 0; i < 10; i++) |
Shaun Nelson |
38:1e6370074fdc | 281 | { |
Shaun Nelson |
38:1e6370074fdc | 282 | osDelay(100); // allows other threads to process |
Shaun Nelson |
38:1e6370074fdc | 283 | result = evbBaro->getStatus(); |
Shaun Nelson |
38:1e6370074fdc | 284 | if( result & MPL3115A2::PTDR) |
Shaun Nelson |
38:1e6370074fdc | 285 | { |
Shaun Nelson |
38:1e6370074fdc | 286 | baro_data = evbBaro->getAllData(false); |
Shaun Nelson |
38:1e6370074fdc | 287 | baro_data._baro /= 4096; // convert 32 bit signed to 20 bit signed value |
Shaun Nelson |
38:1e6370074fdc | 288 | num_whole = baro_data._baro / 16; // 18 bit signed significant integer |
Shaun Nelson |
38:1e6370074fdc | 289 | num_frac = (baro_data._baro & 0xF) * 625 / 100; // 4 bit fractional .0625 per bit |
Shaun Nelson |
38:1e6370074fdc | 290 | sprintf(txtstr,"Alti=%ld.%03d m", num_whole, num_frac); |
Shaun Nelson |
38:1e6370074fdc | 291 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 292 | num_whole = baro_data._temp / 16; // 8 bit signed significant integer |
Shaun Nelson |
38:1e6370074fdc | 293 | num_frac = (baro_data._temp & 0x0F) * 625 / 100; // 4 bit fractional .0625 per bit |
Shaun Nelson |
38:1e6370074fdc | 294 | sensorData.temperature = num_whole + ((float)num_frac / 100); |
Shaun Nelson |
38:1e6370074fdc | 295 | sprintf(txtstr,"Temp=%ld.%03d C", num_whole, num_frac); |
Shaun Nelson |
38:1e6370074fdc | 296 | evbLCD->writeText(0,6,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
38:1e6370074fdc | 297 | |
Shaun Nelson |
38:1e6370074fdc | 298 | break; |
Shaun Nelson |
38:1e6370074fdc | 299 | } |
Shaun Nelson |
38:1e6370074fdc | 300 | } |
Shaun Nelson |
38:1e6370074fdc | 301 | |
Shaun Nelson |
28:4fd8a894a403 | 302 | |
Shaun Nelson |
28:4fd8a894a403 | 303 | /* |
Shaun Nelson |
28:4fd8a894a403 | 304 | * retrieve and print out Ambient Light level |
Shaun Nelson |
28:4fd8a894a403 | 305 | */ |
Shaun Nelson |
38:1e6370074fdc | 306 | uint16_t lux_data = evbAmbLight->getData(); |
Shaun Nelson |
28:4fd8a894a403 | 307 | num_whole = lux_data * 24 / 100; // 16000 lux full scale .24 lux per bit |
Shaun Nelson |
28:4fd8a894a403 | 308 | num_frac = lux_data * 24 % 100; |
Shaun Nelson |
28:4fd8a894a403 | 309 | sprintf(txtstr, "Light=%ld.%02d lux", num_whole, num_frac ); |
Shaun Nelson |
28:4fd8a894a403 | 310 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
Shaun Nelson |
28:4fd8a894a403 | 311 | |
Shaun Nelson |
28:4fd8a894a403 | 312 | evbLCD->endUpdate(); |
Shaun Nelson |
28:4fd8a894a403 | 313 | |
Shaun Nelson |
28:4fd8a894a403 | 314 | return Board_Ok; |
Shaun Nelson |
28:4fd8a894a403 | 315 | } |
Shaun Nelson |
28:4fd8a894a403 | 316 | |
Shaun Nelson |
39:022b327d6bf0 | 317 | EBoardStatus CBoardEVB::setLED(uint8_t ledNum, bool on) |
Shaun Nelson |
39:022b327d6bf0 | 318 | { |
Shaun Nelson |
39:022b327d6bf0 | 319 | if(ledNum != 1) |
Shaun Nelson |
39:022b327d6bf0 | 320 | return Board_Invalid; |
Shaun Nelson |
39:022b327d6bf0 | 321 | |
Shaun Nelson |
39:022b327d6bf0 | 322 | evbBackLight->setLEDCurrent(on ? 16 : 0); |
Shaun Nelson |
39:022b327d6bf0 | 323 | evbLedState = on; |
Shaun Nelson |
39:022b327d6bf0 | 324 | return Board_Ok; |
Shaun Nelson |
39:022b327d6bf0 | 325 | } |
Shaun Nelson |
39:022b327d6bf0 | 326 | |
Shaun Nelson |
39:022b327d6bf0 | 327 | EBoardStatus CBoardEVB::toggleLED(uint8_t ledNum) |
Shaun Nelson |
39:022b327d6bf0 | 328 | { |
Shaun Nelson |
39:022b327d6bf0 | 329 | if(ledNum != 1) |
Shaun Nelson |
39:022b327d6bf0 | 330 | return Board_Invalid; |
Shaun Nelson |
39:022b327d6bf0 | 331 | |
Shaun Nelson |
39:022b327d6bf0 | 332 | evbLedState = !evbLedState; |
Shaun Nelson |
39:022b327d6bf0 | 333 | evbBackLight->setLEDCurrent(evbLedState ? 16 : 0); |
Shaun Nelson |
39:022b327d6bf0 | 334 | return Board_Ok; |
Shaun Nelson |
39:022b327d6bf0 | 335 | } |
Shaun Nelson |
39:022b327d6bf0 | 336 | |
Shaun Nelson |
41:208af6be1869 | 337 | void CBoardEVB::pb1ISR(void) |
Shaun Nelson |
27:1753a44fa9ec | 338 | { |
Shaun Nelson |
27:1753a44fa9ec | 339 | if (!pb1_low) |
Shaun Nelson |
27:1753a44fa9ec | 340 | pb1_low = true; |
Shaun Nelson |
27:1753a44fa9ec | 341 | } |
Shaun Nelson |
27:1753a44fa9ec | 342 | |
Shaun Nelson |
41:208af6be1869 | 343 | void CBoardEVB::pb1_debounce() |
Shaun Nelson |
27:1753a44fa9ec | 344 | { |
Shaun Nelson |
27:1753a44fa9ec | 345 | static uint8_t count = 0; |
Shaun Nelson |
27:1753a44fa9ec | 346 | |
Shaun Nelson |
27:1753a44fa9ec | 347 | while (true) { |
Shaun Nelson |
27:1753a44fa9ec | 348 | if (pb1_low && (mDot08 == 0)) |
Shaun Nelson |
27:1753a44fa9ec | 349 | count++; |
Shaun Nelson |
27:1753a44fa9ec | 350 | else { |
Shaun Nelson |
27:1753a44fa9ec | 351 | count = 0; |
Shaun Nelson |
27:1753a44fa9ec | 352 | pb1_low = false; |
Shaun Nelson |
27:1753a44fa9ec | 353 | } |
Shaun Nelson |
27:1753a44fa9ec | 354 | |
Shaun Nelson |
41:208af6be1869 | 355 | if (count == 5){ |
Shaun Nelson |
41:208af6be1869 | 356 | if(buttonCallback != 0) |
Shaun Nelson |
41:208af6be1869 | 357 | buttonCallback(1); |
Shaun Nelson |
41:208af6be1869 | 358 | } |
Shaun Nelson |
27:1753a44fa9ec | 359 | |
Shaun Nelson |
27:1753a44fa9ec | 360 | Thread::wait(5); |
Shaun Nelson |
27:1753a44fa9ec | 361 | } |
Shaun Nelson |
27:1753a44fa9ec | 362 | } |
Shaun Nelson |
27:1753a44fa9ec | 363 | |
Shaun Nelson |
41:208af6be1869 | 364 | void CBoardEVB::pb2ISR(void) |
Shaun Nelson |
27:1753a44fa9ec | 365 | { |
Shaun Nelson |
27:1753a44fa9ec | 366 | if (!pb2_low) |
Shaun Nelson |
27:1753a44fa9ec | 367 | pb2_low = true; |
Shaun Nelson |
27:1753a44fa9ec | 368 | } |
Shaun Nelson |
27:1753a44fa9ec | 369 | |
Shaun Nelson |
41:208af6be1869 | 370 | void CBoardEVB::pb2_debounce() |
Shaun Nelson |
27:1753a44fa9ec | 371 | { |
Shaun Nelson |
27:1753a44fa9ec | 372 | static uint8_t count = 0; |
Shaun Nelson |
27:1753a44fa9ec | 373 | |
Shaun Nelson |
27:1753a44fa9ec | 374 | while (true) { |
Shaun Nelson |
27:1753a44fa9ec | 375 | |
Shaun Nelson |
27:1753a44fa9ec | 376 | if (pb2_low && (mDot09 == 0)) |
Shaun Nelson |
27:1753a44fa9ec | 377 | count++; |
Shaun Nelson |
27:1753a44fa9ec | 378 | else { |
Shaun Nelson |
27:1753a44fa9ec | 379 | count = 0; |
Shaun Nelson |
27:1753a44fa9ec | 380 | pb2_low = false; |
Shaun Nelson |
27:1753a44fa9ec | 381 | } |
Shaun Nelson |
27:1753a44fa9ec | 382 | |
Shaun Nelson |
27:1753a44fa9ec | 383 | if (count == 5){ |
Shaun Nelson |
27:1753a44fa9ec | 384 | |
Shaun Nelson |
41:208af6be1869 | 385 | if(buttonCallback != 0) |
Shaun Nelson |
41:208af6be1869 | 386 | buttonCallback(2); |
Shaun Nelson |
41:208af6be1869 | 387 | |
Shaun Nelson |
27:1753a44fa9ec | 388 | } |
Shaun Nelson |
27:1753a44fa9ec | 389 | Thread::wait(5); |
Shaun Nelson |
27:1753a44fa9ec | 390 | } |
Shaun Nelson |
27:1753a44fa9ec | 391 | } |
Shaun Nelson |
27:1753a44fa9ec | 392 | |
Shaun Nelson |
27:1753a44fa9ec | 393 | |
Shaun Nelson |
27:1753a44fa9ec | 394 | #endif |