Fork with SeeedStudio Xadow GPS v2 enabled
Dependencies: FXOS8700CQ MODSERIAL XadowGPS mbed
Fork of Avnet_ATT_Cellular_IOT by
Diff: sensors.cpp
- Revision:
- 57:d184175b6b03
- Parent:
- 56:cb42ff383dab
- Child:
- 61:f6b93129f954
diff -r cb42ff383dab -r d184175b6b03 sensors.cpp --- a/sensors.cpp Thu Jul 28 17:21:31 2016 +0000 +++ b/sensors.cpp Thu Jul 28 23:55:06 2016 +0000 @@ -1,15 +1,13 @@ #include "mbed.h" +#include "sensors.h" #include "hardware.h" -#include "sensors.h" +#include "FXOS8700CQ.h" //I2C for pmod sensors: #define Si1145_PMOD_I2C_ADDR 0xC0 //this is for 7-bit addr 0x60 for the Si7020 #define Si7020_PMOD_I2C_ADDR 0x80 //this is for 7-bit addr 0x4 for the Si7020 -#include "FXOS8700CQ.h" -// Pin names for the motion sensor FRDM-K64F board: -FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) -// Storage for the data from the sensor +// Storage for the data from the motion sensor SRAWDATA accel_data; SRAWDATA magn_data; //InterruptIn fxos_int1(PTC6); // unused, common with SW2 on FRDM-K64F @@ -18,7 +16,7 @@ void trigger_fxos_int2(void) { fxos_int2_triggered = true; - //us_ellapsed = t.read_us(); + } /*------------------------------------------------------------------------------ @@ -265,25 +263,29 @@ //printf("PS2_Data = %d\n", PS2); //printf("PS3_Data = %d\n", PS3); //OBJECT PRESENT? +#if (0) if(PS1 < 22000){ //printf("Object Far\n"); - sprintf(SENSOR_DATA.Proximity, "Object Far"); + sprintf(SENSOR_DATA.Proximity, "Object Far\0"); } else if(PS1 < 24000) { //printf("Object in Vicinity\n"); - sprintf(SENSOR_DATA.Proximity, "Object in Vicinity"); + sprintf(SENSOR_DATA.Proximity, "Object in Vicinity\0"); } else if (PS1 < 30000) { //printf("Object Near\n"); - sprintf(SENSOR_DATA.Proximity, "Object Near"); + sprintf(SENSOR_DATA.Proximity, "Object Near\0"); } else { //printf("Object Very Near\n"); - sprintf(SENSOR_DATA.Proximity, "Object Very Near"); + sprintf(SENSOR_DATA.Proximity, "Object Very Near\0"); } +#else + sprintf(SENSOR_DATA.Proximity, "%d\0", PS1); +#endif //Force ALS read: //WriteTo_Si1145_Register(REG_COMMAND, 0x06); @@ -312,8 +314,11 @@ bool bMotionSensor_present = false; void init_motion_sensor() { + // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus... + // Class instantiation with pin names for the motion sensor on the FRDM-K64F board: + FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) int iWhoAmI = fxos.get_whoami(); - + printf("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI); // Iterrupt for active-low interrupt line from FXOS // Configured with only one interrupt on INT2 signaling Data-Ready @@ -332,8 +337,12 @@ void read_motion_sensor() { + // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus... + // Class instantiation with pin names for the motion sensor on the FRDM-K64F board: + FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) if (bMotionSensor_present) { + fxos.enable(); fxos.get_data(&accel_data, &magn_data); //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z); sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x);