lab 6

Dependencies:   ADXL362 mbed MPL3115A2

Committer:
htdoughe
Date:
Fri Mar 02 18:06:12 2018 +0000
Revision:
26:19823b051994
Parent:
25:ded2ac3f76e4
Child:
27:a4d5c85a55e1
need to set sample time but otherwise it does work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rmneubau 0:0f663d16e8a2 1 #include "mbed.h"
rmneubau 0:0f663d16e8a2 2 #include "ADXL362.h"
htdoughe 4:8065ca897f8b 3 #include "string.h"
htdoughe 16:993757c8b398 4 #include "MPL3115A2.h"
htdoughe 26:19823b051994 5 #include <stdio.h>
htdoughe 26:19823b051994 6 #include <time.h>
htdoughe 9:a14593af628d 7
htdoughe 18:216cc41b55f3 8 DigitalOut led3(LED3);
htdoughe 26:19823b051994 9 Serial pc(USBTX, USBRX);
htdoughe 26:19823b051994 10 AnalogIn gpio(A4);
htdoughe 4:8065ca897f8b 11
htdoughe 16:993757c8b398 12 //map of register values and names for the adxl
htdoughe 20:8d93acd1f8cd 13 int aregids[34];
htdoughe 20:8d93acd1f8cd 14 char* aregnames[34];
htdoughe 20:8d93acd1f8cd 15 //populating the map
htdoughe 26:19823b051994 16 void initmap()
htdoughe 26:19823b051994 17 {
htdoughe 20:8d93acd1f8cd 18 aregids[0] = 0x00;
htdoughe 20:8d93acd1f8cd 19 aregids[1] = 0x01;
htdoughe 20:8d93acd1f8cd 20 aregids[2] = 0x02;
htdoughe 20:8d93acd1f8cd 21 aregids[3] = 0x03;
htdoughe 20:8d93acd1f8cd 22 aregids[4] = 0x08;
htdoughe 20:8d93acd1f8cd 23 aregids[5] = 0x09;
htdoughe 20:8d93acd1f8cd 24 aregids[6] = 0x0A;
htdoughe 20:8d93acd1f8cd 25 aregids[7] = 0x0B;
htdoughe 20:8d93acd1f8cd 26 aregids[8] = 0x0c;
htdoughe 20:8d93acd1f8cd 27 aregids[9] = 0x0D;
htdoughe 20:8d93acd1f8cd 28 aregids[10] = 0x0E;
htdoughe 20:8d93acd1f8cd 29 aregids[11] = 0x0F;
htdoughe 20:8d93acd1f8cd 30 aregids[12] = 0x10;
htdoughe 20:8d93acd1f8cd 31 aregids[13] = 0x11;
htdoughe 20:8d93acd1f8cd 32 aregids[14] = 0x12;
htdoughe 20:8d93acd1f8cd 33 aregids[15] = 0x13;
htdoughe 20:8d93acd1f8cd 34 aregids[16] = 0x14;
htdoughe 20:8d93acd1f8cd 35 aregids[17] = 0x15;
htdoughe 20:8d93acd1f8cd 36 aregids[18] = 0x1F;
htdoughe 20:8d93acd1f8cd 37 aregids[19] = 0x20;
htdoughe 20:8d93acd1f8cd 38 aregids[20] = 0x21;
htdoughe 20:8d93acd1f8cd 39 aregids[21] = 0x22;
htdoughe 20:8d93acd1f8cd 40 aregids[22] = 0x23;
htdoughe 20:8d93acd1f8cd 41 aregids[23] = 0x24;
htdoughe 20:8d93acd1f8cd 42 aregids[24] = 0x25;
htdoughe 20:8d93acd1f8cd 43 aregids[25] = 0x26;
htdoughe 20:8d93acd1f8cd 44 aregids[26] = 0x27;
htdoughe 20:8d93acd1f8cd 45 aregids[27] = 0x28;
htdoughe 20:8d93acd1f8cd 46 aregids[28] = 0x29;
htdoughe 20:8d93acd1f8cd 47 aregids[29] = 0x2A;
htdoughe 20:8d93acd1f8cd 48 aregids[30] = 0x2B;
htdoughe 20:8d93acd1f8cd 49 aregids[31] = 0x2C;
htdoughe 20:8d93acd1f8cd 50 aregids[32] = 0x2D;
htdoughe 20:8d93acd1f8cd 51 aregids[33] = 0x2E;
htdoughe 26:19823b051994 52
htdoughe 20:8d93acd1f8cd 53 aregnames[0] = "DEVID_AD";
htdoughe 20:8d93acd1f8cd 54 aregnames[1] = "DEVID_MST";
htdoughe 20:8d93acd1f8cd 55 aregnames[2] = "PARTID";
htdoughe 20:8d93acd1f8cd 56 aregnames[3] = "REVID";
htdoughe 20:8d93acd1f8cd 57 aregnames[4] = "XDATA";
htdoughe 20:8d93acd1f8cd 58 aregnames[5] = "YDATA";
htdoughe 20:8d93acd1f8cd 59 aregnames[6] = "ZDATA";
htdoughe 20:8d93acd1f8cd 60 aregnames[7] = "STATUS";
htdoughe 20:8d93acd1f8cd 61 aregnames[8] = "FIFO_ENTRIES_L";
htdoughe 20:8d93acd1f8cd 62 aregnames[9] = "FIFO_ENTRIES_H";
htdoughe 20:8d93acd1f8cd 63 aregnames[10] = "XDATA_L";
htdoughe 20:8d93acd1f8cd 64 aregnames[11] = "XDATA_H";
htdoughe 20:8d93acd1f8cd 65 aregnames[12] = "YDATA_L";
htdoughe 20:8d93acd1f8cd 66 aregnames[13] = "YDATA_H";
htdoughe 20:8d93acd1f8cd 67 aregnames[14] = "ZDATA_L";
htdoughe 20:8d93acd1f8cd 68 aregnames[15] = "ZDATA_H";
htdoughe 20:8d93acd1f8cd 69 aregnames[16] = "TEMP_L";
htdoughe 20:8d93acd1f8cd 70 aregnames[17] = "TEMP_H";
htdoughe 20:8d93acd1f8cd 71 aregnames[18] = "SOFT_RESET";
htdoughe 20:8d93acd1f8cd 72 aregnames[19] = "THRESH_ACT_L";
htdoughe 20:8d93acd1f8cd 73 aregnames[20] = "THRESH_ACT_H";
htdoughe 20:8d93acd1f8cd 74 aregnames[21] = "TIME_ACT";
htdoughe 20:8d93acd1f8cd 75 aregnames[22] = "THRESH_INACT_L";
htdoughe 20:8d93acd1f8cd 76 aregnames[23] = "THRESH_INACT_H";
htdoughe 20:8d93acd1f8cd 77 aregnames[24] = "TIME_INACT_L";
htdoughe 20:8d93acd1f8cd 78 aregnames[25] = "TIME_INACT_H";
htdoughe 20:8d93acd1f8cd 79 aregnames[26] = "ACT_INACT_CTL";
htdoughe 20:8d93acd1f8cd 80 aregnames[27] = "FIFO_CONTROL";
htdoughe 20:8d93acd1f8cd 81 aregnames[28] = "FIFO_SAMPLES";
htdoughe 20:8d93acd1f8cd 82 aregnames[29] = "INTMAP1";
htdoughe 20:8d93acd1f8cd 83 aregnames[30] = "INTMAP2";
htdoughe 20:8d93acd1f8cd 84 aregnames[31] = "FILTER_CTL";
htdoughe 20:8d93acd1f8cd 85 aregnames[32] = "POWER_CTL";
htdoughe 20:8d93acd1f8cd 86 aregnames[33] = "SELF_TEST";
htdoughe 20:8d93acd1f8cd 87 }
htdoughe 20:8d93acd1f8cd 88
htdoughe 20:8d93acd1f8cd 89 //map of register values and names for the adxl
htdoughe 22:1cd3cb77ec07 90 char mregids[46];
htdoughe 22:1cd3cb77ec07 91 char* mregnames[46];
htdoughe 4:8065ca897f8b 92 //populating the map
htdoughe 26:19823b051994 93 void minitmap()
htdoughe 26:19823b051994 94 {
htdoughe 20:8d93acd1f8cd 95 mregids[0] = 0x00;
htdoughe 20:8d93acd1f8cd 96 mregids[1] = 0x01;
htdoughe 20:8d93acd1f8cd 97 mregids[2] = 0x02;
htdoughe 20:8d93acd1f8cd 98 mregids[3] = 0x03;
htdoughe 20:8d93acd1f8cd 99 mregids[4] = 0x04;
htdoughe 20:8d93acd1f8cd 100 mregids[5] = 0x05;
htdoughe 20:8d93acd1f8cd 101 mregids[6] = 0x06;
htdoughe 20:8d93acd1f8cd 102 mregids[7] = 0x07;
htdoughe 20:8d93acd1f8cd 103 mregids[8] = 0x08;
htdoughe 20:8d93acd1f8cd 104 mregids[9] = 0x09;
htdoughe 20:8d93acd1f8cd 105 mregids[10] = 0x0A;
htdoughe 20:8d93acd1f8cd 106 mregids[11] = 0x0B;
htdoughe 20:8d93acd1f8cd 107 mregids[12] = 0x0C;
htdoughe 20:8d93acd1f8cd 108 mregids[13] = 0x0D;
htdoughe 20:8d93acd1f8cd 109 mregids[14] = 0x0E;
htdoughe 20:8d93acd1f8cd 110 mregids[15] = 0x0F;
htdoughe 20:8d93acd1f8cd 111 mregids[16] = 0x10;
htdoughe 20:8d93acd1f8cd 112 mregids[17] = 0x11;
htdoughe 20:8d93acd1f8cd 113 mregids[18] = 0x12;
htdoughe 20:8d93acd1f8cd 114 mregids[19] = 0x13;
htdoughe 20:8d93acd1f8cd 115 mregids[20] = 0x14;
htdoughe 20:8d93acd1f8cd 116 mregids[21] = 0x15;
htdoughe 20:8d93acd1f8cd 117 mregids[22] = 0x16;
htdoughe 20:8d93acd1f8cd 118 mregids[23] = 0x17;
htdoughe 20:8d93acd1f8cd 119 mregids[24] = 0x18;
htdoughe 20:8d93acd1f8cd 120 mregids[25] = 0x19;
htdoughe 20:8d93acd1f8cd 121 mregids[26] = 0x1A;
htdoughe 20:8d93acd1f8cd 122 mregids[27] = 0x1B;
htdoughe 20:8d93acd1f8cd 123 mregids[28] = 0x1C;
htdoughe 20:8d93acd1f8cd 124 mregids[29] = 0x1D;
htdoughe 20:8d93acd1f8cd 125 mregids[30] = 0x1E;
htdoughe 20:8d93acd1f8cd 126 mregids[31] = 0x1F;
htdoughe 20:8d93acd1f8cd 127 mregids[32] = 0x20;
htdoughe 20:8d93acd1f8cd 128 mregids[33] = 0x21;
htdoughe 20:8d93acd1f8cd 129 mregids[34] = 0x22;
htdoughe 20:8d93acd1f8cd 130 mregids[35] = 0x23;
htdoughe 20:8d93acd1f8cd 131 mregids[36] = 0x24;
htdoughe 20:8d93acd1f8cd 132 mregids[37] = 0x25;
htdoughe 20:8d93acd1f8cd 133 mregids[38] = 0x26;
htdoughe 20:8d93acd1f8cd 134 mregids[39] = 0x27;
htdoughe 20:8d93acd1f8cd 135 mregids[40] = 0x28;
htdoughe 20:8d93acd1f8cd 136 mregids[41] = 0x29;
htdoughe 20:8d93acd1f8cd 137 mregids[42] = 0x2A;
htdoughe 20:8d93acd1f8cd 138 mregids[43] = 0x2B;
htdoughe 20:8d93acd1f8cd 139 mregids[44] = 0x2C;
htdoughe 20:8d93acd1f8cd 140 mregids[45] = 0x2D;
htdoughe 26:19823b051994 141
htdoughe 20:8d93acd1f8cd 142 mregnames[0] = "STATUS";
htdoughe 20:8d93acd1f8cd 143 mregnames[1] = "OUT_P_MSB";
htdoughe 20:8d93acd1f8cd 144 mregnames[2] = "OUT_P_CSB";
htdoughe 20:8d93acd1f8cd 145 mregnames[3] = "OUT_P_LSB";
htdoughe 20:8d93acd1f8cd 146 mregnames[4] = "OUT_T_MSB";
htdoughe 20:8d93acd1f8cd 147 mregnames[5] = "OUT_T_LSB";
htdoughe 20:8d93acd1f8cd 148 mregnames[6] = "DR_STATUS";
htdoughe 20:8d93acd1f8cd 149 mregnames[7] = "OUT_P_DELTA_MSB";
htdoughe 20:8d93acd1f8cd 150 mregnames[8] = "OUT_P_DELTA_CSB";
htdoughe 20:8d93acd1f8cd 151 mregnames[9] = "OUT_T_DELTA_MSB";
htdoughe 20:8d93acd1f8cd 152 mregnames[10] = "OUT_T_DELTA_LSB";
htdoughe 20:8d93acd1f8cd 153 mregnames[11] = "WHO_AM_I";
htdoughe 20:8d93acd1f8cd 154 mregnames[12] = "F_STATUS";
htdoughe 20:8d93acd1f8cd 155 mregnames[13] = "F_DATA";
htdoughe 20:8d93acd1f8cd 156 mregnames[14] = "F_SETUP";
htdoughe 20:8d93acd1f8cd 157 mregnames[15] = "TIME_DLY";
htdoughe 20:8d93acd1f8cd 158 mregnames[16] = "SYSMOD";
htdoughe 20:8d93acd1f8cd 159 mregnames[17] = "INT_SOURCE";
htdoughe 20:8d93acd1f8cd 160 mregnames[18] = "SOFT_RESET";
htdoughe 20:8d93acd1f8cd 161 mregnames[19] = "PT_DATA_CFG";
htdoughe 20:8d93acd1f8cd 162 mregnames[20] = "BAR_IN_MSB";
htdoughe 20:8d93acd1f8cd 163 mregnames[21] = "BAR_IN_LSB";
htdoughe 20:8d93acd1f8cd 164 mregnames[22] = "P_TGT_MSB";
htdoughe 20:8d93acd1f8cd 165 mregnames[23] = "P_TGT_LSB";
htdoughe 20:8d93acd1f8cd 166 mregnames[24] = "T_TGT";
htdoughe 20:8d93acd1f8cd 167 mregnames[25] = "P_WND_MSB";
htdoughe 20:8d93acd1f8cd 168 mregnames[26] = "P_WND_LSB";
htdoughe 20:8d93acd1f8cd 169 mregnames[27] = "T_WND";
htdoughe 20:8d93acd1f8cd 170 mregnames[28] = "P_MIN_MSB";
htdoughe 20:8d93acd1f8cd 171 mregnames[29] = "P_MIN_CSB";
htdoughe 20:8d93acd1f8cd 172 mregnames[30] = "P_MIN_LSB";
htdoughe 20:8d93acd1f8cd 173 mregnames[31] = "T_MIN_MSB";
htdoughe 20:8d93acd1f8cd 174 mregnames[32] = "T_MIN_LSB";
htdoughe 20:8d93acd1f8cd 175 mregnames[33] = "P_MAX_MSB";
htdoughe 20:8d93acd1f8cd 176 mregnames[34] = "P_MAX_CSB";
htdoughe 20:8d93acd1f8cd 177 mregnames[35] = "P_MAX_LSB";
htdoughe 20:8d93acd1f8cd 178 mregnames[36] = "T_MAX_MSB";
htdoughe 20:8d93acd1f8cd 179 mregnames[37] = "T_MAX_LSB";
htdoughe 20:8d93acd1f8cd 180 mregnames[38] = "CTRL_REG1";
htdoughe 20:8d93acd1f8cd 181 mregnames[39] = "CTRL_REG2";
htdoughe 20:8d93acd1f8cd 182 mregnames[40] = "CTRL_REG3";
htdoughe 20:8d93acd1f8cd 183 mregnames[41] = "CTRL_REG4";
htdoughe 20:8d93acd1f8cd 184 mregnames[42] = "CTRL_REG5";
htdoughe 20:8d93acd1f8cd 185 mregnames[43] = "OFF_P";
htdoughe 20:8d93acd1f8cd 186 mregnames[44] = "OFF_T";
htdoughe 20:8d93acd1f8cd 187 mregnames[45] = "OFF_H";
htdoughe 4:8065ca897f8b 188 }
htdoughe 4:8065ca897f8b 189
rmneubau 0:0f663d16e8a2 190 // Interface pulled from ADXL362.cpp
rmneubau 0:0f663d16e8a2 191 // ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
rmneubau 0:0f663d16e8a2 192 ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1);
htdoughe 23:f9461117d7e3 193
htdoughe 23:f9461117d7e3 194 // Selects SDA as I2C1_SDA on pin PB_7
htdoughe 23:f9461117d7e3 195 // Selects SCL on I2C1_SCL on pin PB_6
htdoughe 26:19823b051994 196 // The I2C address of the pressure sensor is fixed at 0x60.
htdoughe 23:f9461117d7e3 197 MPL3115A2 pressure(PB_7, PB_6, 0x60);
rmneubau 0:0f663d16e8a2 198
htdoughe 26:19823b051994 199 int adxl362_reg_print(int s, int l)
htdoughe 26:19823b051994 200 {
htdoughe 4:8065ca897f8b 201 //check s is between 0x00 and 0x2E
htdoughe 26:19823b051994 202 if(s > 0x2E || s < 0x00) {
htdoughe 1:b8716571ecac 203 printf("adx: requires start between 0x00 and 0x2E; given %d (0x%01x)\n", s,s);
htdoughe 4:8065ca897f8b 204 return -1;
htdoughe 26:19823b051994 205 } else if(l < 0) {
htdoughe 4:8065ca897f8b 206 //check length > 0
htdoughe 1:b8716571ecac 207 printf("adx: requires length >= 0, given %d\n", l);
htdoughe 4:8065ca897f8b 208 return -1;
htdoughe 26:19823b051994 209 } else {
rmneubau 0:0f663d16e8a2 210 // start sending stuff
rmneubau 0:0f663d16e8a2 211 //first check DEVID_AD == 0xAD
htdoughe 7:446c8e17a945 212 uint8_t devid = adxl362.read_reg(ADXL362::DEVID_AD);
htdoughe 26:19823b051994 213 //printf("devid = %d\n", devid);
htdoughe 26:19823b051994 214 if(devid != 0xAD) {
htdoughe 2:496a662be854 215 printf("error: DEVID_AD is not 0xAD; exiting\n");
htdoughe 4:8065ca897f8b 216 return -1;
htdoughe 26:19823b051994 217 } else {
rmneubau 0:0f663d16e8a2 218 //now do stuff
htdoughe 1:b8716571ecac 219 //if length == 0, send everything from s to end of registers
htdoughe 4:8065ca897f8b 220 //else print from s to l
htdoughe 4:8065ca897f8b 221 // formula : range = end - start - length
htdoughe 4:8065ca897f8b 222 // area = start + range
htdoughe 4:8065ca897f8b 223 int stop = 0;
htdoughe 26:19823b051994 224 if(l == 0) {
htdoughe 4:8065ca897f8b 225 stop = 34;
htdoughe 26:19823b051994 226 } else {
htdoughe 4:8065ca897f8b 227 stop = s + l;
htdoughe 4:8065ca897f8b 228 }
htdoughe 4:8065ca897f8b 229 int in = s;
htdoughe 26:19823b051994 230 while(in < stop) {
htdoughe 4:8065ca897f8b 231 //get register name
htdoughe 21:b85d1a4f0373 232 char * name = aregnames[in]; //GET NAME
htdoughe 21:b85d1a4f0373 233 ADXL362::ADXL362_register_t reg = (ADXL362::ADXL362_register_t) aregids[in];
htdoughe 8:9c9d58ca2b79 234 uint8_t val = adxl362.read_reg(reg); //GET REG VAL
htdoughe 4:8065ca897f8b 235 //print val
htdoughe 21:b85d1a4f0373 236 printf("0x%01x: %s=0x%01x\r\n", aregids[in], name, val);
htdoughe 4:8065ca897f8b 237 in++;
htdoughe 1:b8716571ecac 238 }
rmneubau 0:0f663d16e8a2 239 }
rmneubau 0:0f663d16e8a2 240 }
htdoughe 5:02aa71487c01 241 return 0;
htdoughe 5:02aa71487c01 242 }
htdoughe 5:02aa71487c01 243
htdoughe 26:19823b051994 244 void knocks()
htdoughe 26:19823b051994 245 {
htdoughe 26:19823b051994 246 int8_t x,y,z, initx, inity, initz;
htdoughe 10:8dcc46dd53bf 247 //initial values of x, y, and z.
htdoughe 10:8dcc46dd53bf 248 //These values are the baseline for the accelerometer; knocks are detected
htdoughe 10:8dcc46dd53bf 249 // in relation to these initial values
htdoughe 9:a14593af628d 250 initx=adxl362.scanx_u8();
htdoughe 9:a14593af628d 251 inity=adxl362.scany_u8();
htdoughe 9:a14593af628d 252 initz=adxl362.scanz_u8();
htdoughe 15:5ce9c63e7da2 253 int count = 0;
htdoughe 18:216cc41b55f3 254 int bs = 7;
htdoughe 26:19823b051994 255
htdoughe 5:02aa71487c01 256 while(1) {
htdoughe 10:8dcc46dd53bf 257 //get the values of x, y, and z to test for a knock
htdoughe 5:02aa71487c01 258 x=adxl362.scanx_u8();
htdoughe 5:02aa71487c01 259 y=adxl362.scany_u8();
htdoughe 5:02aa71487c01 260 z=adxl362.scanz_u8();
htdoughe 26:19823b051994 261 //if x, y, or z vary from baseline by at least bs, a knock has occured.
htdoughe 26:19823b051994 262 if(x > initx+bs || y > inity+bs || z > initz+bs || x < initx-bs || y < inity-bs || z < initz-bs) {
htdoughe 18:216cc41b55f3 263 led3 = 1;
htdoughe 15:5ce9c63e7da2 264 count++;
htdoughe 15:5ce9c63e7da2 265 printf("number of knocks: %d\r\n", count);
rmneubau 11:5aba4ea23082 266 wait_ms(2000);
htdoughe 18:216cc41b55f3 267 led3 = 0;
htdoughe 9:a14593af628d 268 }
htdoughe 16:993757c8b398 269 //printf("x = %d y = %d z = %d\r\n",x,y,z);
htdoughe 5:02aa71487c01 270 wait_ms(100);
htdoughe 5:02aa71487c01 271 }
htdoughe 1:b8716571ecac 272 }
htdoughe 16:993757c8b398 273
htdoughe 26:19823b051994 274 int mpl3115_reg_print(int s, int l)
htdoughe 26:19823b051994 275 {
htdoughe 26:19823b051994 276 if(s > 0x2D || s < 0x00) {
htdoughe 20:8d93acd1f8cd 277 printf("mpl: requires start between 0x00 and 0x20; given %d (0x%01x)\n\r", s,s);
htdoughe 20:8d93acd1f8cd 278 return -1;
htdoughe 26:19823b051994 279 } else if(l < 0) {
htdoughe 20:8d93acd1f8cd 280 //check length > 0
htdoughe 20:8d93acd1f8cd 281 printf("mpl: requires length >= 0, given %d\n\r", l);
htdoughe 20:8d93acd1f8cd 282 return -1;
htdoughe 22:1cd3cb77ec07 283 } else {
htdoughe 20:8d93acd1f8cd 284 //else do stuff
htdoughe 23:f9461117d7e3 285 uint8_t id = pressure.getID();
htdoughe 26:19823b051994 286 //printf("whoami = 0x%01x", id);
htdoughe 23:f9461117d7e3 287 if(id != 0xC4) {
htdoughe 21:b85d1a4f0373 288 printf("error: WHO_AM_I is not 0xC4; exiting\n");
htdoughe 20:8d93acd1f8cd 289 return -1;
htdoughe 22:1cd3cb77ec07 290 } else {
htdoughe 21:b85d1a4f0373 291 //now do stuff
htdoughe 21:b85d1a4f0373 292 //if length == 0, send everything from s to end of registers
htdoughe 21:b85d1a4f0373 293 //else print from s to l
htdoughe 21:b85d1a4f0373 294 // formula : range = end - start - length
htdoughe 21:b85d1a4f0373 295 // area = start + range
htdoughe 21:b85d1a4f0373 296 int stop = 0;
htdoughe 22:1cd3cb77ec07 297 if(l == 0) {
htdoughe 26:19823b051994 298 stop = 46;
htdoughe 22:1cd3cb77ec07 299 } else {
htdoughe 21:b85d1a4f0373 300 stop = s + l;
htdoughe 21:b85d1a4f0373 301 }
htdoughe 21:b85d1a4f0373 302 int in = s;
htdoughe 22:1cd3cb77ec07 303 while(in < stop) {
htdoughe 21:b85d1a4f0373 304 //get register name
htdoughe 21:b85d1a4f0373 305 char * name = mregnames[in]; //GET NAME
htdoughe 23:f9461117d7e3 306 int reg = mregids[in];
htdoughe 23:f9461117d7e3 307 uint8_t val;
htdoughe 23:f9461117d7e3 308 pressure.readRegs(reg,&val,sizeof(uint8_t)); //GET REG VAL
htdoughe 21:b85d1a4f0373 309 //print val
htdoughe 21:b85d1a4f0373 310 printf("0x%01x: %s=0x%01x\r\n", mregids[in], name, val);
htdoughe 21:b85d1a4f0373 311 in++;
htdoughe 22:1cd3cb77ec07 312 }//while
htdoughe 22:1cd3cb77ec07 313 }//else
htdoughe 22:1cd3cb77ec07 314 }//else
htdoughe 22:1cd3cb77ec07 315 return 0;
htdoughe 26:19823b051994 316 }//print mpl
htdoughe 26:19823b051994 317
htdoughe 26:19823b051994 318 int measureAlt()
htdoughe 26:19823b051994 319 {
htdoughe 26:19823b051994 320
htdoughe 26:19823b051994 321 printf("measuring things\r\n");
htdoughe 26:19823b051994 322 //make output file
htdoughe 26:19823b051994 323 //FILE * log;
htdoughe 26:19823b051994 324 //time_t time = time(NULL);
htdoughe 26:19823b051994 325 //char* tstring = ctime(&time);
htdoughe 26:19823b051994 326 //char* filen = strcat(tstring, ".txt");
htdoughe 26:19823b051994 327 //log = fopen(filen, "w");
htdoughe 26:19823b051994 328
htdoughe 26:19823b051994 329 double data[900];
htdoughe 26:19823b051994 330
htdoughe 26:19823b051994 331 int ind = 0;
htdoughe 26:19823b051994 332
htdoughe 20:8d93acd1f8cd 333
htdoughe 26:19823b051994 334 //GPIO pin indicates sampling should begin -- if voltage == 3.3, start
htdoughe 26:19823b051994 335 while(ind < 900 && gpio.read() > 0.00) {
htdoughe 26:19823b051994 336 printf("in the while\r\n");
htdoughe 26:19823b051994 337 //then we measure
htdoughe 26:19823b051994 338 //pressure and temperature sampled at 10times/second (10 hz)
htdoughe 26:19823b051994 339 //LED blinks during sampling at 1 hz (1 time/second)
htdoughe 26:19823b051994 340 led3 = 1;
htdoughe 26:19823b051994 341 for(int i = 0; i < 10; i++) {
htdoughe 26:19823b051994 342 printf("getting pressure and temp\r\n");
htdoughe 26:19823b051994 343 data[ind++] = pressure.getPressure();
htdoughe 26:19823b051994 344 data[ind++] = pressure.getTemperature();
htdoughe 26:19823b051994 345 wait_ms(1);
htdoughe 26:19823b051994 346 }//for
htdoughe 26:19823b051994 347 led3 = 0;
htdoughe 26:19823b051994 348 for(int i = 0; i < 10; i++) {
htdoughe 26:19823b051994 349 //WRITE TO CONTROL REGISTER 1 and WRITE THOSE BITS TO '0'
htdoughe 26:19823b051994 350 // bits 5, 4, and 3
htdoughe 26:19823b051994 351 printf("pressure and temp 2.0\r\n");
htdoughe 26:19823b051994 352 data[ind++] = pressure.getPressure();
htdoughe 26:19823b051994 353 data[ind++] = pressure.getTemperature();
htdoughe 26:19823b051994 354 wait_ms(1);
htdoughe 26:19823b051994 355 }//for
htdoughe 26:19823b051994 356 }
htdoughe 26:19823b051994 357
htdoughe 26:19823b051994 358 int pind = 0;
htdoughe 26:19823b051994 359 int pend = ind;
htdoughe 26:19823b051994 360 char in;
htdoughe 26:19823b051994 361 int ch;
htdoughe 26:19823b051994 362 char p = 'p';
htdoughe 26:19823b051994 363 while(1) {
htdoughe 26:19823b051994 364 printf("p%% ");
htdoughe 26:19823b051994 365 while((ch = pc.getc()) != 13) {
htdoughe 26:19823b051994 366 pc.putc(ch);
htdoughe 26:19823b051994 367 //ch2 = ch;
htdoughe 26:19823b051994 368 //strcat(cmd, &ch2);
htdoughe 26:19823b051994 369 in = ch;
htdoughe 26:19823b051994 370 }//while
htdoughe 26:19823b051994 371 if(in == p){
htdoughe 26:19823b051994 372 while(pind < pend+1){
htdoughe 26:19823b051994 373 pc.printf("\n\r%f\t%f", data[pind],data[pind+1]);
htdoughe 26:19823b051994 374 pind += 2;
htdoughe 26:19823b051994 375 }//while
htdoughe 26:19823b051994 376 }else{
htdoughe 26:19823b051994 377 in = 0;
htdoughe 26:19823b051994 378 }//if/else
htdoughe 26:19823b051994 379 }//while
htdoughe 26:19823b051994 380 //fclose(log);
htdoughe 26:19823b051994 381
htdoughe 26:19823b051994 382 return 0;
htdoughe 26:19823b051994 383
htdoughe 26:19823b051994 384 }//measureAlt
htdoughe 26:19823b051994 385
htdoughe 26:19823b051994 386 int main()
htdoughe 26:19823b051994 387 {
htdoughe 16:993757c8b398 388 initmap();
htdoughe 22:1cd3cb77ec07 389 minitmap();
htdoughe 16:993757c8b398 390 adxl362.reset();
htdoughe 26:19823b051994 391 pressure.activate();
htdoughe 16:993757c8b398 392 wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
htdoughe 16:993757c8b398 393 adxl362.set_mode(ADXL362::MEASUREMENT);
htdoughe 16:993757c8b398 394 int start, length;
htdoughe 16:993757c8b398 395 start = 0;
htdoughe 16:993757c8b398 396 length = 0;
htdoughe 17:6a08357dbb3f 397 //while(1){
htdoughe 26:19823b051994 398 //adxl362_reg_print(start, length);
htdoughe 26:19823b051994 399 // mpl3115_reg_print(start, length);
htdoughe 17:6a08357dbb3f 400 //}
htdoughe 26:19823b051994 401 //knocks();
htdoughe 26:19823b051994 402
htdoughe 26:19823b051994 403 measureAlt();
htdoughe 26:19823b051994 404 //while(1);
htdoughe 16:993757c8b398 405 }