Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/observatory/observatoryweathermodel.cpp
Show All 25 Lines | 18 | { | |||
---|---|---|---|---|---|
26 | connect(weatherInterface, &Weather::newWeatherData, this, &ObservatoryWeatherModel::updateWeatherData); | 26 | connect(weatherInterface, &Weather::newWeatherData, this, &ObservatoryWeatherModel::updateWeatherData); | ||
27 | connect(weatherInterface, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); | 27 | connect(weatherInterface, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); | ||
28 | 28 | | |||
29 | // read the default values | 29 | // read the default values | ||
30 | warningActionsActive = Options::warningActionsActive(); | 30 | warningActionsActive = Options::warningActionsActive(); | ||
31 | warningActions.parkDome = Options::weatherWarningCloseDome(); | 31 | warningActions.parkDome = Options::weatherWarningCloseDome(); | ||
32 | warningActions.closeShutter = Options::weatherWarningCloseShutter(); | 32 | warningActions.closeShutter = Options::weatherWarningCloseShutter(); | ||
33 | warningActions.delay = Options::weatherWarningDelay(); | 33 | warningActions.delay = Options::weatherWarningDelay(); | ||
34 | warningActions.stopScheduler = Options::weatherAlertStopScheduler(); | | |||
35 | alertActionsActive = Options::alertActionsActive(); | 34 | alertActionsActive = Options::alertActionsActive(); | ||
36 | alertActions.parkDome = Options::weatherAlertCloseDome(); | 35 | alertActions.parkDome = Options::weatherAlertCloseDome(); | ||
37 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | 36 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | ||
38 | alertActions.stopScheduler = Options::weatherAlertStopScheduler(); | | |||
39 | alertActions.delay = Options::weatherAlertDelay(); | 37 | alertActions.delay = Options::weatherAlertDelay(); | ||
40 | 38 | | |||
39 | // not implemented yet | ||||
40 | warningActions.stopScheduler = false; | ||||
41 | alertActions.stopScheduler = false; | ||||
42 | | ||||
41 | warningTimer.setInterval(static_cast<int>(warningActions.delay * 1000)); | 43 | warningTimer.setInterval(static_cast<int>(warningActions.delay * 1000)); | ||
42 | warningTimer.setSingleShot(true); | 44 | warningTimer.setSingleShot(true); | ||
43 | alertTimer.setInterval(static_cast<int>(alertActions.delay * 1000)); | 45 | alertTimer.setInterval(static_cast<int>(alertActions.delay * 1000)); | ||
44 | alertTimer.setSingleShot(true); | 46 | alertTimer.setSingleShot(true); | ||
45 | 47 | | |||
46 | connect(&warningTimer, &QTimer::timeout, [this]() | 48 | connect(&warningTimer, &QTimer::timeout, [this]() | ||
47 | { | 49 | { | ||
48 | execute(warningActions); | 50 | execute(warningActions); | ||
Show All 19 Lines | |||||
68 | { | 70 | { | ||
69 | warningActionsActive = active; | 71 | warningActionsActive = active; | ||
70 | Options::setWarningActionsActive(active); | 72 | Options::setWarningActionsActive(active); | ||
71 | 73 | | |||
72 | // stop warning actions if deactivated | 74 | // stop warning actions if deactivated | ||
73 | if (!active && warningTimer.isActive()) | 75 | if (!active && warningTimer.isActive()) | ||
74 | warningTimer.stop(); | 76 | warningTimer.stop(); | ||
75 | // start warning timer if activated | 77 | // start warning timer if activated | ||
76 | else if (active && !warningTimer.isActive() && weatherInterface->status() == ISD::Weather::WEATHER_WARNING) | 78 | else if (weatherInterface->status() == ISD::Weather::WEATHER_WARNING) | ||
79 | startWarningTimer(); | ||||
80 | } | ||||
81 | | ||||
82 | void ObservatoryWeatherModel::startWarningTimer() | ||||
83 | { | ||||
84 | if (warningActionsActive && (warningActions.parkDome || warningActions.closeShutter || warningActions.stopScheduler)) | ||||
85 | { | ||||
86 | if (!warningTimer.isActive()) | ||||
77 | warningTimer.start(); | 87 | warningTimer.start(); | ||
78 | } | 88 | } | ||
89 | else if (warningTimer.isActive()) | ||||
90 | warningTimer.stop(); | ||||
91 | } | ||||
79 | 92 | | |||
80 | void ObservatoryWeatherModel::setAlertActionsActive(bool active) | 93 | void ObservatoryWeatherModel::setAlertActionsActive(bool active) | ||
81 | { | 94 | { | ||
82 | alertActionsActive = active; | 95 | alertActionsActive = active; | ||
83 | Options::setAlertActionsActive(active); | 96 | Options::setAlertActionsActive(active); | ||
84 | 97 | | |||
85 | // stop alert actions if deactivated | 98 | // stop alert actions if deactivated | ||
86 | if (!active && alertTimer.isActive()) | 99 | if (!active && alertTimer.isActive()) | ||
87 | alertTimer.stop(); | 100 | alertTimer.stop(); | ||
88 | // start alert timer if activated | 101 | // start alert timer if activated | ||
89 | else if (active && !alertTimer.isActive() && weatherInterface->status() == ISD::Weather::WEATHER_ALERT) | 102 | else if (weatherInterface->status() == ISD::Weather::WEATHER_ALERT) | ||
103 | startAlertTimer(); | ||||
104 | } | ||||
105 | | ||||
106 | void ObservatoryWeatherModel::startAlertTimer() | ||||
107 | { | ||||
108 | if (alertActionsActive && (alertActions.parkDome || alertActions.closeShutter || alertActions.stopScheduler)) | ||||
109 | { | ||||
110 | if (!alertTimer.isActive()) | ||||
90 | alertTimer.start(); | 111 | alertTimer.start(); | ||
91 | } | 112 | } | ||
113 | else if (alertTimer.isActive()) | ||||
114 | alertTimer.stop(); | ||||
115 | } | ||||
92 | 116 | | |||
93 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) | 117 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) | ||
94 | { | 118 | { | ||
95 | warningActions = actions; | 119 | warningActions = actions; | ||
96 | Options::setWeatherWarningCloseDome(actions.parkDome); | 120 | Options::setWeatherWarningCloseDome(actions.parkDome); | ||
97 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | 121 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | ||
98 | Options::setWeatherWarningDelay(actions.delay); | 122 | Options::setWeatherWarningDelay(actions.delay); | ||
123 | if (!warningTimer.isActive()) | ||||
99 | warningTimer.setInterval(static_cast<int>(actions.delay * 1000)); | 124 | warningTimer.setInterval(static_cast<int>(actions.delay * 1000)); | ||
125 | | ||||
126 | if (weatherInterface->status() == ISD::Weather::WEATHER_WARNING) | ||||
127 | startWarningTimer(); | ||||
100 | } | 128 | } | ||
101 | 129 | | |||
102 | 130 | | |||
103 | QString ObservatoryWeatherModel::getWarningActionsStatus() | 131 | QString ObservatoryWeatherModel::getWarningActionsStatus() | ||
104 | { | 132 | { | ||
105 | if (warningTimer.isActive()) | 133 | if (warningTimer.isActive()) | ||
106 | { | 134 | { | ||
107 | int remaining = warningTimer.remainingTime() / 1000; | 135 | int remaining = warningTimer.remainingTime() / 1000; | ||
108 | return i18np("%1 second remaining", "%1 seconds remaining", remaining); | 136 | return i18np("%1 second remaining", "%1 seconds remaining", remaining); | ||
109 | } | 137 | } | ||
110 | 138 | | |||
111 | return i18n("Status: inactive"); | 139 | return i18n("Status: inactive"); | ||
112 | } | 140 | } | ||
113 | 141 | | |||
114 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) | 142 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) | ||
115 | { | 143 | { | ||
116 | alertActions = actions; | 144 | alertActions = actions; | ||
117 | Options::setWeatherAlertCloseDome(actions.parkDome); | 145 | Options::setWeatherAlertCloseDome(actions.parkDome); | ||
118 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | 146 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | ||
119 | Options::setWeatherAlertDelay(actions.delay); | 147 | Options::setWeatherAlertDelay(actions.delay); | ||
148 | if (!alertTimer.isActive()) | ||||
120 | alertTimer.setInterval(static_cast<int>(actions.delay * 1000)); | 149 | alertTimer.setInterval(static_cast<int>(actions.delay * 1000)); | ||
150 | | ||||
151 | if (weatherInterface->status() == ISD::Weather::WEATHER_ALERT) | ||||
152 | startAlertTimer(); | ||||
121 | } | 153 | } | ||
122 | 154 | | |||
123 | QString ObservatoryWeatherModel::getAlertActionsStatus() | 155 | QString ObservatoryWeatherModel::getAlertActionsStatus() | ||
124 | { | 156 | { | ||
125 | if (alertTimer.isActive()) | 157 | if (alertTimer.isActive()) | ||
126 | { | 158 | { | ||
127 | int remaining = alertTimer.remainingTime() / 1000; | 159 | int remaining = alertTimer.remainingTime() / 1000; | ||
128 | return i18np("%1 second remaining", "%1 seconds remaining", remaining); | 160 | return i18np("%1 second remaining", "%1 seconds remaining", remaining); | ||
Show All 13 Lines | |||||
142 | { | 174 | { | ||
143 | switch (status) | 175 | switch (status) | ||
144 | { | 176 | { | ||
145 | case ISD::Weather::WEATHER_OK: | 177 | case ISD::Weather::WEATHER_OK: | ||
146 | warningTimer.stop(); | 178 | warningTimer.stop(); | ||
147 | alertTimer.stop(); | 179 | alertTimer.stop(); | ||
148 | break; | 180 | break; | ||
149 | case ISD::Weather::WEATHER_WARNING: | 181 | case ISD::Weather::WEATHER_WARNING: | ||
150 | if (warningActionsActive) | | |||
151 | warningTimer.start(); | | |||
152 | alertTimer.stop(); | 182 | alertTimer.stop(); | ||
183 | startWarningTimer(); | ||||
153 | break; | 184 | break; | ||
154 | case ISD::Weather::WEATHER_ALERT: | 185 | case ISD::Weather::WEATHER_ALERT: | ||
155 | warningTimer.stop(); | 186 | warningTimer.stop(); | ||
156 | if (alertActionsActive) | 187 | startAlertTimer(); | ||
157 | alertTimer.start(); | | |||
158 | break; | 188 | break; | ||
159 | default: | 189 | default: | ||
160 | break; | 190 | break; | ||
161 | } | 191 | } | ||
162 | emit newStatus(status); | 192 | emit newStatus(status); | ||
163 | } | 193 | } | ||
164 | 194 | | |||
165 | void ObservatoryWeatherModel::updateWeatherData(std::vector<ISD::Weather::WeatherData> entries) | 195 | void ObservatoryWeatherModel::updateWeatherData(std::vector<ISD::Weather::WeatherData> entries) | ||
Show All 28 Lines |