The Hiking Pal tracking device firmware. See full description on the detail page: https://www.hackster.io/bowenfeng/hiking-pal-v1-07c02d

Dependencies:   FXOS8700CQ MODSERIAL mbed

Fork of Avnet_ATT_Cellular_IOT by Avnet

Revision:
61:f6b93129f954
Parent:
57:d184175b6b03
Child:
64:09004cd610df
--- a/sensors.cpp	Sat Jul 30 16:26:22 2016 +0000
+++ b/sensors.cpp	Mon Aug 01 18:29:04 2016 +0000
@@ -2,6 +2,8 @@
 #include "sensors.h"
 #include "hardware.h"
 #include "FXOS8700CQ.h"
+#include "HTS221.h"
+#include <string>
 
 //I2C for pmod sensors:
 #define Si1145_PMOD_I2C_ADDR   0xC0 //this is for 7-bit addr 0x60 for the Si7020
@@ -312,7 +314,7 @@
 //* Read the FXOS8700CQ - 6-axis combo Sensor Accelerometer and Magnetometer
 //********************************************************************************************************************************************
 bool bMotionSensor_present = false;
-void init_motion_sensor()
+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:
@@ -333,9 +335,9 @@
         bMotionSensor_present = true;
         fxos.enable();
     }
-} //init_motion_sensor
+} //Init_motion_sensor()
 
-void read_motion_sensor()
+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:
@@ -359,8 +361,46 @@
         sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y);
         sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z);
     } //bMotionSensor_present
-} //read_motion_sensor
+} //Read_motion_sensor()
+
+
+//********************************************************************************************************************************************
+//* Read the HTS221 temperature & humidity sensor on the Cellular Shield
+//********************************************************************************************************************************************
+// These are to be built on the fly
+string my_temp;
+string my_humidity;
+HTS221 hts221;
 
+#define CTOF(x)  ((x)*1.8+32)
+bool bHTS221_present = false;
+void Init_HTS221()
+{
+    int i;
+    void hts221_init(void);
+    i = hts221.begin();
+    if (i)
+    {
+        bHTS221_present = true;
+        pc.printf(BLU "HTS221 Detected (0x%02X)\n\r",i);
+        printf("  Temp  is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
+        printf("  Humid is: %02d %%\n\r",hts221.readHumidity());
+    }
+    else
+    {
+        bHTS221_present = false;
+        pc.printf(RED "HTS221 NOT DETECTED!\n\r");
+    }
+} //Init_HTS221()
+
+void Read_HTS221()
+{
+    if (bHTS221_present)
+    {
+        sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature()));
+        sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity());
+    } //bHTS221_present
+} //Read_HTS221()
 
 #ifdef USE_VIRTUAL_SENSORS
 bool bUsbConnected = false;
@@ -497,14 +537,16 @@
 #ifdef USE_VIRTUAL_SENSORS
    pc.attach(&UsbUartRxCallback, MODSERIAL::RxIrq);
 #endif
+    Init_HTS221();
     Init_Si7020();
     Init_Si1145();
-    init_motion_sensor();
+    Init_motion_sensor();
 } //sensors_init
 
 void read_sensors(void)
 {
+    Read_HTS221();
     Read_Si7020();
     Read_Si1145();
-    read_motion_sensor();
+    Read_motion_sensor();
 } //read_sensors