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