CPS_Lab*
/
AltTest2
Lab 7
Fork of AltTest2 by
Diff: main.cpp
- Revision:
- 0:d7735965d4ca
- Child:
- 1:03565a1413e6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 01 15:37:18 2018 +0000 @@ -0,0 +1,197 @@ +#include "mbed.h" +#include "MPL3115A2.h" +#include <string.h> +#include <stdlib.h> + +Serial pc(SERIAL_TX, SERIAL_RX); +DigitalOut myled(LED1); +MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); + +/* +char *int_array_to_string(uint8_t int_array[], int size_of_array) { + char returnstring[size_of_array]; + for (int temp = 0; temp < size_of_array; temp++) + returnstring[temp] = itoa(int_array[temp]); + return returnstring; +} +*/ +int MPL3115A2_reg_print(int start, int length) { + uint8_t valArray[7]; + int len = 5; + if(length == 0) + length = 45; + int i = start, end = start + length; + if(start > 0x2D || start < 0x00) + return(-1); + if(length < 0) + return(-1); + if (pressure_sensor.getID()!=0xC4) + return(-1); + if (end > 46) + return(-1); + for( i = start; i <= end; i++) { + char name[25]; + MPL3115A2::readRegs(i, valArray, len); + switch (i) { + case 0x00: + strcpy(name,"MPL_STATUS"); + break; + case 0x01: + strcpy(name,"MPL_OUT_P_MSB"); + break; + case 0x02: + strcpy(name, "MPL_OUT_P_CSB"); + break; + case 0x03: + strcpy(name,"MPL_OUT_P_LSB"); + break; + case 0x04: + strcpy(name,"MPL_OUT_T_MSB"); + break; + case 0x05: + strcpy(name,"MPL_OUT_T_LSB"); + break; + case 0x06: + strcpy(name,"MPL_DR_STATUS"); + break; + case 0x07: + strcpy(name,"MPL_OUT_P_DELTA_MSB"); + break; + case 0x08: + strcpy(name,"MPL_OUT_P_DELTA_CSB"); + break; + case 0x09: + strcpy(name,"MPL_OUT_P_DELTA_LSB"); + break; + case 0x0A: + strcpy(name,"MPL_OUT_T_DELTA_MSB"); + break; + case 0x0B: + strcpy(name,"MPL_OUT_T_DELTA_LSB"); + break; + case 0x0C: + strcpy(name,"MPL_WHO_AM_I"); + break; + case 0x0D: + strcpy(name,"MPL_F_STATUS"); + break; + case 0x0E: + strcpy(name,"MPL_F_DATA"); + break; + case 0x0F: + strcpy(name,"MPL_F_SETUP"); + break; + case 0x10: + strcpy(name,"MPL_TIME_DLY"); + break; + case 0x11: + strcpy(name,"MPL_SYSMOD"); + break; + case 0x12: + strcpy(name,"MPL_INT_SOURCE"); + break; + case 0x13: + strcpy(name,"MPL_PT_DATA_CFG"); + break; + case 0x14: + strcpy(name,"MPL_BAR_IN_MSB"); + break; + case 0x15: + strcpy(name,"MPL_BAR_IN_LSB"); + break; + case 0x16: + strcpy(name,"MPL_P_TGT_MSB"); + break; + case 0x17: + strcpy(name,"MPL_P_TGT_LSB"); + break; + case 0x18: + strcpy(name,"MPL_T_TGT"); + break; + case 0x19: + strcpy(name,"MPL_P_WND_MSB"); + break; + case 0x1A: + strcpy(name,"MPL_P_WND_LSB"); + break; + case 0x1B: + strcpy(name,"MPL_T_WND"); + break; + case 0x1C: + strcpy(name,"MPL_P_MIN_MSB"); + break; + case 0x1D: + strcpy(name,"MPL_P_MIN_CSB"); + break; + case 0x1E: + strcpy(name,"MPL_P_MIN_LSB"); + break; + case 0x1F: + strcpy(name,"MPL_T_MIN_MSB"); + break; + case 0x20: + strcpy(name,"MPL_T_MIN_LSB"); + break; + case 0x21: + strcpy(name,"MPL_P_MAX_MSB"); + break; + case 0x22: + strcpy(name,"MPL_P_MAX_CSB"); + break; + case 0x23: + strcpy(name,"MPL_P_MAX_LSB"); + break; + case 0x24: + strcpy(name,"MPL_T_MAX_MSB"); + break; + case 0x25: + strcpy(name,"MPL_T_MAX_LSB"); + break; + case 0x26: + strcpy(name,"MPL_CTRL_REG1"); + break; + case 0x27: + strcpy(name,"MPL_CTRL_REG2"); + break; + case 0x28: + strcpy(name,"MPL_CTRL_REG3"); + break; + case 0x29: + strcpy(name,"MPL_CTRL_REG4"); + break; + case 0x2A: + strcpy(name,"MPL_CTRL_REG5"); + break; + case 0x2B: + strcpy(name,"MPL_OFF_P"); + break; + case 0x2C: + strcpy(name,"MPL_OFF_T"); + break; + case 0x2D: + strcpy(name,"MPL_OFF_H"); + break; + default: + printf("ERR\n\r"); + } + printf("0x%02X: %s = ", i, name); + for(int j = 0; j < 8; j++) + printf("%d", valArray[j]); + printf("\n\r"); + + } + return(0); +} + + + +int main() { + int return_val, start, length; + + printf("Enter start: \n\r"); + scanf("%d", &start); + printf("Enter length: \n\r"); + scanf("%d", &length); + return_val = MPL3115A2_reg_print(start, length); + +} \ No newline at end of file