// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | bytran@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The bytran logo is distributed under the Creative Commons 3.0 Attribution License: https://creativecommons.org/licenses/by/3.0/us/
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object is used to access sensors data avaiable within the device (i.e. a cell phone)
#ifndef SENSORSCELLPHONE_H
#define SENSORSCELLPHONE_H

#include <QObject>
#include <QtSensors/QPressureSensor>
#include <QtSensors/QAmbientTemperatureSensor>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5,9,0)  // The humidity sensor was introduced in Qt 5.9
    #include <QtSensors/QHumiditySensor>
#endif
#include "concpressunitsconvert.h"
#include "temperatureunitsconvert.h"
#include "humidityconvert.h"

class SensorsCellPhone : public QObject
{
    Q_OBJECT    
public:
    explicit SensorsCellPhone(QObject *parent = nullptr);

    // Methods to get the last recorded values from sensors
    double getTotalPressure();
    double getTemperature();
    double getHumidity();

    // Methods to start and end data recording from total pressure sensors
    void setEnableTotalPressureSensor(bool enable);
    bool getTotalPressureSensorIsEnabled();
    void setEnableTemperatureSensor(bool enable);
    bool getTemperatureSensorIsEnabled();
    void setEnableHumiditySensor(bool enable);
    bool getHumiditySensorIsEnabled();

    // Methods to determine if sensors are available
    bool getTotalPressureSensorIsPresent();  // Method is used to indicate if a pressure sensor is available
    bool getTemperatureSensorIsPresent();    // Method is used to indicate if a temperature sensor is available
    bool getHumiditySensorIsPresent();       // Method is used to indicate if a humidity sensor is available

signals:

    // Signal is emited when the sensors data is updated
    void totalPressureUpdated();
    void temperatureUpdated();
    void humidityUpdated();

    // Signal is emited when the activated state of one of the sensors is changed
    void barometerActiveChanged();
    void thermometerActiveChanged();
    void humiditySensorActiveChanged();
    void sensorActiveChanged();

public slots:

private slots:

private:

    // Sensors to get the pressure, temperature and humidity
    QPressureSensor *pressureSensor;               // Pressure sensor
    QAmbientTemperatureSensor *temperatureSensor;  // Ambient temerature sensor
    #if QT_VERSION >= QT_VERSION_CHECK(5,9,0)
        QHumiditySensor *humiditySensor;           // Humidity sensor
    #endif
};

#endif // SENSORSCELLPHONE_H
