LoRa_Node_STM32F103C8T6

Dependencies:   mbed mbed-STM32F103C8T6 OneWireCRC_LoRa_Node SX1276Lib_LoRa_Node

Revision:
5:6e899f5db65e
Parent:
4:a8853c148f2a
Child:
6:531b8dccca06
--- a/Thermometer.cpp	Mon Apr 23 21:28:49 2018 +0000
+++ b/Thermometer.cpp	Mon Apr 30 17:10:02 2018 +0000
@@ -1,9 +1,13 @@
 #include "Thermometer.h"
 
+Thermometer thermometer(true, true, false, THERM_PIN);
+
 Thermometer::Thermometer(bool crcOn, bool useAddr, bool parasitic, PinName pin)
     : thermometer(crcOn, useAddr, parasitic, pin)
 {
     meassuredValue = 0.0;
+    intervalSeconds = MEASURE_INTERVAL;
+    counter = 0;
 };
 
 void Thermometer::Init()
@@ -12,9 +16,18 @@
     thermometer.setResolution(THERMOMETER_RESOLUTION); 
 };
 
-void Thermometer::StartPeriodicMeassure(float timeSec)
+void Thermometer::StartPeriodicMeassure(int seconds)
 {
-   thermometerTicker.attach(this,&Thermometer::OnSampleTick,timeSec);
+   Meassure();
+   intervalSeconds = seconds;
+   counter = 0;
+   thermometerTicker.attach(this,&Thermometer::OnSampleTick,1.0);       // kazdu sekundu
+};
+
+void Thermometer::StopPeriodicMeassure()
+{
+   thermometerTicker.detach();
+   counter = 0;
 };
 
 void Thermometer::Meassure()
@@ -25,9 +38,14 @@
         meassuredValue = thermometer.readTemperature();
     }
     rfm.SendValue(GATEWAY_ID, meassuredValue);
-}
+};
 
 void Thermometer::OnSampleTick()
 {
-    Meassure();
+    counter++;
+    if(counter >= intervalSeconds)
+    {
+        Meassure();
+        counter = 0;
+    }
 };
\ No newline at end of file