lab 7 code

Dependencies:   MPL3115A2 mbed

Committer:
m0t0
Date:
Sat Mar 10 15:52:30 2018 +0000
Revision:
2:10322e272717
Parent:
1:2a6907395c5d
lab 7;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m0t0 0:4350259cf0d0 1 #include "mbed.h"
m0t0 0:4350259cf0d0 2 #include "MPL3115A2.h"
m0t0 1:2a6907395c5d 3 #include "string"
m0t0 1:2a6907395c5d 4 #include "ctype.h"
m0t0 0:4350259cf0d0 5
m0t0 0:4350259cf0d0 6 Serial pc(SERIAL_TX, SERIAL_RX);
m0t0 0:4350259cf0d0 7 DigitalOut myled(LED1);
m0t0 0:4350259cf0d0 8
m0t0 0:4350259cf0d0 9 // Selects SDA as I2C1_SDA on pin PB_7
m0t0 0:4350259cf0d0 10 // Selects SCL on I2C1_SCL on pin PB_6
m0t0 0:4350259cf0d0 11 // The I2C address of the pressure sensor is fixed at 0x60.
m0t0 0:4350259cf0d0 12 MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
m0t0 0:4350259cf0d0 13
m0t0 0:4350259cf0d0 14 struct dataPoints
m0t0 0:4350259cf0d0 15 {
m0t0 0:4350259cf0d0 16 double pres;
m0t0 1:2a6907395c5d 17 double alt;
m0t0 0:4350259cf0d0 18
m0t0 0:4350259cf0d0 19 };
m0t0 0:4350259cf0d0 20
m0t0 0:4350259cf0d0 21 int mpl3115_reg_print(int start, int length) {
m0t0 0:4350259cf0d0 22
m0t0 0:4350259cf0d0 23 if(0x00 <= start && start <=0x2D){
m0t0 0:4350259cf0d0 24 if(length==0){
m0t0 0:4350259cf0d0 25 length=46;
m0t0 0:4350259cf0d0 26 uint8_t data[1];
m0t0 0:4350259cf0d0 27 for(int i=start; i<length; i++){
m0t0 0:4350259cf0d0 28 pressure_sensor.readRegs(i, data, 1);
m0t0 0:4350259cf0d0 29 switch(i){
m0t0 0:4350259cf0d0 30 case(0x00):
m0t0 0:4350259cf0d0 31 printf("0x%x: MPL_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 32 break;
m0t0 0:4350259cf0d0 33 case(0x01):
m0t0 0:4350259cf0d0 34 printf("0x%x: MPL_OUT_P_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 35 break;
m0t0 0:4350259cf0d0 36 case(0x02):
m0t0 0:4350259cf0d0 37 printf("0x%x: MPL_OUT_P_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 38 break;
m0t0 0:4350259cf0d0 39 case(0x03):
m0t0 0:4350259cf0d0 40 printf("0x%x: MPL_OUT_P_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 41 break;
m0t0 0:4350259cf0d0 42 case(0x04):
m0t0 0:4350259cf0d0 43 printf("0x%x: MPL_OUT_T_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 44 break;
m0t0 0:4350259cf0d0 45 case(0x05):
m0t0 0:4350259cf0d0 46 printf("0x%x: MPL_OUT_T_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 47 break;
m0t0 0:4350259cf0d0 48 case(0x06):
m0t0 0:4350259cf0d0 49 printf("0x%x: MPL_DR_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 50 break;
m0t0 0:4350259cf0d0 51 case(0x07):
m0t0 0:4350259cf0d0 52 printf("0x%x: MPL_OUT_P_DELTA_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 53 break;
m0t0 0:4350259cf0d0 54 case(0x08):
m0t0 0:4350259cf0d0 55 printf("0x%x: MPL_OUT_P_DELTA_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 56 break;
m0t0 0:4350259cf0d0 57 case(0x09):
m0t0 0:4350259cf0d0 58 printf("0x%x: MPL_OUT_P_DELTA_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 59 break;
m0t0 0:4350259cf0d0 60 case(0x0A):
m0t0 0:4350259cf0d0 61 printf("0x%x: MPL_OUT_T_DELTA_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 62 break;
m0t0 0:4350259cf0d0 63 case(0x0B):
m0t0 0:4350259cf0d0 64 printf("0x%x: MPL_OUT_T_DELTA_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 65 break;
m0t0 0:4350259cf0d0 66 case(0x0C):
m0t0 0:4350259cf0d0 67 printf("0x%x: MPL_WHO_AM_I=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 68 break;
m0t0 0:4350259cf0d0 69 case(0x0D):
m0t0 0:4350259cf0d0 70 printf("0x%x: MPL_F_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 71 break;
m0t0 0:4350259cf0d0 72 case(0x0E):
m0t0 0:4350259cf0d0 73 printf("0x%x: MPL_F_DATA=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 74 break;
m0t0 0:4350259cf0d0 75 case(0x0F):
m0t0 0:4350259cf0d0 76 printf("0x%x: MPL_F_SETUP=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 77 break;
m0t0 0:4350259cf0d0 78 case(0x10):
m0t0 0:4350259cf0d0 79 printf("0x%x: MPL_TIME_DLY=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 80 break;
m0t0 0:4350259cf0d0 81 case(0x11):
m0t0 0:4350259cf0d0 82 printf("0x%x: MPL_SYSMOD=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 83 break;
m0t0 0:4350259cf0d0 84 case(0x12):
m0t0 0:4350259cf0d0 85 printf("0x%x: MPL_INT_SOURCE=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 86 break;
m0t0 0:4350259cf0d0 87 case(0x13):
m0t0 0:4350259cf0d0 88 printf("0x%x: MPL_PT_DATA_CFG=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 89 break;
m0t0 0:4350259cf0d0 90 case(0x14):
m0t0 0:4350259cf0d0 91 printf("0x%x: MPL_BAR_IN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 92 break;
m0t0 0:4350259cf0d0 93 case(0x15):
m0t0 0:4350259cf0d0 94 printf("0x%x: MPL_BAR_IN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 95 break;
m0t0 0:4350259cf0d0 96 case(0x16):
m0t0 0:4350259cf0d0 97 printf("0x%x: MPL_P_TGT_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 98 break;
m0t0 0:4350259cf0d0 99 case(0x17):
m0t0 0:4350259cf0d0 100 printf("0x%x: MPL_P_TGT_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 101 break;
m0t0 0:4350259cf0d0 102 case(0x18):
m0t0 0:4350259cf0d0 103 printf("0x%x: MPL_T_TGT=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 104 break;
m0t0 0:4350259cf0d0 105 case(0x19):
m0t0 0:4350259cf0d0 106 printf("0x%x: MPL_P_WND_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 107 break;
m0t0 0:4350259cf0d0 108 case(0x1A):
m0t0 0:4350259cf0d0 109 printf("0x%x: MPL_P_WND_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 110 break;
m0t0 0:4350259cf0d0 111 case(0x1B):
m0t0 0:4350259cf0d0 112 printf("0x%x: MPL_T_WND=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 113 break;
m0t0 0:4350259cf0d0 114 case(0x1C):
m0t0 0:4350259cf0d0 115 printf("0x%x: MPL_P_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 116 break;
m0t0 0:4350259cf0d0 117 case(0x1D):
m0t0 0:4350259cf0d0 118 printf("0x%x: MPL_P_MIN_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 119 break;
m0t0 0:4350259cf0d0 120 case(0x1E):
m0t0 0:4350259cf0d0 121 printf("0x%x: MPL_P_MIN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 122 break;
m0t0 0:4350259cf0d0 123 case(0x1F):
m0t0 0:4350259cf0d0 124 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 125 break;
m0t0 0:4350259cf0d0 126 case(0x20):
m0t0 0:4350259cf0d0 127 printf("0x%x: MPL_T_MIN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 128 break;
m0t0 0:4350259cf0d0 129 case(0x21):
m0t0 0:4350259cf0d0 130 printf("0x%x: MPL_P_MAX_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 131 break;
m0t0 0:4350259cf0d0 132 case(0x22):
m0t0 0:4350259cf0d0 133 printf("0x%x: MPL_P_MAX_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 134 break;
m0t0 0:4350259cf0d0 135 case(0x23):
m0t0 0:4350259cf0d0 136 printf("0x%x: MPL_P_MAX_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 137 break;
m0t0 0:4350259cf0d0 138 case(0x24):
m0t0 0:4350259cf0d0 139 printf("0x%x: MPL_T_MAX_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 140 break;
m0t0 0:4350259cf0d0 141 case(0x25):
m0t0 0:4350259cf0d0 142 printf("0x%x: MPL_T_MAX_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 143 break;
m0t0 0:4350259cf0d0 144 case(0x26):
m0t0 0:4350259cf0d0 145 printf("0x%x: MPL_CTRL_REG1=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 146 break;
m0t0 0:4350259cf0d0 147 case(0x27):
m0t0 0:4350259cf0d0 148 printf("0x%x: MPL_CTRL_REG2=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 149 break;
m0t0 0:4350259cf0d0 150 case(0x28):
m0t0 0:4350259cf0d0 151 printf("0x%x: MPL_CTRL_REG3=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 152 break;
m0t0 0:4350259cf0d0 153 case(0x29):
m0t0 0:4350259cf0d0 154 printf("0x%x: MPL_CTRL_REG4=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 155 break;
m0t0 0:4350259cf0d0 156 case(0x2A):
m0t0 0:4350259cf0d0 157 printf("0x%x: MPL_CTRL_REG5=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 158 break;
m0t0 0:4350259cf0d0 159 case(0x2B):
m0t0 0:4350259cf0d0 160 printf("0x%x: MPL_OFF_P=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 161 break;
m0t0 0:4350259cf0d0 162 case(0x2C):
m0t0 0:4350259cf0d0 163 printf("0x%x: MPL_OFF_T=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 164 break;
m0t0 0:4350259cf0d0 165 case(0x2D):
m0t0 0:4350259cf0d0 166 printf("0x%x: MPL_OFF_H=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 167 break;
m0t0 0:4350259cf0d0 168 case(0x2E):
m0t0 0:4350259cf0d0 169 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 170 break;
m0t0 0:4350259cf0d0 171 case(0x2F):
m0t0 0:4350259cf0d0 172 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 173 break;
m0t0 0:4350259cf0d0 174 }
m0t0 0:4350259cf0d0 175 }
m0t0 0:4350259cf0d0 176 }
m0t0 0:4350259cf0d0 177 else if(length>0){
m0t0 0:4350259cf0d0 178 uint8_t data[1];
m0t0 0:4350259cf0d0 179 for(int i=start; i<length; i++){
m0t0 0:4350259cf0d0 180 pressure_sensor.readRegs(i, data, 1);
m0t0 0:4350259cf0d0 181 switch(i){
m0t0 0:4350259cf0d0 182 case(0x00):
m0t0 0:4350259cf0d0 183 printf("0x%x: MPL_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 184 break;
m0t0 0:4350259cf0d0 185 case(0x01):
m0t0 0:4350259cf0d0 186 printf("0x%x: MPL_OUT_P_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 187 break;
m0t0 0:4350259cf0d0 188 case(0x02):
m0t0 0:4350259cf0d0 189 printf("0x%x: MPL_OUT_P_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 190 break;
m0t0 0:4350259cf0d0 191 case(0x03):
m0t0 0:4350259cf0d0 192 printf("0x%x: MPL_OUT_P_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 193 break;
m0t0 0:4350259cf0d0 194 case(0x04):
m0t0 0:4350259cf0d0 195 printf("0x%x: MPL_OUT_T_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 196 break;
m0t0 0:4350259cf0d0 197 case(0x05):
m0t0 0:4350259cf0d0 198 printf("0x%x: MPL_OUT_T_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 199 break;
m0t0 0:4350259cf0d0 200 case(0x06):
m0t0 0:4350259cf0d0 201 printf("0x%x: MPL_DR_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 202 break;
m0t0 0:4350259cf0d0 203 case(0x07):
m0t0 0:4350259cf0d0 204 printf("0x%x: MPL_OUT_P_DELTA_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 205 break;
m0t0 0:4350259cf0d0 206 case(0x08):
m0t0 0:4350259cf0d0 207 printf("0x%x: MPL_OUT_P_DELTA_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 208 break;
m0t0 0:4350259cf0d0 209 case(0x09):
m0t0 0:4350259cf0d0 210 printf("0x%x: MPL_OUT_P_DELTA_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 211 break;
m0t0 0:4350259cf0d0 212 case(0x0A):
m0t0 0:4350259cf0d0 213 printf("0x%x: MPL_OUT_T_DELTA_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 214 break;
m0t0 0:4350259cf0d0 215 case(0x0B):
m0t0 0:4350259cf0d0 216 printf("0x%x: MPL_OUT_T_DELTA_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 217 break;
m0t0 0:4350259cf0d0 218 case(0x0C):
m0t0 0:4350259cf0d0 219 printf("0x%x: MPL_WHO_AM_I=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 220 break;
m0t0 0:4350259cf0d0 221 case(0x0D):
m0t0 0:4350259cf0d0 222 printf("0x%x: MPL_F_STATUS=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 223 break;
m0t0 0:4350259cf0d0 224 case(0x0E):
m0t0 0:4350259cf0d0 225 printf("0x%x: MPL_F_DATA=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 226 break;
m0t0 0:4350259cf0d0 227 case(0x0F):
m0t0 0:4350259cf0d0 228 printf("0x%x: MPL_F_SETUP=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 229 break;
m0t0 0:4350259cf0d0 230 case(0x10):
m0t0 0:4350259cf0d0 231 printf("0x%x: MPL_TIME_DLY=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 232 break;
m0t0 0:4350259cf0d0 233 case(0x11):
m0t0 0:4350259cf0d0 234 printf("0x%x: MPL_SYSMOD=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 235 break;
m0t0 0:4350259cf0d0 236 case(0x12):
m0t0 0:4350259cf0d0 237 printf("0x%x: MPL_INT_SOURCE=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 238 break;
m0t0 0:4350259cf0d0 239 case(0x13):
m0t0 0:4350259cf0d0 240 printf("0x%x: MPL_PT_DATA_CFG=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 241 break;
m0t0 0:4350259cf0d0 242 case(0x14):
m0t0 0:4350259cf0d0 243 printf("0x%x: MPL_BAR_IN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 244 break;
m0t0 0:4350259cf0d0 245 case(0x15):
m0t0 0:4350259cf0d0 246 printf("0x%x: MPL_BAR_IN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 247 break;
m0t0 0:4350259cf0d0 248 case(0x16):
m0t0 0:4350259cf0d0 249 printf("0x%x: MPL_P_TGT_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 250 break;
m0t0 0:4350259cf0d0 251 case(0x17):
m0t0 0:4350259cf0d0 252 printf("0x%x: MPL_P_TGT_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 253 break;
m0t0 0:4350259cf0d0 254 case(0x18):
m0t0 0:4350259cf0d0 255 printf("0x%x: MPL_T_TGT=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 256 break;
m0t0 0:4350259cf0d0 257 case(0x19):
m0t0 0:4350259cf0d0 258 printf("0x%x: MPL_P_WND_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 259 break;
m0t0 0:4350259cf0d0 260 case(0x1A):
m0t0 0:4350259cf0d0 261 printf("0x%x: MPL_P_WND_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 262 break;
m0t0 0:4350259cf0d0 263 case(0x1B):
m0t0 0:4350259cf0d0 264 printf("0x%x: MPL_T_WND=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 265 break;
m0t0 0:4350259cf0d0 266 case(0x1C):
m0t0 0:4350259cf0d0 267 printf("0x%x: MPL_P_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 268 break;
m0t0 0:4350259cf0d0 269 case(0x1D):
m0t0 0:4350259cf0d0 270 printf("0x%x: MPL_P_MIN_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 271 break;
m0t0 0:4350259cf0d0 272 case(0x1E):
m0t0 0:4350259cf0d0 273 printf("0x%x: MPL_P_MIN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 274 break;
m0t0 0:4350259cf0d0 275 case(0x1F):
m0t0 0:4350259cf0d0 276 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 277 break;
m0t0 0:4350259cf0d0 278 case(0x20):
m0t0 0:4350259cf0d0 279 printf("0x%x: MPL_T_MIN_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 280 break;
m0t0 0:4350259cf0d0 281 case(0x21):
m0t0 0:4350259cf0d0 282 printf("0x%x: MPL_P_MAX_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 283 break;
m0t0 0:4350259cf0d0 284 case(0x22):
m0t0 0:4350259cf0d0 285 printf("0x%x: MPL_P_MAX_CSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 286 break;
m0t0 0:4350259cf0d0 287 case(0x23):
m0t0 0:4350259cf0d0 288 printf("0x%x: MPL_P_MAX_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 289 break;
m0t0 0:4350259cf0d0 290 case(0x24):
m0t0 0:4350259cf0d0 291 printf("0x%x: MPL_T_MAX_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 292 break;
m0t0 0:4350259cf0d0 293 case(0x25):
m0t0 0:4350259cf0d0 294 printf("0x%x: MPL_T_MAX_LSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 295 break;
m0t0 0:4350259cf0d0 296 case(0x26):
m0t0 0:4350259cf0d0 297 printf("0x%x: MPL_CTRL_REG1=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 298 break;
m0t0 0:4350259cf0d0 299 case(0x27):
m0t0 0:4350259cf0d0 300 printf("0x%x: MPL_CTRL_REG2=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 301 break;
m0t0 0:4350259cf0d0 302 case(0x28):
m0t0 0:4350259cf0d0 303 printf("0x%x: MPL_CTRL_REG3=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 304 break;
m0t0 0:4350259cf0d0 305 case(0x29):
m0t0 0:4350259cf0d0 306 printf("0x%x: MPL_CTRL_REG4=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 307 break;
m0t0 0:4350259cf0d0 308 case(0x2A):
m0t0 0:4350259cf0d0 309 printf("0x%x: MPL_CTRL_REG5=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 310 break;
m0t0 0:4350259cf0d0 311 case(0x2B):
m0t0 0:4350259cf0d0 312 printf("0x%x: MPL_OFF_P=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 313 break;
m0t0 0:4350259cf0d0 314 case(0x2C):
m0t0 0:4350259cf0d0 315 printf("0x%x: MPL_OFF_T=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 316 break;
m0t0 0:4350259cf0d0 317 case(0x2D):
m0t0 0:4350259cf0d0 318 printf("0x%x: MPL_OFF_H=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 319 break;
m0t0 0:4350259cf0d0 320 case(0x2E):
m0t0 0:4350259cf0d0 321 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 322 break;
m0t0 0:4350259cf0d0 323 case(0x2F):
m0t0 0:4350259cf0d0 324 printf("0x%x: MPL_T_MIN_MSB=0x%x\r\n",i,data[0]);
m0t0 0:4350259cf0d0 325 break;
m0t0 0:4350259cf0d0 326 }
m0t0 0:4350259cf0d0 327 }
m0t0 0:4350259cf0d0 328 return 0;
m0t0 0:4350259cf0d0 329 }
m0t0 0:4350259cf0d0 330 else{
m0t0 0:4350259cf0d0 331 return -1;
m0t0 0:4350259cf0d0 332 }
m0t0 0:4350259cf0d0 333 }
m0t0 1:2a6907395c5d 334 }
m0t0 1:2a6907395c5d 335
m0t0 1:2a6907395c5d 336 //Solution entails
m0t0 1:2a6907395c5d 337 char s[1];
m0t0 1:2a6907395c5d 338 int main() {
m0t0 1:2a6907395c5d 339
m0t0 1:2a6907395c5d 340 dataPoints data[100];
m0t0 1:2a6907395c5d 341
m0t0 1:2a6907395c5d 342 uint8_t id;
m0t0 1:2a6907395c5d 343 pc.printf("\n\r*** MPL3115A2 Pressure/Altitude Sensor Test *** \n\r");
m0t0 1:2a6907395c5d 344 while ((id=pressure_sensor.getID())!=0xC4) {
m0t0 1:2a6907395c5d 345 pc.printf("Status read unsuccessful: Value = 0x%02x\n\r",id);
m0t0 1:2a6907395c5d 346 pc.printf("Check wiring to the pressure sensor\n\r",id);
m0t0 1:2a6907395c5d 347 pc.printf("Retesting for correct ID in 1 second...\n\r");
m0t0 1:2a6907395c5d 348 wait(1);
m0t0 1:2a6907395c5d 349 }
m0t0 1:2a6907395c5d 350 //uint8_t tmp[2];
m0t0 1:2a6907395c5d 351 //tmp[0] = 0x26;
m0t0 1:2a6907395c5d 352 // pressure_sensor.readRegs(0x26, &tmp[1], 1);
m0t0 1:2a6907395c5d 353 // tmp[1] = tmp[1] & 0xC6;
m0t0 1:2a6907395c5d 354 // pressure_sensor.writeRegs(tmp,2);
m0t0 1:2a6907395c5d 355 pc.printf("Status read successfully: Value = 0x%02x\n\r",id);
m0t0 1:2a6907395c5d 356 pc.printf("***1hz readings from the pressure sensor***\n\r");
m0t0 1:2a6907395c5d 357
m0t0 1:2a6907395c5d 358 int counter= 0;
m0t0 1:2a6907395c5d 359 while(1) {
m0t0 1:2a6907395c5d 360 mpl3115_reg_print(0,0);
m0t0 1:2a6907395c5d 361 //this is where I would check for the GPIO pin if implemented
m0t0 1:2a6907395c5d 362 if(counter!=100){
m0t0 1:2a6907395c5d 363 dataPoints p1 = {0,0};
m0t0 1:2a6907395c5d 364 //pc.printf("%f hPA; %f m\n\r",pressure_sensor.getPressure(),pressure_sensor.getAltitude());
m0t0 1:2a6907395c5d 365 p1.pres = pressure_sensor.getPressure();
m0t0 1:2a6907395c5d 366 p1.alt = pressure_sensor.getAltitude();
m0t0 1:2a6907395c5d 367 data[counter] = p1;
m0t0 1:2a6907395c5d 368 //pc.printf("STORED VALUES: \n\r Pressure: %f hPA, Altitude: %f m\n\r",data[0].pres,data[0].alt);
m0t0 1:2a6907395c5d 369 pc.printf("DATA STORED\n\r");
m0t0 1:2a6907395c5d 370 if (pc.readable()){
m0t0 1:2a6907395c5d 371 s[1]=pc.getc();
m0t0 1:2a6907395c5d 372 if(s[1] == 'p'){
m0t0 1:2a6907395c5d 373 pc.printf("STORED VALUES: \n\r Pressure: %f hPA, Altitude: %f m\n\r",data[0].pres,data[0].alt);
m0t0 1:2a6907395c5d 374 for(int i=1; i<=counter; i++){
m0t0 1:2a6907395c5d 375 pc.printf("Pressure: %f hPA, Altitude: %f m\n\r",data[i].pres,data[i].alt);
m0t0 1:2a6907395c5d 376 s[1] = 'x';
m0t0 1:2a6907395c5d 377
m0t0 1:2a6907395c5d 378 }
m0t0 1:2a6907395c5d 379 }
m0t0 1:2a6907395c5d 380 }
m0t0 1:2a6907395c5d 381
m0t0 1:2a6907395c5d 382
m0t0 1:2a6907395c5d 383 //if the counter is going to go over the 100 limit reset it to zero and then
m0t0 1:2a6907395c5d 384 if(counter+1<=100){
m0t0 1:2a6907395c5d 385 counter++;
m0t0 1:2a6907395c5d 386 }
m0t0 1:2a6907395c5d 387 else{
m0t0 1:2a6907395c5d 388 counter=0;
m0t0 1:2a6907395c5d 389 }
m0t0 1:2a6907395c5d 390 myled = !myled;
m0t0 1:2a6907395c5d 391 wait(1);
m0t0 1:2a6907395c5d 392 }
m0t0 1:2a6907395c5d 393 else{
m0t0 1:2a6907395c5d 394 pc.printf("STORED VALUES: \n\r Pressure: %f hPA, Altitude: %f m\n\r",data[0].pres,data[0].alt);
m0t0 1:2a6907395c5d 395 for(int i=1; i<=counter; i++){
m0t0 1:2a6907395c5d 396 pc.printf("Pressure: %f hPA, Altitude: %f m\n\r",data[i].pres,data[i].alt);
m0t0 1:2a6907395c5d 397 }
m0t0 1:2a6907395c5d 398 for(int i=0; i<=100; i++){
m0t0 1:2a6907395c5d 399 data[i].pres=NULL;
m0t0 1:2a6907395c5d 400 data[i].alt=NULL;
m0t0 1:2a6907395c5d 401 }
m0t0 1:2a6907395c5d 402 pc.printf("Cleared Data \n\r");
m0t0 1:2a6907395c5d 403 }
m0t0 1:2a6907395c5d 404
m0t0 1:2a6907395c5d 405 }
m0t0 1:2a6907395c5d 406
m0t0 1:2a6907395c5d 407
m0t0 1:2a6907395c5d 408 }