Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/observatory/observatoryweathermodel.cpp
- This file was added.
1 | /* Ekos Observatory Module | ||||
---|---|---|---|---|---|
2 | Copyright (C) Wolfgang Reissenberger <sterne-jaeger@t-online.de> | ||||
3 | | ||||
4 | This application is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | */ | ||||
9 | | ||||
10 | #include "observatoryweathermodel.h" | ||||
11 | #include "Options.h" | ||||
12 | | ||||
13 | namespace Ekos | ||||
14 | { | ||||
15 | | ||||
16 | void ObservatoryWeatherModel::initModel(Weather *weather) | ||||
17 | { | ||||
18 | mWeather = weather; | ||||
19 | | ||||
20 | // ensure that we start the timers if required | ||||
21 | weatherChanged(status()); | ||||
22 | | ||||
23 | connect(mWeather, &Weather::ready, this, &ObservatoryWeatherModel::updateWeatherStatus); | ||||
24 | connect(mWeather, &Weather::newStatus, this, &ObservatoryWeatherModel::weatherChanged); | ||||
25 | connect(mWeather, &Weather::disconnected, this, &ObservatoryWeatherModel::disconnected); | ||||
26 | | ||||
27 | // read the default values | ||||
28 | warningActions.parkDome = Options::weatherWarningCloseDome(); | ||||
29 | warningActions.closeShutter = Options::weatherWarningCloseShutter(); | ||||
30 | warningActions.delay = Options::weatherWarningDelay(); | ||||
31 | alertActions.parkDome = Options::weatherAlertCloseDome(); | ||||
32 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | ||||
33 | alertActions.delay = Options::weatherAlertDelay(); | ||||
34 | | ||||
35 | warningTimer.setInterval(warningActions.delay * 60 * 1000); | ||||
36 | warningTimer.setSingleShot(true); | ||||
37 | alertTimer.setInterval(alertActions.delay * 60 * 1000); | ||||
38 | alertTimer.setSingleShot(true); | ||||
39 | | ||||
40 | connect(&warningTimer, &QTimer::timeout, [this]() { execute(warningActions); }); | ||||
41 | connect(&alertTimer, &QTimer::timeout, [this]() { execute(alertActions); }); | ||||
42 | | ||||
43 | if (mWeather->status() != ISD::Weather::WEATHER_IDLE) | ||||
44 | emit ready(); | ||||
45 | } | ||||
46 | | ||||
47 | ISD::Weather::Status ObservatoryWeatherModel::status() | ||||
48 | { | ||||
49 | if (mWeather == nullptr) | ||||
50 | return ISD::Weather::WEATHER_IDLE; | ||||
51 | | ||||
52 | return mWeather->status(); | ||||
53 | } | ||||
54 | | ||||
55 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) { | ||||
56 | warningActions = actions; | ||||
57 | Options::setWeatherWarningCloseDome(actions.parkDome); | ||||
58 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | ||||
59 | Options::setWeatherWarningDelay(actions.delay); | ||||
60 | warningTimer.setInterval(actions.delay * 60 * 1000); | ||||
61 | } | ||||
62 | | ||||
63 | | ||||
64 | QString ObservatoryWeatherModel::getWarningActionsStatus() | ||||
65 | { | ||||
66 | if (warningTimer.isActive()) | ||||
67 | { | ||||
68 | QString status; | ||||
69 | int remaining = warningTimer.remainingTime()/1000; | ||||
70 | return status.sprintf("%02d:%02d remaining", remaining/60, remaining%60); | ||||
71 | } | ||||
72 | | ||||
73 | return "Status: inactive"; | ||||
74 | } | ||||
75 | | ||||
76 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) { | ||||
77 | alertActions = actions; | ||||
78 | Options::setWeatherAlertCloseDome(actions.parkDome); | ||||
79 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | ||||
80 | Options::setWeatherAlertDelay(actions.delay); | ||||
81 | alertTimer.setInterval(actions.delay * 60 * 1000); | ||||
82 | } | ||||
83 | | ||||
84 | QString ObservatoryWeatherModel::getAlertActionsStatus() | ||||
85 | { | ||||
86 | if (alertTimer.isActive()) | ||||
87 | { | ||||
88 | QString status; | ||||
89 | int remaining = alertTimer.remainingTime()/1000; | ||||
90 | return status.sprintf("%02d:%02d remaining", remaining/60, remaining%60); | ||||
91 | } | ||||
92 | | ||||
93 | return "Status: inactive"; | ||||
94 | } | ||||
95 | | ||||
96 | void ObservatoryWeatherModel::updateWeatherStatus() | ||||
97 | { | ||||
98 | weatherChanged(status()); | ||||
99 | emit ready(); | ||||
100 | } | ||||
101 | | ||||
102 | | ||||
103 | void ObservatoryWeatherModel::weatherChanged(ISD::Weather::Status status) | ||||
104 | { | ||||
105 | switch (status) { | ||||
106 | case ISD::Weather::WEATHER_OK: | ||||
107 | warningTimer.stop(); | ||||
108 | alertTimer.stop(); | ||||
109 | break; | ||||
110 | case ISD::Weather::WEATHER_WARNING: | ||||
111 | warningTimer.start(); | ||||
112 | alertTimer.stop(); | ||||
113 | break; | ||||
114 | case ISD::Weather::WEATHER_ALERT: | ||||
115 | warningTimer.stop(); | ||||
116 | alertTimer.start(); | ||||
117 | break; | ||||
118 | default: | ||||
119 | break; | ||||
120 | } | ||||
121 | emit newStatus(status); | ||||
122 | } | ||||
123 | | ||||
124 | } // Ekos |