Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: WeatherStation.cpp
- Revision:
- 4:bfe306335065
- Child:
- 5:0d9e292a9d06
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WeatherStation.cpp Tue Mar 05 10:27:40 2019 +0000
@@ -0,0 +1,66 @@
+#include "WeatherStation.h"
+
+// initialization of static data members
+// here you must define and initialize WeatherStation::m_measurementInterval and WeatherStation::m_blinkInterval
+ const int WeatherStation::m_blinkInterval = 500;
+ const int WeatherStation::m_measurementInterval = 10000;
+
+// constructor
+WeatherStation::WeatherStation(NRFDevKit& nrfDevKit, Logger& logger)
+: // newly declared devices must be initialized here
+ m_nrfDevKit(nrfDevKit),
+ 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){
+}
+
+void WeatherStation::start() {
+ m_logger.log("WeatherStation is starting\r\n");
+ // make sure that the LPW25HB device is present
+ // if not log an error and return
+
+
+
+ m_logger.log("LPS25HB device found\r\n");
+ // make sure that the HDC1000 device is present
+ // if not log an error and return
+
+ m_logger.log("HDC1000 device found\r\n");
+
+ // to show we're running we'll blink every m_blinkInterval milliseconds
+ // the syntax used here is the following:
+ // 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);
+
+ // schedule measurements every m_measurementInterval milliseconds
+ // apply the same syntax as in the previous call
+ // 1. the measurement interval is m_measurementInterval
+ // 2. the object is the WeatherStation itself (recall how you refer to the current object in Java - the same applies in c++)
+ // 3. the method to call is performMeasurements()
+ // m_eventQueue.call_every(TO COMPLETED);
+
+ m_eventQueue.call_every(m_measurementInterval, this, &WeatherStation::performMeasurements);
+
+ // this will not return until shutdown
+ m_eventQueue.dispatch_forever();
+}
+
+void WeatherStation::performMeasurements(void) {
+ m_logger.log("Performing measurements\r\n");
+
+ // get and log pressure
+ m_logger.log("Pressure value is %f HPA.\r\n", m_lps25hb.getPressure());
+
+ // get and log temperature
+ m_logger.log("Temperature value is %f DEG.\r\n", m_hdc1000.getTemperature());
+
+ // get and log humidity
+ m_logger.log("Humidiy value is %f.\r\n", m_hdc1000.getHumidity());
+
+ // get and log the battery level
+ m_logger.log("Battery value is %f.\r\n", m_nrfDevKit.getBatteryLevel());
+
+}
+