yes Spada / Mbed OS programme
Committer:
loicguibert
Date:
Tue Mar 05 10:27:40 2019 +0000
Revision:
4:bfe306335065
Child:
5:0d9e292a9d06
Mesurements ok, lib ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
loicguibert 4:bfe306335065 1 #include "WeatherStation.h"
loicguibert 4:bfe306335065 2
loicguibert 4:bfe306335065 3 // initialization of static data members
loicguibert 4:bfe306335065 4 // here you must define and initialize WeatherStation::m_measurementInterval and WeatherStation::m_blinkInterval
loicguibert 4:bfe306335065 5 const int WeatherStation::m_blinkInterval = 500;
loicguibert 4:bfe306335065 6 const int WeatherStation::m_measurementInterval = 10000;
loicguibert 4:bfe306335065 7
loicguibert 4:bfe306335065 8 // constructor
loicguibert 4:bfe306335065 9 WeatherStation::WeatherStation(NRFDevKit& nrfDevKit, Logger& logger)
loicguibert 4:bfe306335065 10 : // newly declared devices must be initialized here
loicguibert 4:bfe306335065 11 m_nrfDevKit(nrfDevKit),
loicguibert 4:bfe306335065 12 m_logger(logger),
loicguibert 4:bfe306335065 13 m_lps25hb(m_nrfDevKit.getSDA(), m_nrfDevKit.getSCL(), m_logger),
loicguibert 4:bfe306335065 14 m_hdc1000(m_nrfDevKit.getSDA(), m_nrfDevKit.getSCL(), m_nrfDevKit.getDataRdy(), m_logger){
loicguibert 4:bfe306335065 15 }
loicguibert 4:bfe306335065 16
loicguibert 4:bfe306335065 17 void WeatherStation::start() {
loicguibert 4:bfe306335065 18 m_logger.log("WeatherStation is starting\r\n");
loicguibert 4:bfe306335065 19 // make sure that the LPW25HB device is present
loicguibert 4:bfe306335065 20 // if not log an error and return
loicguibert 4:bfe306335065 21
loicguibert 4:bfe306335065 22
loicguibert 4:bfe306335065 23
loicguibert 4:bfe306335065 24 m_logger.log("LPS25HB device found\r\n");
loicguibert 4:bfe306335065 25 // make sure that the HDC1000 device is present
loicguibert 4:bfe306335065 26 // if not log an error and return
loicguibert 4:bfe306335065 27
loicguibert 4:bfe306335065 28 m_logger.log("HDC1000 device found\r\n");
loicguibert 4:bfe306335065 29
loicguibert 4:bfe306335065 30 // to show we're running we'll blink every m_blinkInterval milliseconds
loicguibert 4:bfe306335065 31 // the syntax used here is the following:
loicguibert 4:bfe306335065 32 // 1. the first argument represents the interval in milliseconds at which the event is executed
loicguibert 4:bfe306335065 33 // 2. the second argument represents the address of instance of the object on which the method passed in argument 3 will be applied
loicguibert 4:bfe306335065 34 // 3. the third argument is the address of the method to be called (applied to the object passed as argument 2)
loicguibert 4:bfe306335065 35 m_eventQueue.call_every(m_blinkInterval, &m_nrfDevKit, &NRFDevKit::blink1);
loicguibert 4:bfe306335065 36
loicguibert 4:bfe306335065 37 // schedule measurements every m_measurementInterval milliseconds
loicguibert 4:bfe306335065 38 // apply the same syntax as in the previous call
loicguibert 4:bfe306335065 39 // 1. the measurement interval is m_measurementInterval
loicguibert 4:bfe306335065 40 // 2. the object is the WeatherStation itself (recall how you refer to the current object in Java - the same applies in c++)
loicguibert 4:bfe306335065 41 // 3. the method to call is performMeasurements()
loicguibert 4:bfe306335065 42 // m_eventQueue.call_every(TO COMPLETED);
loicguibert 4:bfe306335065 43
loicguibert 4:bfe306335065 44 m_eventQueue.call_every(m_measurementInterval, this, &WeatherStation::performMeasurements);
loicguibert 4:bfe306335065 45
loicguibert 4:bfe306335065 46 // this will not return until shutdown
loicguibert 4:bfe306335065 47 m_eventQueue.dispatch_forever();
loicguibert 4:bfe306335065 48 }
loicguibert 4:bfe306335065 49
loicguibert 4:bfe306335065 50 void WeatherStation::performMeasurements(void) {
loicguibert 4:bfe306335065 51 m_logger.log("Performing measurements\r\n");
loicguibert 4:bfe306335065 52
loicguibert 4:bfe306335065 53 // get and log pressure
loicguibert 4:bfe306335065 54 m_logger.log("Pressure value is %f HPA.\r\n", m_lps25hb.getPressure());
loicguibert 4:bfe306335065 55
loicguibert 4:bfe306335065 56 // get and log temperature
loicguibert 4:bfe306335065 57 m_logger.log("Temperature value is %f DEG.\r\n", m_hdc1000.getTemperature());
loicguibert 4:bfe306335065 58
loicguibert 4:bfe306335065 59 // get and log humidity
loicguibert 4:bfe306335065 60 m_logger.log("Humidiy value is %f.\r\n", m_hdc1000.getHumidity());
loicguibert 4:bfe306335065 61
loicguibert 4:bfe306335065 62 // get and log the battery level
loicguibert 4:bfe306335065 63 m_logger.log("Battery value is %f.\r\n", m_nrfDevKit.getBatteryLevel());
loicguibert 4:bfe306335065 64
loicguibert 4:bfe306335065 65 }
loicguibert 4:bfe306335065 66