yes Spada / Mbed OS programme
Revision:
11:dbc310addbf6
Parent:
6:5f56e551f84f
Child:
12:856286ad4cdc
--- a/WeatherStation.cpp	Tue Mar 12 13:34:08 2019 +0000
+++ b/WeatherStation.cpp	Tue Mar 19 20:48:48 2019 +0000
@@ -1,16 +1,17 @@
 #include "WeatherStation.h"
 
 // initialization of static data members
-    const int WeatherStation::m_blinkInterval = 500;
+    //const int WeatherStation::m_blinkInterval = 500;
     const int WeatherStation::m_measurementInterval = 10000;
 
 // constructor
-WeatherStation::WeatherStation(NRFDevKit& nrfDevKit, Logger& logger) 
-:
-    m_nrfDevKit(nrfDevKit),
+WeatherStation::WeatherStation(IDevKit& iDevKit, Logger& logger, BLE& ble) :
+    GAPPeripheral(ble, iDevKit, "Spada-Guibert", GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED, m_eventQueue, logger),
+    m_iDevKit(iDevKit),
     m_logger(logger),
-    m_lps25hb(m_nrfDevKit.getSDA(), m_nrfDevKit.getSCL(), m_logger),
-    m_hdc1000(m_nrfDevKit.getSDA(), m_nrfDevKit.getSCL(), m_nrfDevKit.getDataRdy(), m_logger){
+    //m_peripheral(ble, iDevKit, "Spada-Guibert", GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED,m_eventQueue, logger),
+    m_lps25hb(m_iDevKit.getSDA(), m_iDevKit.getSCL(), m_logger),
+    m_hdc1000(m_iDevKit.getSDA(), m_iDevKit.getSCL(), m_iDevKit.getDataRdy(), m_logger) {
 }
 
 void WeatherStation::start() {
@@ -45,7 +46,7 @@
   //   1. the first argument represents the interval in milliseconds at which the event is executed
   //   2. the second argument represents  the address of instance of the object on which the method passed in argument 3 will be applied
   //  3. the third argument is the address of the method to be called (applied to the object passed as argument 2)
-  m_eventQueue.call_every(m_blinkInterval, &m_nrfDevKit, &NRFDevKit::blink1);
+  //m_eventQueue.call_every(m_blinkInterval, &m_iDevKit, &IDevKit::toggleLed1);
 
   // schedule measurements every m_measurementInterval milliseconds
   // apply the same syntax as in the previous call
@@ -55,10 +56,20 @@
   // m_eventQueue.call_every(TO COMPLETED);
   
   m_eventQueue.call_every(m_measurementInterval, this, &WeatherStation::performMeasurements);
+  
+  // Starting the BLE peripheral
+  // the syntax used here is the following:
+  //  1. the first argument represents  the address of instance of the object on which the method passed in argument 3 will be applied
+  //  2. the second argument is the address of the method to be called (applied to the object passed as argument 2)
+    m_eventQueue.call(this, &WeatherStation::advertise);
     
   // this will not return until shutdown
   m_eventQueue.dispatch_forever(); 
 }
+
+void WeatherStation::advertise(void){
+    GAPPeripheral::advertise();
+}
  
 void WeatherStation::performMeasurements(void) {
   m_logger.log("Performing measurements:\r\n");
@@ -73,7 +84,7 @@
   m_logger.log("Humidiy:        %.02f %%\r\n", m_hdc1000.getHumidity());
   
   // get and log the battery level
-  m_logger.log("Battery:        %u mV\r\n", m_nrfDevKit.getBatteryLevel());
+  m_logger.log("Battery:        %u mV\r\n", m_iDevKit.getBatteryLevel());
   
   //Cleaning the console by the addition of a blank line
   m_logger.log("\r\n");