LoRa_Node_STM32F103C8T6

Dependencies:   mbed mbed-STM32F103C8T6 OneWireCRC_LoRa_Node SX1276Lib_LoRa_Node

Thermometer.cpp

Committer:
lukas_formanek
Date:
2018-04-30
Revision:
5:6e899f5db65e
Parent:
4:a8853c148f2a
Child:
6:531b8dccca06

File content as of revision 5:6e899f5db65e:

#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()
{
    thermometer.initialize();
    thermometer.setResolution(THERMOMETER_RESOLUTION); 
};

void Thermometer::StartPeriodicMeassure(int seconds)
{
   Meassure();
   intervalSeconds = seconds;
   counter = 0;
   thermometerTicker.attach(this,&Thermometer::OnSampleTick,1.0);       // kazdu sekundu
};

void Thermometer::StopPeriodicMeassure()
{
   thermometerTicker.detach();
   counter = 0;
};

void Thermometer::Meassure()
{
    meassuredValue = thermometer.readTemperature();
    while((rint(meassuredValue)) == 85) {
        Init();
        meassuredValue = thermometer.readTemperature();
    }
    rfm.SendValue(GATEWAY_ID, meassuredValue);
};

void Thermometer::OnSampleTick()
{
    counter++;
    if(counter >= intervalSeconds)
    {
        Meassure();
        counter = 0;
    }
};