1 | /*
|
---|
2 | LX200 Autostar
|
---|
3 | Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
|
---|
4 |
|
---|
5 | This library is free software; you can redistribute it and/or
|
---|
6 | modify it under the terms of the GNU Lesser General Public
|
---|
7 | License as published by the Free Software Foundation; either
|
---|
8 | version 2.1 of the License, or (at your option) any later version.
|
---|
9 |
|
---|
10 | This library is distributed in the hope that it will be useful,
|
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | Lesser General Public License for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU Lesser General Public
|
---|
16 | License along with this library; if not, write to the Free Software
|
---|
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
18 |
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "lx200autostar.h"
|
---|
22 | #include "lx200driver.h"
|
---|
23 |
|
---|
24 | #include <stdio.h>
|
---|
25 | #include <stdlib.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <unistd.h>
|
---|
28 |
|
---|
29 | #define BASIC_GROUP "Main Control"
|
---|
30 | #define FIRMWARE_GROUP "Firmware data"
|
---|
31 | #define FOCUS_GROUP "Focus Control"
|
---|
32 |
|
---|
33 |
|
---|
34 | extern LX200Generic *telescope;
|
---|
35 | extern int MaxReticleFlashRate;
|
---|
36 | extern ITextVectorProperty TimeTP;
|
---|
37 | extern INumberVectorProperty SDTimeNP;
|
---|
38 | extern INumberVectorProperty EquatorialCoordsWNP;
|
---|
39 | extern INumberVectorProperty EquatorialCoordsRNP;
|
---|
40 | extern INumberVectorProperty FocusTimerNP;
|
---|
41 | extern ISwitchVectorProperty ConnectSP;
|
---|
42 | extern ISwitchVectorProperty FocusMotionSP;
|
---|
43 | extern ISwitchVectorProperty AbortSlewSP;
|
---|
44 | extern ISwitchVectorProperty MovementNSSP;
|
---|
45 | extern ISwitchVectorProperty MovementWESP;
|
---|
46 |
|
---|
47 |
|
---|
48 | static IText VersionT[] ={{ "Date", "", 0, 0, 0, 0} ,
|
---|
49 | { "Time", "", 0, 0, 0, 0} ,
|
---|
50 | { "Number", "", 0, 0, 0 ,0} ,
|
---|
51 | { "Full", "", 0, 0, 0, 0} ,
|
---|
52 | { "Name", "" ,0 ,0 ,0 ,0}};
|
---|
53 |
|
---|
54 | static ITextVectorProperty VersionInfo = {mydev, "Firmware Info", "", FIRMWARE_GROUP, IP_RO, 0, IPS_IDLE, VersionT, NARRAY(VersionT), "" ,0};
|
---|
55 |
|
---|
56 | // Focus Control
|
---|
57 | static INumber FocusSpeedN[] = {{"SPEED", "Speed", "%0.f", 0.0, 4.0, 1.0, 0.0, 0, 0, 0}};
|
---|
58 | static INumberVectorProperty FocusSpeedNP = {mydev, "FOCUS_SPEED", "Speed", FOCUS_GROUP, IP_RW, 0, IPS_IDLE, FocusSpeedN, NARRAY(FocusSpeedN), "", 0};
|
---|
59 |
|
---|
60 | /********************************************
|
---|
61 | Property: Park telescope to HOME
|
---|
62 | *********************************************/
|
---|
63 | static ISwitch ParkS[] = { {"PARK", "Park", ISS_OFF, 0, 0} };
|
---|
64 | ISwitchVectorProperty ParkSP = {mydev, "TELESCOPE_PARK", "Park Scope", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE, ParkS, NARRAY(ParkS), "", 0 };
|
---|
65 |
|
---|
66 |
|
---|
67 | void changeLX200AutostarDeviceName(const char *newName)
|
---|
68 | {
|
---|
69 | strcpy(VersionInfo.device, newName);
|
---|
70 | strcpy(FocusSpeedNP.device, newName);
|
---|
71 | strcpy(ParkSP.device, newName);
|
---|
72 | }
|
---|
73 |
|
---|
74 | LX200Autostar::LX200Autostar() : LX200Generic()
|
---|
75 | {
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | void LX200Autostar::ISGetProperties (const char *dev)
|
---|
80 | {
|
---|
81 |
|
---|
82 | if (dev && strcmp (thisDevice, dev))
|
---|
83 | return;
|
---|
84 |
|
---|
85 | LX200Generic::ISGetProperties(dev);
|
---|
86 |
|
---|
87 | IDDefSwitch (&ParkSP, NULL);
|
---|
88 | IDDefText (&VersionInfo, NULL);
|
---|
89 | IDDefNumber (&FocusSpeedNP, NULL);
|
---|
90 |
|
---|
91 | // For Autostar, we have a different focus speed method
|
---|
92 | // Therefore, we don't need the classical one
|
---|
93 | IDDelete(thisDevice, "FOCUS_MODE", NULL);
|
---|
94 |
|
---|
95 | }
|
---|
96 |
|
---|
97 | void LX200Autostar::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
|
---|
98 | {
|
---|
99 | // ignore if not ours //
|
---|
100 | if (strcmp (dev, thisDevice))
|
---|
101 | return;
|
---|
102 |
|
---|
103 | // suppress warning
|
---|
104 | n=n;
|
---|
105 |
|
---|
106 | LX200Generic::ISNewText (dev, name, texts, names, n);
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | void LX200Autostar::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
|
---|
112 | {
|
---|
113 | // ignore if not ours
|
---|
114 | if (strcmp (dev, thisDevice))
|
---|
115 | return;
|
---|
116 |
|
---|
117 | // Focus speed
|
---|
118 | if (!strcmp (name, FocusSpeedNP.name))
|
---|
119 | {
|
---|
120 | if (checkPower(&FocusSpeedNP))
|
---|
121 | return;
|
---|
122 |
|
---|
123 | if (IUUpdateNumber(&FocusSpeedNP, values, names, n) < 0)
|
---|
124 | return;
|
---|
125 |
|
---|
126 | setGPSFocuserSpeed(fd, ( (int) FocusSpeedN[0].value));
|
---|
127 | FocusSpeedNP.s = IPS_OK;
|
---|
128 | IDSetNumber(&FocusSpeedNP, NULL);
|
---|
129 | return;
|
---|
130 | }
|
---|
131 |
|
---|
132 | LX200Generic::ISNewNumber (dev, name, values, names, n);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void LX200Autostar::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
|
---|
136 | {
|
---|
137 | int index=0, err=0;
|
---|
138 |
|
---|
139 | if (!strcmp(name, ParkSP.name))
|
---|
140 | {
|
---|
141 | if (checkPower(&ParkSP))
|
---|
142 | return;
|
---|
143 |
|
---|
144 | if (EquatorialCoordsWNP.s == IPS_BUSY)
|
---|
145 | {
|
---|
146 | if (abortSlew(fd) < 0)
|
---|
147 | {
|
---|
148 | AbortSlewSP.s = IPS_ALERT;
|
---|
149 | IDSetSwitch(&AbortSlewSP, NULL);
|
---|
150 | slewError(err);
|
---|
151 | return;
|
---|
152 | }
|
---|
153 |
|
---|
154 | AbortSlewSP.s = IPS_OK;
|
---|
155 | EquatorialCoordsWNP.s = IPS_IDLE;
|
---|
156 | IDSetSwitch(&AbortSlewSP, "Slew aborted.");
|
---|
157 | IDSetNumber(&EquatorialCoordsWNP, NULL);
|
---|
158 |
|
---|
159 | if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)
|
---|
160 | {
|
---|
161 | MovementNSSP.s = MovementWESP.s = IPS_IDLE;
|
---|
162 | EquatorialCoordsWNP.s = IPS_IDLE;
|
---|
163 | IUResetSwitch(&MovementNSSP);
|
---|
164 | IUResetSwitch(&MovementWESP);
|
---|
165 | IUResetSwitch(&AbortSlewSP);
|
---|
166 |
|
---|
167 | IDSetSwitch(&MovementNSSP, NULL);
|
---|
168 | IDSetSwitch(&MovementWESP, NULL);
|
---|
169 | }
|
---|
170 |
|
---|
171 | // sleep for 200 mseconds
|
---|
172 | usleep(200000);
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (slewToPark(fd) < 0)
|
---|
176 | {
|
---|
177 | ParkSP.s = IPS_ALERT;
|
---|
178 | IDSetSwitch(&ParkSP, "Parking Failed.");
|
---|
179 | return;
|
---|
180 | }
|
---|
181 |
|
---|
182 | ParkSP.s = IPS_OK;
|
---|
183 | ConnectSP.s = IPS_IDLE;
|
---|
184 | ConnectSP.sp[0].s = ISS_OFF;
|
---|
185 | ConnectSP.sp[1].s = ISS_ON;
|
---|
186 | tty_disconnect(fd);
|
---|
187 | IDSetSwitch(&ParkSP, "The telescope is slewing to park position. Turn off the telescope after park is complete. Disconnecting...");
|
---|
188 | IDSetSwitch(&ConnectSP, NULL);
|
---|
189 | return;
|
---|
190 | }
|
---|
191 |
|
---|
192 | // Focus Motion
|
---|
193 | if (!strcmp (name, FocusMotionSP.name))
|
---|
194 | {
|
---|
195 | if (checkPower(&FocusMotionSP))
|
---|
196 | return;
|
---|
197 |
|
---|
198 | IUResetSwitch(&FocusMotionSP);
|
---|
199 |
|
---|
200 | // If speed is "halt"
|
---|
201 | if (FocusSpeedN[0].value == 0)
|
---|
202 | {
|
---|
203 | FocusMotionSP.s = IPS_IDLE;
|
---|
204 | IDSetSwitch(&FocusMotionSP, NULL);
|
---|
205 | return;
|
---|
206 | }
|
---|
207 |
|
---|
208 | IUUpdateSwitch(&FocusMotionSP, states, names, n);
|
---|
209 | index = getOnSwitch(&FocusMotionSP);
|
---|
210 |
|
---|
211 |
|
---|
212 | if ( ( err = setFocuserMotion(fd, index) < 0) )
|
---|
213 | {
|
---|
214 | handleError(&FocusMotionSP, err, "Setting focuser speed");
|
---|
215 | return;
|
---|
216 | }
|
---|
217 |
|
---|
218 | FocusMotionSP.s = IPS_BUSY;
|
---|
219 |
|
---|
220 | // with a timer
|
---|
221 | if (FocusTimerNP.np[0].value > 0)
|
---|
222 | {
|
---|
223 | FocusTimerNP.s = IPS_BUSY;
|
---|
224 | IDLog("Starting Focus Timer BUSY\n");
|
---|
225 | IEAddTimer(50, LX200Generic::updateFocusTimer, this);
|
---|
226 | }
|
---|
227 |
|
---|
228 | IDSetSwitch(&FocusMotionSP, NULL);
|
---|
229 | return;
|
---|
230 | }
|
---|
231 |
|
---|
232 | LX200Generic::ISNewSwitch (dev, name, states, names, n);
|
---|
233 |
|
---|
234 | }
|
---|
235 |
|
---|
236 | void LX200Autostar::ISPoll ()
|
---|
237 | {
|
---|
238 |
|
---|
239 | LX200Generic::ISPoll();
|
---|
240 |
|
---|
241 | }
|
---|
242 |
|
---|
243 | void LX200Autostar::getBasicData()
|
---|
244 | {
|
---|
245 |
|
---|
246 | VersionInfo.tp[0].text = new char[64];
|
---|
247 | getVersionDate(fd, VersionInfo.tp[0].text);
|
---|
248 | VersionInfo.tp[1].text = new char[64];
|
---|
249 | getVersionTime(fd, VersionInfo.tp[1].text);
|
---|
250 | VersionInfo.tp[2].text = new char[64];
|
---|
251 | getVersionNumber(fd, VersionInfo.tp[2].text);
|
---|
252 | VersionInfo.tp[3].text = new char[128];
|
---|
253 | getFullVersion(fd, VersionInfo.tp[3].text);
|
---|
254 | VersionInfo.tp[4].text = new char[128];
|
---|
255 | getProductName(fd, VersionInfo.tp[4].text);
|
---|
256 |
|
---|
257 | IDSetText(&VersionInfo, NULL);
|
---|
258 |
|
---|
259 | // process parent
|
---|
260 | LX200Generic::getBasicData();
|
---|
261 |
|
---|
262 | }
|
---|