hhh

Dependencies:   HC_SR04_Ultrasonic_Library X_NUCLEO_IKS01A2 mbed LoRaWAN-lib SX1272Lib

Fork of LoRaWANdemoUnina by Salvatore Gulfo

Revision:
9:85c85c65299a
Parent:
8:346c55cb6033
--- a/app/main.cpp	Tue Oct 03 13:11:33 2017 +0000
+++ b/app/main.cpp	Fri Nov 17 12:29:00 2017 +0000
@@ -21,15 +21,18 @@
 #include "SerialDisplay.h"
 #include "XNucleoIKS01A2.h"
 #include "string.h"
+#include "ultrasonic.h"
 
 /* Instantiate the expansion board */
 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+ultrasonic usensor(D8, D9, .1, 1);
+//static HCSR04 *myUS = ultrasonic::ultrasonic(D8,D9,.1,1) //set the trigger pin to D8 and the Echo pin to D9
 
 /* Retrieve the composing elements of the expansion board */
-static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
+//static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
 //static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
 //static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
-
+//static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
 /*!
  * Defines the application data transmission duty cycle. 5s, value in [ms].
  */
@@ -56,7 +59,7 @@
  *
  * \remark Please note that when ADR is enabled the end-device should be static
  */
-#define LORAWAN_ADR_ON                              1
+#define LORAWAN_ADR_ON                              0
 
 #if defined( USE_BAND_868 )
 
@@ -334,13 +337,15 @@
  */
     float value1, value2;
     char buffer1[32];
+    long dist1;
   //  int16_t Myaxes_int[3];
   //  float Myaxes[3];
   //  float sensitivity;
  //   int32_t axes[3];
- //   char Cont[64];
-   uint32_t Cont[64];
- //  InterruptIn BlueButton(USER_BUTTON);  
+    char Cont[64];
+ //  uint32_t Cont[64];
+ // InterruptIn BlueButton(USER_BUTTON);  
+ 
 static void PrepareTxFrame( uint8_t port )
 {
     
@@ -349,9 +354,13 @@
         
     case 13:
     
-        hum_temp->get_temperature(&value1);
-        hum_temp->get_humidity(&value2);
-        strcpy((char*)Cont, (char*) print_double(buffer1,value2) );
+       
+        //  hum_temp->get_temperature(&value1);
+     //     hum_temp->get_humidity(&value2);
+      //    press_temp->get_pressure(&value1);
+          dist1 = usensor.getCurrentDistance();
+         // usensor->getCurrentDistance(&dist1); 
+          strcpy((char*)Cont, (char*) print_double(buffer1,dist1) );
 //       strcat((char*)Cont, " " );
  //       strcat((char*)Cont, print_double(buffer1,value2) );
  //       strcat((char*)Cont, " ");
@@ -389,16 +398,18 @@
          strcat(Cont, " ");
          strcat(Cont, (char*) print_double(buffer1, value2)); */
          
-       // while(1) {
-        AppDataSize = sprintf ((char*)AppData,(char*)Cont);    
-  /*       if (BlueButton)
+  /*      while(1) {
+   //     AppDataSize = sprintf ((char*)AppData,(char*)Cont);    
+         if (BlueButton)
          { AppDataSize = sprintf((char*)AppData, "0");   
-          break;  }
+         break;  
+  }
           else
        {  AppDataSize = sprintf((char*)AppData, "1");   
-         break;        }  
- //   AppDataSize = sprintf((char*)AppData, "69"); 
-         //} */
+         break; 
+                }  */
+    AppDataSize = sprintf((char*)AppData, (char*)Cont); 
+  //       } 
     break;
     
     case 15:
@@ -881,10 +892,11 @@
     
     //enable sensors
   //  accelerometer -> enable();
-    hum_temp -> enable();
+  //  hum_temp -> enable();
+ //   press_temp -> enable();
    // acc_gyro->enable_x();
    // acc_gyro->enable_g();
-
+    usensor.startUpdates();
     BoardInit( );
     SerialDisplayInit( );
 
@@ -1041,7 +1053,7 @@
                 IsNetworkJoinedStatusUpdate = true;
                 break;
             }
-            case DEVICE_STATE_SEND:
+            case DEVICE_STATE_SEND:    //send frame
             {
                 if( NextTx == true )
                 {