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 | warningActions.stopScheduler = Options::weatherAlertStopScheduler(); | ||||
32 | alertActions.parkDome = Options::weatherAlertCloseDome(); | ||||
33 | alertActions.closeShutter = Options::weatherAlertCloseShutter(); | ||||
34 | alertActions.stopScheduler = Options::weatherAlertStopScheduler(); | ||||
35 | alertActions.delay = Options::weatherAlertDelay(); | ||||
36 | | ||||
37 | warningTimer.setInterval(warningActions.delay * 1000); | ||||
38 | warningTimer.setSingleShot(true); | ||||
39 | alertTimer.setInterval(alertActions.delay * 1000); | ||||
40 | alertTimer.setSingleShot(true); | ||||
41 | | ||||
42 | connect(&warningTimer, &QTimer::timeout, [this]() { execute(warningActions); }); | ||||
43 | connect(&alertTimer, &QTimer::timeout, [this]() { execute(alertActions); }); | ||||
44 | | ||||
45 | if (mWeather->status() != ISD::Weather::WEATHER_IDLE) | ||||
46 | emit ready(); | ||||
47 | } | ||||
48 | | ||||
49 | ISD::Weather::Status ObservatoryWeatherModel::status() | ||||
50 | { | ||||
51 | if (mWeather == nullptr) | ||||
52 | return ISD::Weather::WEATHER_IDLE; | ||||
53 | | ||||
54 | return mWeather->status(); | ||||
55 | } | ||||
56 | | ||||
57 | void ObservatoryWeatherModel::setWarningActions(WeatherActions actions) { | ||||
58 | warningActions = actions; | ||||
59 | Options::setWeatherWarningCloseDome(actions.parkDome); | ||||
60 | Options::setWeatherWarningCloseShutter(actions.closeShutter); | ||||
61 | Options::setWeatherWarningDelay(actions.delay); | ||||
62 | warningTimer.setInterval(actions.delay * 1000); | ||||
63 | } | ||||
64 | | ||||
65 | | ||||
66 | QString ObservatoryWeatherModel::getWarningActionsStatus() | ||||
67 | { | ||||
68 | if (warningTimer.isActive()) | ||||
69 | { | ||||
70 | QString status; | ||||
71 | int remaining = warningTimer.remainingTime()/1000; | ||||
72 | return status.sprintf("%02ds remaining", remaining); | ||||
73 | } | ||||
74 | | ||||
75 | return "Status: inactive"; | ||||
76 | } | ||||
77 | | ||||
78 | void ObservatoryWeatherModel::setAlertActions(WeatherActions actions) { | ||||
79 | alertActions = actions; | ||||
80 | Options::setWeatherAlertCloseDome(actions.parkDome); | ||||
81 | Options::setWeatherAlertCloseShutter(actions.closeShutter); | ||||
82 | Options::setWeatherAlertDelay(actions.delay); | ||||
83 | alertTimer.setInterval(actions.delay * 1000); | ||||
84 | } | ||||
85 | | ||||
86 | QString ObservatoryWeatherModel::getAlertActionsStatus() | ||||
87 | { | ||||
88 | if (alertTimer.isActive()) | ||||
89 | { | ||||
90 | QString status; | ||||
91 | int remaining = alertTimer.remainingTime()/1000; | ||||
92 | return status.sprintf("%02ds remaining", remaining); | ||||
93 | } | ||||
94 | | ||||
95 | return "Status: inactive"; | ||||
96 | } | ||||
97 | | ||||
98 | void ObservatoryWeatherModel::updateWeatherStatus() | ||||
99 | { | ||||
100 | weatherChanged(status()); | ||||
101 | emit ready(); | ||||
102 | } | ||||
103 | | ||||
104 | | ||||
105 | void ObservatoryWeatherModel::weatherChanged(ISD::Weather::Status status) | ||||
106 | { | ||||
107 | switch (status) { | ||||
108 | case ISD::Weather::WEATHER_OK: | ||||
109 | warningTimer.stop(); | ||||
110 | alertTimer.stop(); | ||||
111 | break; | ||||
112 | case ISD::Weather::WEATHER_WARNING: | ||||
113 | warningTimer.start(); | ||||
114 | alertTimer.stop(); | ||||
115 | break; | ||||
116 | case ISD::Weather::WEATHER_ALERT: | ||||
117 | warningTimer.stop(); | ||||
118 | alertTimer.start(); | ||||
119 | break; | ||||
120 | default: | ||||
121 | break; | ||||
122 | } | ||||
123 | emit newStatus(status); | ||||
124 | } | ||||
125 | | ||||
126 | } // Ekos |