Francis CHATAIN / Mbed 2 deprecated MSNV2-Terminal_V1-6

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Files at this revision

API Documentation at this revision

Comitter:
FCH_31
Date:
Thu Aug 23 14:23:46 2018 +0000
Parent:
11:e44a78814c4b
Child:
13:5414193da1de
Commit message:
4

Changed in this revision

Application.cpp Show annotated file Show diff for this revision Revisions of this file
Application.h Show annotated file Show diff for this revision Revisions of this file
IKS01A2.cpp Show annotated file Show diff for this revision Revisions of this file
IKS01A2.h Show annotated file Show diff for this revision Revisions of this file
Sensor.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
util.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Application.cpp	Wed Aug 22 21:25:52 2018 +0000
+++ b/Application.cpp	Thu Aug 23 14:23:46 2018 +0000
@@ -18,6 +18,7 @@
 #include "Tftlcd.h"
 #include "Lora.h"
 #include "Sensor.h"
+#include "IKS01A2.h"
 
 
 static DataBase dataBase    ;       // Database creation 
@@ -28,6 +29,7 @@
 Tftlcd     tftlcd      ;   // eventuellement a déplacer   (uniquement valable sur les conf nucléo)
 Sensor     sensor      ;   // eventuellement a déplacer
 
+Iks01a2    iks01a2      ; 
 
 Application::Application()  {   // constructeur 
     // Basic  instance
@@ -69,9 +71,7 @@
     
     debugSerial = new RawSerial (USBTX,USBRX, 230400);        // Debug Link 
     tftlcd.Init () ;  
-    
     // I2C, SPI, UART .... 
-
 }
 
 
@@ -81,6 +81,8 @@
     //bme280 = new BME280(i2c_rt);
     // depend of the list identified 
     //bme280->init(config->getBME280_MODE());
+    iks01a2.init () ; 
+//    iks01a2.read () ; 
 }
 
 void Application::initActuators(){
@@ -90,26 +92,26 @@
     //bme280->init(config->getBME280_MODE());
 }
 
-void Application::manageSensors () {
-    readSensors             (); 
-    messages.buildSensors   () ; 
-    sendMessage             () ; 
+void Application::manageSensors     () {
+    readSensors                     (); 
+    messages.buildSensors           () ; 
+    sendMessage                     () ; 
 }
 
-void Application::manageGoodhealth () {
-    readSensors                         (); 
-    messages.buildGoodhealth            () ; 
-    //sendMessage                         () ; 
+void Application::manageGoodhealth  () {
+    readSensors                     (); 
+    messages.buildGoodhealth        () ; 
+    //sendMessage                   () ; 
 }
 
-void Application::manageSynchro () {
-    messages.buildSynchro             () ; 
-    //sendMessage                     () ; 
+void Application::manageSynchro     () {
+    messages.buildSynchro           () ; 
+    //sendMessage                   () ; 
 }
 
-void Application::manageConfiguration () {
-    messages.buildConfiguration     () ; 
-    //sendMessage             () ; 
+void Application::manageConfiguration   () {
+    messages.buildConfiguration         () ; 
+    //sendMessage                       () ; 
 }
 
 void Application::manageListening () {
@@ -118,7 +120,7 @@
 
 void Application::getScheduling (uint16_t &TimerPayload,  uint16_t &TimerGoodhealth, uint16_t &TimerSynchro, uint16_t &TimerListening ) {
 
-    TimerPayload        = 1L     ;   // TODO  Dépend de la lecture de la memoire  (ici simulé)
+    TimerPayload        = 2L     ;   // TODO  Dépend de la lecture de la memoire  (ici simulé)
     TimerGoodhealth     = 60L    ; 
     TimerSynchro        = 0L     ;  
     TimerListening      = 0L     ;                  
@@ -133,13 +135,14 @@
 void Application::readSensors       () {
     printf( "*** APP_ ***  readSensors \r\n");
     // depend of the list identified 
-    // Each sensor send can put a event in the db
-    }
+    // Each sensor send a event in the db
+    iks01a2.read () ; 
+}
 
 void Application::writeActuators    () {
     // depend of the list identified 
     // Each sensor send can put a event in the queu
-    }
+}
     
 
 
--- a/Application.h	Wed Aug 22 21:25:52 2018 +0000
+++ b/Application.h	Thu Aug 23 14:23:46 2018 +0000
@@ -16,6 +16,7 @@
 // All Sensors/Actuator header here
 #include "Sensor.h"
 #include "Actuator.h"
+#include "IKS01A2.h"
 
 
 #ifndef __APPLICATION_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IKS01A2.cpp	Thu Aug 23 14:23:46 2018 +0000
@@ -0,0 +1,215 @@
+/*
+ * MISNet   
+ *
+ *  IKS01A2:   STM Sensors Board 
+ *
+ *  Created on: August 17, 2018       Author: Francis CHATAIN
+ *
+ */
+
+// =====================================  Includes
+
+#include "mbed.h"
+#include "main.h"
+#include "IKS01A2.h"
+#include "XNucleoIKS01A2.h"
+
+// =====================================  Method of class
+
+/* Instantiate the expansion board */
+static XNucleoIKS01A2 *mems_expansion_board;// = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+
+/* Retrieve the composing elements of the expansion board */
+static HTS221Sensor         *hum_temp;//       = mems_expansion_board->ht_sensor;
+static LPS22HBSensor        *press_temp;//     = mems_expansion_board->pt_sensor;
+static LSM303AGRMagSensor   *magnetometer;//   = mems_expansion_board->magnetometer;
+static LSM303AGRAccSensor   *accelerometer;//  = mems_expansion_board->accelerometer;
+static LSM6DSLSensor        *acc_gyro;//       = mems_expansion_board->acc_gyro;
+
+static char *print_double   ( char* str, double v, int decimalDigits=2) ; 
+
+
+Iks01a2::Iks01a2 () {}
+Iks01a2::~Iks01a2 () {}
+    
+void Iks01a2::init () {
+    mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+    hum_temp       = mems_expansion_board->ht_sensor;
+    press_temp     = mems_expansion_board->pt_sensor;
+    magnetometer   = mems_expansion_board->magnetometer;
+    accelerometer  = mems_expansion_board->accelerometer;
+    acc_gyro       = mems_expansion_board->acc_gyro;
+
+    /* Enable all sensors */
+    hum_temp->enable        ();
+    press_temp->enable      ();
+    magnetometer->enable    ();
+    accelerometer->enable   ();
+    acc_gyro->enable_x      ();
+    acc_gyro->enable_g      ();
+
+    hum_temp->read_id       (&id1);
+    printf("*** IKS ***  HTS221  humidity & temperature    = 0x%X\r\n", id1);
+    press_temp->read_id     (&id2);
+    printf("*** IKS ***  LPS22HB  pressure & temperature   = 0x%X\r\n", id2);
+    magnetometer->read_id   (&id3);
+    printf("*** IKS ***  LSM303AGR magnetometer            = 0x%X\r\n", id3);
+    accelerometer->read_id  (&id4);
+    printf("*** IKS ***  LSM303AGR accelerometer           = 0x%X\r\n", id4);
+    acc_gyro->read_id       (&id5);
+    printf("*** IKS ***  LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id5);
+    
+    if (hum_temp->get_temperature   (&valueTH1) != 0) {
+        printf("!!!!!!!!!!!!!!");
+    }   
+
+    hum_temp->get_humidity      (&valueTH2)   ;   
+    printf("*** IKS ***  ============================================================== \r\n");
+    printf("*** IKS ***  HTS221    : [temp] %7f C, [hum]   %7f  \r\n"    , valueTH1,valueTH2);
+    //printf("*** IKS ***  HTS221    : [temp] %7s C, [hum]   %7s  \r\n"    , print_double(buffer1, valueTH1), print_double(buffer2, valueTH2));
+    press_temp->get_temperature (&valueTP1)   ;    
+    press_temp->get_pressure    (&valueTP2)   ;    
+    printf("*** IKS ***  LPS22HB   : [temp] %7f C, [press] %f mbar\r\n" , valueTP1, valueTP2);
+    //printf("*** IKS ***  LPS22HB   : [temp] %7s C, [press] %s mbar\r\n" , print_double(buffer3, valueTP1), print_double(buffer4, valueTP2));
+    magnetometer->get_m_axes    (axesM)       ;   
+    printf("*** IKS ***  LSM303AGR : [mag/mgauss]  %6ld, %6ld, %6ld\r\n", axesM[0], axesM[1], axesM[2]);  
+    accelerometer->get_x_axes   (axesA)       ;   
+    printf("*** IKS ***  LSM303AGR : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesA[0], axesA[1], axesA[2]);
+    acc_gyro->get_x_axes        (axesG1)      ;    
+    printf("*** IKS ***  LSM6DSL   : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesG1[0], axesG1[1], axesG1[2]);
+    acc_gyro->get_g_axes        (axesG2)      ;        
+    printf("*** IKS ***  LSM6DSL   : [gyro/mdps]   %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]);
+    printf("*** IKS ***  ============================================================== \r\n");
+
+    
+    printf("============>>>>>>>>>>> Deuxieme lecture \r\n");
+    printf("Adresse de hum_temp : %p\r\n", hum_temp);    
+    if (hum_temp->get_temperature   (&valueTH1) != 0) {
+        printf("!!!!!!!!!!!!!!");
+    }   
+
+    hum_temp->get_humidity      (&valueTH2)   ;   
+    printf("*** IKS ***  ============================================================== \r\n");
+    printf("*** IKS ***  HTS221    : [temp] %7f C, [hum]   %7f  \r\n"    , valueTH1,valueTH2);
+
+    /* Disable all sensors */
+    hum_temp->disable        ();
+    press_temp->disable      ();
+    magnetometer->disable    ();
+    accelerometer->disable   ();
+    acc_gyro->disable_x      ();
+    acc_gyro->disable_g      ();
+
+    /* Enable all sensors */
+    hum_temp->enable        ();
+    press_temp->enable      ();
+    magnetometer->enable    ();
+    accelerometer->enable   ();
+    acc_gyro->enable_x      ();
+    acc_gyro->enable_g      ();
+
+    wait(2);
+    
+    printf("============>>>>>>>>>>> Troisieme lecture \r\n");
+    printf("Adresse de hum_temp : %p\r\n", hum_temp);    
+    if (hum_temp->get_temperature   (&valueTH1) != 0) {
+        printf("!!!!!!!!!!!!!!");
+    }   
+
+    hum_temp->get_humidity      (&valueTH2)   ;   
+    printf("*** IKS ***  ============================================================== \r\n");
+    printf("*** IKS ***  HTS221    : [temp] %7f C, [hum]   %7f  \r\n"    , valueTH1,valueTH2);
+} 
+
+
+void Iks01a2::getValues () {} ;   
+
+void Iks01a2::read ()  
+{
+    /* Enable all sensors 
+    if (hum_temp->enable() != 0) printf("*** IKS *** enable error\r\n");
+    press_temp->enable      ();
+    magnetometer->enable    ();
+    accelerometer->enable   ();
+    acc_gyro->enable_x      ();
+    acc_gyro->enable_g      ();
+  */
+
+    mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+    hum_temp       = mems_expansion_board->ht_sensor;
+    press_temp     = mems_expansion_board->pt_sensor;
+    magnetometer   = mems_expansion_board->magnetometer;
+    accelerometer  = mems_expansion_board->accelerometer;
+    acc_gyro       = mems_expansion_board->acc_gyro;
+
+    printf( "*** IKS ***  Mon Read a moi que j'ai \r\n") ; 
+    valueTH1 = valueTH2 =0 ; 
+  
+    
+    if (hum_temp->get_temperature   (&valueTH1) != 0) {
+        printf("!!!!!!!!!!!!!!");
+    }   
+    //hum_temp->get_temperature   (&valueTH1)   ;   
+    hum_temp->get_humidity      (&valueTH2)   ;   
+    printf("*** IKS ***  ============================================================== \r\n");
+    printf("Adresse de hum_temp : %p\r\n", hum_temp);
+    printf("*** IKS ***  HTS221    : [temp] %7f C, [hum]   %7f  \r\n"    , valueTH1,valueTH2);
+    //printf("*** IKS ***  HTS221    : [temp] %7s C, [hum]   %7s  \r\n"    , print_double(buffer1, valueTH1), print_double(buffer2, valueTH2));
+    press_temp->get_temperature (&valueTP1)   ;    
+    press_temp->get_pressure    (&valueTP2)   ;    
+    printf("*** IKS ***  LPS22HB   : [temp] %7f C, [press] %f mbar\r\n" , valueTP1, valueTP2);
+    //printf("*** IKS ***  LPS22HB   : [temp] %7s C, [press] %s mbar\r\n" , print_double(buffer3, valueTP1), print_double(buffer4, valueTP2));
+    magnetometer->get_m_axes    (axesM)       ;   
+    printf("*** IKS ***  LSM303AGR : [mag/mgauss]  %6ld, %6ld, %6ld\r\n", axesM[0], axesM[1], axesM[2]);  
+    accelerometer->get_x_axes   (axesA)       ;   
+    printf("*** IKS ***  LSM303AGR : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesA[0], axesA[1], axesA[2]);
+    acc_gyro->get_x_axes        (axesG1)      ;    
+    printf("*** IKS ***  LSM6DSL   : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesG1[0], axesG1[1], axesG1[2]);
+    acc_gyro->get_g_axes        (axesG2)      ;        
+    printf("*** IKS ***  LSM6DSL   : [gyro/mdps]   %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]);
+    printf("*** IKS ***  ============================================================== \r\n");
+  
+
+   
+
+}
+
+
+
+//  A deplacer dans utils   TODO
+
+/* Helper function for printing floats & doubles */
+static char *print_double(char* str, double v, int decimalDigits)
+{
+  int i = 1;
+  int intPart, fractPart;
+  int len;
+  char *ptr;
+
+  /* prepare decimal digits multiplicator */
+  for (;decimalDigits!=0; i*=10, decimalDigits--);
+
+  /* calculate integer & fractinal parts */
+  intPart = (int)v;
+  fractPart = (int)((v-(double)(int)v)*i);
+
+  /* fill in integer part */
+  sprintf(str, "%i.", intPart);
+
+  /* prepare fill in of fractional part */
+  len = strlen(str);
+  ptr = &str[len];
+
+  /* fill in leading fractional zeros */
+  for (i/=10;i>1; i/=10, ptr++) {
+    if (fractPart >= i) {
+      break;
+    }
+    *ptr = '0';
+  }
+
+  /* fill in (rest of) fractional part */
+  sprintf(ptr, "%i", fractPart);
+
+  return str;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IKS01A2.h	Thu Aug 23 14:23:46 2018 +0000
@@ -0,0 +1,43 @@
+/*
+ * MISNet   
+ *
+ *  IKS01A2:   STM Sensors Board 
+ *
+ *  Created on: August 17, 2018         Author: Francis CHATAIN
+ *
+ */
+#ifndef __IKS01A2_H__
+#define __IKS01A2_H__
+
+
+#include "mbed.h"
+#include "main.h"
+
+
+// =======================================  Class content 
+class Iks01a2 
+{
+    // Public variable /method 
+    public:
+        Iks01a2();
+        ~Iks01a2();
+        
+        void init () ; 
+        void read () ; 
+        void getValues () ; 
+              
+    // Private variable /method 
+    private:
+        uint8_t     id1, id2, id3, id4, id5, id6, id7;
+        float       valueTH1, valueTH2, valueTP1, valueTP2;
+        int32_t     axesA[3], axesM[3], axesG1[3], axesG2[3];
+        char        buffer1[32], buffer2[32], buffer3[32], buffer4[32];
+        
+        char *print_double(char* str, double v, int decimalDigits)  ; 
+    
+    // Protected variable /method 
+    protected:
+      
+} ; 
+
+#endif 
\ No newline at end of file
--- a/Sensor.cpp	Wed Aug 22 21:25:52 2018 +0000
+++ b/Sensor.cpp	Thu Aug 23 14:23:46 2018 +0000
@@ -6,10 +6,6 @@
  *  Created on: August 17, 2018       Author: Francis CHATAIN
  *
  */
- 
-#ifndef __SENSOR_C__
-#define __SENSOR_C__
-
 
 // =====================================  Includes
 #include "Sensor.h"
@@ -19,6 +15,3 @@
 
 void Sensor::test () {}
 
-
-
-#endif
\ No newline at end of file
--- a/main.cpp	Wed Aug 22 21:25:52 2018 +0000
+++ b/main.cpp	Thu Aug 23 14:23:46 2018 +0000
@@ -80,7 +80,8 @@
 void loop () { 
     while(1) { 
         // deepsleep ();     // perd la conf uart 
-        sleep () ; 
+        //sleep () ; 
+        wait(1);
     } 
 }
 // No action : all event by IRQ 
--- a/util.cpp	Wed Aug 22 21:25:52 2018 +0000
+++ b/util.cpp	Thu Aug 23 14:23:46 2018 +0000
@@ -10,6 +10,44 @@
 #include "mbed.h"
 #include <string>
 
+
+/* Helper function for printing floats & doubles */
+static char *print_double(char* str, double v, int decimalDigits)
+{
+  int i = 1;
+  int intPart, fractPart;
+  int len;
+  char *ptr;
+
+  /* prepare decimal digits multiplicator */
+  for (;decimalDigits!=0; i*=10, decimalDigits--);
+
+  /* calculate integer & fractinal parts */
+  intPart = (int)v;
+  fractPart = (int)((v-(double)(int)v)*i);
+
+  /* fill in integer part */
+  sprintf(str, "%i.", intPart);
+
+  /* prepare fill in of fractional part */
+  len = strlen(str);
+  ptr = &str[len];
+
+  /* fill in leading fractional zeros */
+  for (i/=10;i>1; i/=10, ptr++) {
+    if (fractPart >= i) {
+      break;
+    }
+    *ptr = '0';
+  }
+
+  /* fill in (rest of) fractional part */
+  sprintf(ptr, "%i", fractPart);
+
+  return str;
+}
+
+
 // Convert a byte to string
 string binToString (unsigned char *inputData, int dataLength)
 {
@@ -25,3 +63,29 @@
     for (i = 0; i < len; i++) 
         printf("%02x", buf[i]); printf("\n"); 
 }
+
+
+// LITTLE ENDIAN!
+uint16_t read16(uint8_t *src)
+{
+  uint16_t d;
+  uint8_t b;
+  b = *src;
+  d = *(src+1);
+  d <<= 8;
+  d |= b;
+  return d;
+}
+
+// LITTLE ENDIAN!
+uint32_t read32(uint8_t *src)
+{
+  uint32_t d;
+  uint16_t b;
+
+  b = read16(src);
+  d = read16(src+2);
+  d <<= 16;
+  d |= b;
+  return d;
+}
\ No newline at end of file