Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/observatory/observatoryweathermodel.cpp
Show All 17 Lines | |||||
18 | { | 18 | { | ||
19 | weatherInterface = weather; | 19 | weatherInterface = weather; | ||
20 | 20 | | |||
21 | // ensure that we start the timers if required | 21 | // ensure that we start the timers if required | ||
22 | weatherChanged(status()); | 22 | weatherChanged(status()); | ||
23 | 23 | | |||
24 | connect(weatherInterface, &Weather::ready, this, &ObservatoryWeatherModel::updateWeatherStatus); | 24 | connect(weatherInterface, &Weather::ready, this, &ObservatoryWeatherModel::updateWeatherStatus); | ||
25 | connect(weatherInterface, &Weather::newStatus, this, &ObservatoryWeatherModel::weatherChanged); | 25 | connect(weatherInterface, &Weather::newStatus, this, &ObservatoryWeatherModel::weatherChanged); | ||
26 | connect(weatherInterface, &Weather::newWeatherData, this, &ObservatoryWeatherModel::updateWeatherData); | ||||
26 | connect(weatherInterface, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); | 27 | connect(weatherInterface, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); | ||
27 | 28 | | |||
28 | // read the default values | 29 | // read the default values | ||
29 | warningActionsActive = Options::warningActionsActive(); | 30 | warningActionsActive = Options::warningActionsActive(); | ||
30 | warningActions.parkDome = Options::weatherWarningCloseDome(); | 31 | warningActions.parkDome = Options::weatherWarningCloseDome(); | ||
31 | warningActions.closeShutter = Options::weatherWarningCloseShutter(); | 32 | warningActions.closeShutter = Options::weatherWarningCloseShutter(); | ||
32 | warningActions.delay = Options::weatherWarningDelay(); | 33 | warningActions.delay = Options::weatherWarningDelay(); | ||
33 | warningActions.stopScheduler = Options::weatherAlertStopScheduler(); | 34 | warningActions.stopScheduler = Options::weatherAlertStopScheduler(); | ||
34 | alertActionsActive = Options::alertActionsActive(); | 35 | alertActionsActive = Options::alertActionsActive(); | ||
35 | alertActions.parkDome = Options::weatherAlertCloseDome(); | 36 | alertActions.parkDome = Options::weatherAlertCloseDome(); | ||
36 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | 37 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | ||
37 | alertActions.stopScheduler = Options::weatherAlertStopScheduler(); | 38 | alertActions.stopScheduler = Options::weatherAlertStopScheduler(); | ||
38 | alertActions.delay = Options::weatherAlertDelay(); | 39 | alertActions.delay = Options::weatherAlertDelay(); | ||
39 | 40 | | |||
40 | warningTimer.setInterval(warningActions.delay * 1000); | 41 | warningTimer.setInterval(static_cast<int>(warningActions.delay * 1000)); | ||
41 | warningTimer.setSingleShot(true); | 42 | warningTimer.setSingleShot(true); | ||
42 | alertTimer.setInterval(alertActions.delay * 1000); | 43 | alertTimer.setInterval(static_cast<int>(alertActions.delay * 1000)); | ||
43 | alertTimer.setSingleShot(true); | 44 | alertTimer.setSingleShot(true); | ||
44 | 45 | | |||
45 | connect(&warningTimer, &QTimer::timeout, [this]() | 46 | connect(&warningTimer, &QTimer::timeout, [this]() | ||
46 | { | 47 | { | ||
47 | execute(warningActions); | 48 | execute(warningActions); | ||
48 | }); | 49 | }); | ||
49 | connect(&alertTimer, &QTimer::timeout, [this]() | 50 | connect(&alertTimer, &QTimer::timeout, [this]() | ||
50 | { | 51 | { | ||
Show All 39 Lines | |||||
90 | } | 91 | } | ||
91 | 92 | | |||
92 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) | 93 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) | ||
93 | { | 94 | { | ||
94 | warningActions = actions; | 95 | warningActions = actions; | ||
95 | Options::setWeatherWarningCloseDome(actions.parkDome); | 96 | Options::setWeatherWarningCloseDome(actions.parkDome); | ||
96 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | 97 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | ||
97 | Options::setWeatherWarningDelay(actions.delay); | 98 | Options::setWeatherWarningDelay(actions.delay); | ||
98 | warningTimer.setInterval(actions.delay * 1000); | 99 | warningTimer.setInterval(static_cast<int>(actions.delay * 1000)); | ||
99 | } | 100 | } | ||
100 | 101 | | |||
101 | 102 | | |||
102 | QString ObservatoryWeatherModel::getWarningActionsStatus() | 103 | QString ObservatoryWeatherModel::getWarningActionsStatus() | ||
103 | { | 104 | { | ||
104 | if (warningTimer.isActive()) | 105 | if (warningTimer.isActive()) | ||
105 | { | 106 | { | ||
106 | int remaining = warningTimer.remainingTime() / 1000; | 107 | int remaining = warningTimer.remainingTime() / 1000; | ||
107 | return i18np("%1 second remaining", "%1 seconds remaining", QString::number(remaining)); | 108 | return i18np("%1 second remaining", "%1 seconds remaining", QString::number(remaining)); | ||
108 | } | 109 | } | ||
109 | 110 | | |||
110 | return i18n("Status: inactive"); | 111 | return i18n("Status: inactive"); | ||
111 | } | 112 | } | ||
112 | 113 | | |||
113 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) | 114 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) | ||
114 | { | 115 | { | ||
115 | alertActions = actions; | 116 | alertActions = actions; | ||
116 | Options::setWeatherAlertCloseDome(actions.parkDome); | 117 | Options::setWeatherAlertCloseDome(actions.parkDome); | ||
117 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | 118 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | ||
118 | Options::setWeatherAlertDelay(actions.delay); | 119 | Options::setWeatherAlertDelay(actions.delay); | ||
119 | alertTimer.setInterval(actions.delay * 1000); | 120 | alertTimer.setInterval(static_cast<int>(actions.delay * 1000)); | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | QString ObservatoryWeatherModel::getAlertActionsStatus() | 123 | QString ObservatoryWeatherModel::getAlertActionsStatus() | ||
123 | { | 124 | { | ||
124 | if (alertTimer.isActive()) | 125 | if (alertTimer.isActive()) | ||
125 | { | 126 | { | ||
126 | int remaining = alertTimer.remainingTime() / 1000; | 127 | int remaining = alertTimer.remainingTime() / 1000; | ||
127 | return i18np("%1 second remaining", "%1 seconds remaining", QString::number(remaining)); | 128 | return i18np("%1 second remaining", "%1 seconds remaining", QString::number(remaining)); | ||
Show All 28 Lines | 156 | if (alertActionsActive) | |||
156 | alertTimer.start(); | 157 | alertTimer.start(); | ||
157 | break; | 158 | break; | ||
158 | default: | 159 | default: | ||
159 | break; | 160 | break; | ||
160 | } | 161 | } | ||
161 | emit newStatus(status); | 162 | emit newStatus(status); | ||
162 | } | 163 | } | ||
163 | 164 | | |||
165 | void ObservatoryWeatherModel::updateWeatherData(std::vector<ISD::Weather::WeatherData> entries) | ||||
166 | { | ||||
167 | // add or update all received values | ||||
168 | for (std::vector<ISD::Weather::WeatherData>::iterator entry = entries.begin(); entry != entries.end(); ++entry) | ||||
169 | { | ||||
170 | // update if already existing | ||||
171 | unsigned long pos = findWeatherData(entry->name); | ||||
172 | if (pos < m_WeatherData.size()) | ||||
173 | m_WeatherData[pos].value = entry->value; | ||||
174 | // new weather sensor? | ||||
175 | else if (entry->name.startsWith("WEATHER_")) | ||||
176 | m_WeatherData.push_back({QString(entry->name), QString(entry->label), entry->value}); | ||||
177 | } | ||||
178 | // update UI | ||||
179 | emit newStatus(status()); | ||||
180 | } | ||||
181 | | ||||
182 | unsigned long ObservatoryWeatherModel::findWeatherData(const QString name) | ||||
183 | { | ||||
184 | unsigned long i; | ||||
185 | for (i = 0; i < m_WeatherData.size(); i++) | ||||
186 | { | ||||
187 | if (m_WeatherData[i].name.compare(name) == 0) | ||||
188 | return i; | ||||
189 | } | ||||
190 | // none found | ||||
191 | return i; | ||||
192 | } | ||||
164 | } // Ekos | 193 | } // Ekos |