diff --git a/kstars/ekos/auxiliary/weather.h b/kstars/ekos/auxiliary/weather.h --- a/kstars/ekos/auxiliary/weather.h +++ b/kstars/ekos/auxiliary/weather.h @@ -71,6 +71,7 @@ * @param status IPS_OK --> Good, IPS_BUSY --> Warning, IPS_ALERT --> Alert */ void newStatus(ISD::Weather::Status status); + void newWeatherData(std::vector); void ready(); // Signal when the underlying ISD::Weather signals a Disconnected() void disconnected(); diff --git a/kstars/ekos/auxiliary/weather.cpp b/kstars/ekos/auxiliary/weather.cpp --- a/kstars/ekos/auxiliary/weather.cpp +++ b/kstars/ekos/auxiliary/weather.cpp @@ -34,6 +34,7 @@ currentWeather = static_cast(newWeather); currentWeather->disconnect(this); connect(currentWeather, &ISD::Weather::newStatus, this, &Weather::newStatus); + connect(currentWeather, &ISD::Weather::newWeatherData, this, &Weather::newWeatherData); connect(currentWeather, &ISD::Weather::ready, this, &Weather::ready); connect(currentWeather, &ISD::Weather::Connected, this, &Weather::ready); connect(currentWeather, &ISD::Weather::Disconnected, this, &Weather::disconnected); diff --git a/kstars/ekos/observatory/observatory.h b/kstars/ekos/observatory/observatory.h --- a/kstars/ekos/observatory/observatory.h +++ b/kstars/ekos/observatory/observatory.h @@ -15,6 +15,7 @@ #include "observatoryweathermodel.h" #include +#include #include namespace Ekos @@ -86,6 +87,11 @@ void activateButton(QPushButton *button, QString title); void buttonPressed(QPushButton *button, QString title); + // weather sensor data + QFormLayout* sensorDataBoxLayout; + QList*> sensorDataWidgets; + + private slots: // observatory status handling void setObseratoryStatusControl(ObservatoryStatusControl control); diff --git a/kstars/ekos/observatory/observatory.cpp b/kstars/ekos/observatory/observatory.cpp --- a/kstars/ekos/observatory/observatory.cpp +++ b/kstars/ekos/observatory/observatory.cpp @@ -36,6 +36,9 @@ // make invisible, since not implemented yet weatherWarningSchedulerCB->setVisible(false); weatherAlertSchedulerCB->setVisible(false); + // initialize the weather sensor data group box + sensorDataBoxLayout = new QFormLayout(); + sensorDataBox->setLayout(sensorDataBoxLayout); } void Observatory::setObseratoryStatusControl(ObservatoryStatusControl control) @@ -509,15 +512,42 @@ } weatherStatusLabel->setPixmap(QIcon::fromTheme(label.c_str()).pixmap(QSize(48, 48))); + + std::vector weatherData = getWeatherModel()->getWeatherData(); + + // update weather sensor data + int row_nr = 0; + std::vector::iterator it; + for (it=weatherData.begin(); it != weatherData.end(); ++it) + { + if (sensorDataBoxLayout->rowCount() > row_nr) + { + sensorDataWidgets.value(row_nr)->first->setText(QString(it->label)); + sensorDataWidgets.value(row_nr)->second->setText(QString().setNum(it->value, 'f', 2)); + } + else + { + QLabel* labelWidget = new QLabel(it->label); + QLineEdit* valueWidget = new QLineEdit(QString().setNum(it->value, 'f', 2)); + valueWidget->setReadOnly(false); + valueWidget->setAlignment(Qt::AlignRight); + + sensorDataWidgets.append(new QPair(labelWidget, valueWidget)); + + sensorDataBoxLayout->addRow(labelWidget, valueWidget); + } + row_nr++; + } + } void Observatory::weatherWarningSettingsChanged() { struct WeatherActions actions; actions.parkDome = weatherWarningDomeCB->isChecked(); actions.closeShutter = weatherWarningShutterCB->isChecked(); - actions.delay = weatherWarningDelaySB->value(); + actions.delay = static_cast(weatherWarningDelaySB->value()); getWeatherModel()->setWarningActions(actions); } @@ -527,7 +557,7 @@ struct WeatherActions actions; actions.parkDome = weatherAlertDomeCB->isChecked(); actions.closeShutter = weatherAlertShutterCB->isChecked(); - actions.delay = weatherAlertDelaySB->value(); + actions.delay = static_cast(weatherAlertDelaySB->value()); getWeatherModel()->setAlertActions(actions); } @@ -549,15 +579,15 @@ { weatherWarningDomeCB->setChecked(actions.parkDome); weatherWarningShutterCB->setChecked(actions.closeShutter); - weatherWarningDelaySB->setValue(actions.delay); + weatherWarningDelaySB->setValue(static_cast(actions.delay)); } void Observatory::setAlertActions(WeatherActions actions) { weatherAlertDomeCB->setChecked(actions.parkDome); weatherAlertShutterCB->setChecked(actions.closeShutter); - weatherAlertDelaySB->setValue(actions.delay); + weatherAlertDelaySB->setValue(static_cast(actions.delay)); } void Observatory::toggleButtons(QPushButton *buttonPressed, QString titlePressed, QPushButton *buttonCounterpart, QString titleCounterpart) diff --git a/kstars/ekos/observatory/observatory.ui b/kstars/ekos/observatory/observatory.ui --- a/kstars/ekos/observatory/observatory.ui +++ b/kstars/ekos/observatory/observatory.ui @@ -802,7 +802,45 @@ 3 - + + + + + 0 + 0 + + + + + 48 + 48 + + + + + 48 + 48 + + + + + + + + + + + false + + + Display the weather status. The warning and alert limits are set in the INDI tab. + + + Weather Status: + + + + false @@ -899,7 +937,7 @@ - Delay (se&c): + Delay (sec): @@ -991,7 +1029,7 @@ - De&lay (sec): + Delay (sec): @@ -1014,31 +1052,6 @@ - - - - 0 - 0 - - - - - 48 - 48 - - - - - 48 - 48 - - - - - - - - Qt::Horizontal @@ -1051,16 +1064,10 @@ - - - - false - - - Display the weather status. The warning and alert limits are set in the INDI tab. - - - Weather Status: + + + + Sensor Data diff --git a/kstars/ekos/observatory/observatoryweathermodel.h b/kstars/ekos/observatory/observatoryweathermodel.h --- a/kstars/ekos/observatory/observatoryweathermodel.h +++ b/kstars/ekos/observatory/observatoryweathermodel.h @@ -19,7 +19,7 @@ struct WeatherActions { bool parkDome, closeShutter, stopScheduler; - int delay; + uint delay; }; class ObservatoryWeatherModel : public QObject @@ -61,6 +61,12 @@ return alertActionsActive; } + /** + * @brief Retrieve the currently known weather sensor values + */ + std::vector getWeatherData() { return m_WeatherData; } + + public slots: /** * @brief Activate or deactivate the weather warning actions @@ -77,6 +83,12 @@ struct WeatherActions warningActions, alertActions; bool warningActionsActive, alertActionsActive; + // hold all sensor data received from the weather station + std::vector m_WeatherData; + // update the stored values + void updateWeatherData(std::vector entries); + unsigned long findWeatherData(QString name); + private slots: void weatherChanged(ISD::Weather::Status status); void updateWeatherStatus(); diff --git a/kstars/ekos/observatory/observatoryweathermodel.cpp b/kstars/ekos/observatory/observatoryweathermodel.cpp --- a/kstars/ekos/observatory/observatoryweathermodel.cpp +++ b/kstars/ekos/observatory/observatoryweathermodel.cpp @@ -23,6 +23,7 @@ connect(weatherInterface, &Weather::ready, this, &ObservatoryWeatherModel::updateWeatherStatus); connect(weatherInterface, &Weather::newStatus, this, &ObservatoryWeatherModel::weatherChanged); + connect(weatherInterface, &Weather::newWeatherData, this, &ObservatoryWeatherModel::updateWeatherData); connect(weatherInterface, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); // read the default values @@ -37,9 +38,9 @@ alertActions.stopScheduler = Options::weatherAlertStopScheduler(); alertActions.delay = Options::weatherAlertDelay(); - warningTimer.setInterval(warningActions.delay * 1000); + warningTimer.setInterval(static_cast(warningActions.delay * 1000)); warningTimer.setSingleShot(true); - alertTimer.setInterval(alertActions.delay * 1000); + alertTimer.setInterval(static_cast(alertActions.delay * 1000)); alertTimer.setSingleShot(true); connect(&warningTimer, &QTimer::timeout, [this]() @@ -95,7 +96,7 @@ Options::setWeatherWarningCloseDome(actions.parkDome); Options::setWeatherWarningCloseShutter(actions.closeShutter); Options::setWeatherWarningDelay(actions.delay); - warningTimer.setInterval(actions.delay * 1000); + warningTimer.setInterval(static_cast(actions.delay * 1000)); } @@ -116,7 +117,7 @@ Options::setWeatherAlertCloseDome(actions.parkDome); Options::setWeatherAlertCloseShutter(actions.closeShutter); Options::setWeatherAlertDelay(actions.delay); - alertTimer.setInterval(actions.delay * 1000); + alertTimer.setInterval(static_cast(actions.delay * 1000)); } QString ObservatoryWeatherModel::getAlertActionsStatus() @@ -161,4 +162,32 @@ emit newStatus(status); } +void ObservatoryWeatherModel::updateWeatherData(std::vector entries) +{ + // add or update all received values + for (std::vector::iterator entry = entries.begin(); entry != entries.end(); ++entry) + { + // update if already existing + unsigned long pos = findWeatherData(entry->name); + if (pos < m_WeatherData.size()) + m_WeatherData[pos].value = entry->value; + // new weather sensor? + else if (entry->name.startsWith("WEATHER_")) + m_WeatherData.push_back({QString(entry->name), QString(entry->label), entry->value}); + } + // update UI + emit newStatus(status()); +} + +unsigned long ObservatoryWeatherModel::findWeatherData(const QString name) +{ + unsigned long i; + for (i = 0; i < m_WeatherData.size(); i++) + { + if (m_WeatherData[i].name.compare(name) == 0) + return i; + } + // none found + return i; +} } // Ekos diff --git a/kstars/indi/indiweather.h b/kstars/indi/indiweather.h --- a/kstars/indi/indiweather.h +++ b/kstars/indi/indiweather.h @@ -37,6 +37,8 @@ WEATHER_ALERT, } Status; + typedef struct { QString name; QString label; double value; } WeatherData; + void registerProperty(INDI::Property *prop) override; void processSwitch(ISwitchVectorProperty *svp) override; void processText(ITextVectorProperty *tvp) override; @@ -53,6 +55,7 @@ signals: void newStatus(Status status); + void newWeatherData(std::vector); void ready(); private: diff --git a/kstars/indi/indiweather.cpp b/kstars/indi/indiweather.cpp --- a/kstars/indi/indiweather.cpp +++ b/kstars/indi/indiweather.cpp @@ -49,6 +49,19 @@ void Weather::processNumber(INumberVectorProperty *nvp) { + if (nvp == nullptr) + return; + std::vector entries; + + // read all sensor values recieved + for (int i = 0; i < nvp->nnp; i++) + { + INumber number = nvp->np[i]; + entries.push_back({QString(number.name), QString(number.label), number.value}); + } + emit newWeatherData(entries); + + // and now continue with the standard behavior DeviceDecorator::processNumber(nvp); }