From a38a67419e51603c4bec5fddd5b5253a717f7cab Mon Sep 17 00:00:00 2001 From: Daniel TARTAVEL Date: Sun, 19 Oct 2025 08:21:35 +0200 Subject: [PATCH] debug sauvegarde\naffichage fleche --- src/barometertrend.h | 15 ++++++++++--- src/main.cpp | 6 ++++++ src/pws2mqtt.cpp | 50 ++++++++++++++++++++++++++++---------------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/barometertrend.h b/src/barometertrend.h index 146eced..491ae65 100644 --- a/src/barometertrend.h +++ b/src/barometertrend.h @@ -30,10 +30,19 @@ public: m_timestamps.reserve(360 + 16); restoreHistory(); // Sauvegarde automatique toutes les 10 minutes - connect(&m_saveTimer, &QTimer::timeout, this, &BarometerTrend::saveHistory); - m_saveTimer.start(10 * 60 * 1000); + m_saveTimer = new QTimer(this); + connect(m_saveTimer, &QTimer::timeout, this, &BarometerTrend::saveHistory); + m_saveTimer->start(10 * 60 * 1000); + if (!m_saveTimer->isActive()) + { + debug(DEBUGMACRO, "Le timer n'est pas démarré", ERROR); + } } + ~BarometerTrend() + { + saveHistory(); + } void addPressure(double pressure_hPa) { debug(DEBUGMACRO, "adding pressure " + QByteArray::number(pressure_hPa), DEBUG); @@ -349,7 +358,7 @@ public: private: QVector m_values; QVector m_timestamps; - QTimer m_saveTimer; + QTimer *m_saveTimer; private slots: void saveHistory() diff --git a/src/main.cpp b/src/main.cpp index 482bf70..4a04fac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,7 @@ #include #include "pws2mqtt.h" #include "mqtt.h" +#include "src/barometertrend.h" #include "version.h" #include #include @@ -36,6 +37,7 @@ using namespace std; Pws2mqtt *pws2mqtt; MqttClient *mqttClient; QHttpServer *httpServer; +BarometerTrend *baro; int main(int argc, char *argv[]) { @@ -59,8 +61,12 @@ int main(int argc, char *argv[]) //declaration of debug level pws2mqtt = new Pws2mqtt; + baro = new BarometerTrend; pws2mqtt->listeningHttp(); + + + //notify (QString("Program started"), "default"); a.exec(); diff --git a/src/pws2mqtt.cpp b/src/pws2mqtt.cpp index e20e673..f6dc915 100644 --- a/src/pws2mqtt.cpp +++ b/src/pws2mqtt.cpp @@ -22,8 +22,8 @@ extern MqttClient *mqttClient; extern Pws2mqtt *pws2mqtt; extern QHttpServer *httpServer; +extern BarometerTrend *baro; UtciCalculator calc; -BarometerTrend baro; using namespace std; @@ -229,17 +229,18 @@ void Pws2mqtt::parseData(QList> queryList) debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - }else if (name == "windspeedmph" or name == "windgustmph") + }else if (name == "windspeedmph") { QString msg = ""; - static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600); + quint8 i; + static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600); quint8 windPriority = 1; propertiesValue["vent"] = round(mphTokmh(value.toFloat())); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["vent"]), DEBUG); - for (quint8 i=0; i> queryList) } } - if (propertyList["forcevent"] != msg or propertyList["rafales"] != msg) - { - if (name == "windspeedmph") - { - //propertyList["forcevent"] = msg; - propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertiesValue["vent"])); - }else - { - propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertiesValue["vent"])); - } - priority = setPriority(priority, windPriority); + propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertiesValue["vent"])); + propertiesValue["forcevent"] = i; + if (i >= 5) + { + attachment = this->outputPath; + } - attachment = this->outputPath; + if (propertiesValue["forcevent"] != i or propertiesValue["rafales"] != i) + { + priority = qMax(priority, windPriority); } debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); + }else if (name == "windgustmph") + { + QString msg = ""; + static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600); + + propertiesValue[name] = round(mphTokmh(value.toFloat())); + + debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["rafale"]), DEBUG); + + propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertiesValue[name])); + + if (propertiesValue["rafales"] > 50) + { + priority = qMax(priority, (quint8)4); + } + debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); }else if (name == "rainin") { static double ecart; @@ -312,12 +326,12 @@ void Pws2mqtt::parseData(QList> queryList) propertyValue = round(tohPa(pair.second.toFloat()) * 100) / 100; debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG); - baro.addPressure(propertyValue); + baro->addPressure(propertyValue); propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; static QString prevision; - auto ret = baro.forecast(propertiesValue["tempf"], propertiesValue["humidity"]); + auto ret = baro->forecast(propertiesValue["tempf"], propertiesValue["humidity"]); QString newPrevision = ret.message; if (prevision != newPrevision)