moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / indi / lx200classic.cpp
blob57c7bfeae7a54fcdc1629fd6957c9a9c01e09389
1 /*
2 LX200 Classoc
3 Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "lx200classic.h"
26 #include "lx200driver.h"
28 extern LX200Generic *telescope;
29 extern INumberVectorProperty eqNum;
30 extern ITextVectorProperty Time;
31 extern int MaxReticleFlashRate;
33 #define BASIC_GROUP "Main Control"
34 #define LIBRARY_GROUP "Library"
35 #define MOVE_GROUP "Movement Control"
37 static IText ObjectText[] = {{"objectText", "Info", 0, 0, 0, 0}};
38 static ITextVectorProperty ObjectInfo = {mydev, "Object Info", "", BASIC_GROUP, IP_RO, 0, IPS_IDLE, ObjectText, NARRAY(ObjectText), "", 0};
40 /* Library group */
41 static ISwitch StarCatalogS[] = {{"STAR", "", ISS_ON, 0, 0}, {"SAO", "", ISS_OFF, 0, 0}, {"GCVS", "", ISS_OFF, 0, 0}};
42 static ISwitch DeepSkyCatalogS[] = {{"NGC", "", ISS_ON, 0, 0}, {"IC", "", ISS_OFF, 0, 0}, {"UGC", "", ISS_OFF, 0, 0}, {"Caldwell", "", ISS_OFF, 0, 0}, {"Arp", "", ISS_OFF, 0, 0}, {"Abell", "", ISS_OFF, 0, 0}, {"Messier", "", ISS_OFF, 0, 0}};
43 static ISwitch SolarS[] = { {"Select", "Select item...", ISS_ON, 0, 0}, {"1", "Mercury", ISS_OFF,0 , 0}, {"2", "Venus", ISS_OFF, 0, 0}, {"3", "Moon", ISS_OFF, 0, 0}, {"4", "Mars", ISS_OFF, 0, 0}, {"5", "Jupiter", ISS_OFF, 0, 0}, {"6", "Saturn", ISS_OFF, 0, 0}, {"7", "Uranus", ISS_OFF, 0, 0}, {"8", "Neptune", ISS_OFF, 0, 0}, {"9", "Pluto", ISS_OFF, 0 ,0}};
45 static ISwitchVectorProperty StarCatalogSw = { mydev, "Star Catalogs", "", LIBRARY_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, StarCatalogS, NARRAY(StarCatalogS), "", 0};
46 static ISwitchVectorProperty DeepSkyCatalogSw= { mydev, "Deep Sky Catalogs", "", LIBRARY_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, DeepSkyCatalogS, NARRAY(DeepSkyCatalogS), "", 0};
47 static ISwitchVectorProperty SolarSw = { mydev, "SOLAR_SYSTEM", "Solar System", LIBRARY_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, SolarS, NARRAY(SolarS), "", 0};
49 static INumber ObjectN[] = { "ObjectN", "Number", "%g", 1., 10000., 1., 0., 0, 0, 0};
50 static INumberVectorProperty ObjectNo= { mydev, "Object Number", "", LIBRARY_GROUP, IP_RW, 0, IPS_IDLE, ObjectN, NARRAY(ObjectN), "", 0 };
52 static INumber MaxSlew[] = {{"maxSlew", "Rate", "%g", 2.0, 9.0, 1.0, 9., 0, 0 ,0}};
53 static INumberVectorProperty MaxSlewRate = { mydev, "Max slew Rate", "", MOVE_GROUP, IP_RW, 0, IPS_IDLE, MaxSlew, NARRAY(MaxSlew), "", 0};
55 static INumber altLimit[] = {
56 {"minAlt", "min Alt", "%+03f", -90., 90., 0., 0., 0, 0, 0},
57 {"maxAlt", "max Alt", "%+03f", -90., 90., 0., 0., 0, 0, 0}};
58 static INumberVectorProperty elevationLimit = { mydev, "altLimit", "Slew elevation Limit", BASIC_GROUP, IP_RW, 0, IPS_IDLE, altLimit, NARRAY(altLimit), "", 0};
60 void changeLX200ClassicDeviceName(const char *newName)
62 strcpy(ObjectInfo.device, newName);
63 strcpy(SolarSw.device, newName);
64 strcpy(StarCatalogSw.device, newName);
65 strcpy(DeepSkyCatalogSw.device, newName);
66 strcpy(ObjectNo.device, newName);
67 strcpy(MaxSlewRate.device , newName );
68 strcpy(elevationLimit.device , newName );
71 LX200Classic::LX200Classic() : LX200Generic()
73 ObjectInfo.tp[0].text = new char[128];
74 strcpy(ObjectInfo.tp[0].text, "");
76 currentCatalog = LX200_STAR_C;
77 currentSubCatalog = 0;
82 void LX200Classic::ISGetProperties (const char *dev)
85 if (dev && strcmp (thisDevice, dev))
86 return;
88 LX200Generic::ISGetProperties(dev);
90 IDDefNumber (&elevationLimit, NULL);
91 IDDefText (&ObjectInfo, NULL);
92 IDDefSwitch (&SolarSw, NULL);
93 IDDefSwitch (&StarCatalogSw, NULL);
94 IDDefSwitch (&DeepSkyCatalogSw, NULL);
95 IDDefNumber (&ObjectNo, NULL);
96 IDDefNumber (&MaxSlewRate, NULL);
100 void LX200Classic::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
102 // ignore if not ours //
103 if (strcmp (dev, thisDevice))
104 return;
106 LX200Generic::ISNewText (dev, name, texts, names, n);
110 void LX200Classic::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
112 int err=0;
114 // ignore if not ours //
115 if (strcmp (dev, thisDevice))
116 return;
118 if ( !strcmp (name, ObjectNo.name) )
120 if (checkPower(&ObjectNo))
121 return;
123 selectCatalogObject( currentCatalog, (int) values[0]);
125 getLX200RA(&eqNum.np[0].value);
126 getLX200DEC(&eqNum.np[1].value);
128 ObjectNo.s = eqNum.s = IPS_OK;
129 IDSetNumber(&ObjectNo , "Object updated");
130 IDSetNumber(&eqNum, NULL);
132 if (getObjectInfo(ObjectText[0].text) < 0)
133 IDMessage(thisDevice, "Getting object info failed.");
134 else
135 IDSetText (&ObjectInfo, NULL);
137 handleCoordSet();
139 return;
142 if ( !strcmp (name, MaxSlewRate.name) )
145 if (checkPower(&MaxSlewRate))
146 return;
148 if ( ( err = setMaxSlewRate( (int) values[0]) < 0) )
150 handleError(&MaxSlewRate, err, "Setting maximum slew rate");
151 return;
153 MaxSlewRate.s = IPS_OK;
154 MaxSlewRate.np[0].value = values[0];
155 IDSetNumber(&MaxSlewRate, NULL);
156 return;
161 if (!strcmp (name, elevationLimit.name))
163 // new elevation limits
164 double minAlt = 0, maxAlt = 0;
165 int i, nset;
167 if (checkPower(&elevationLimit))
168 return;
170 for (nset = i = 0; i < n; i++)
172 INumber *altp = IUFindNumber (&elevationLimit, names[i]);
173 if (altp == &altLimit[0])
175 minAlt = values[i];
176 nset += minAlt >= -90.0 && minAlt <= 90.0;
177 } else if (altp == &altLimit[1])
179 maxAlt = values[i];
180 nset += maxAlt >= -90.0 && maxAlt <= 90.0;
183 if (nset == 2)
185 //char l[32], L[32];
186 if ( ( err = setMinElevationLimit( (int) minAlt) < 0) )
188 handleError(&elevationLimit, err, "Setting elevation limit");
190 setMaxElevationLimit( (int) maxAlt);
191 elevationLimit.np[0].value = minAlt;
192 elevationLimit.np[1].value = maxAlt;
193 elevationLimit.s = IPS_OK;
194 IDSetNumber (&elevationLimit, NULL);
195 } else
197 elevationLimit.s = IPS_IDLE;
198 IDSetNumber(&elevationLimit, "elevation limit missing or invalid");
201 return;
204 LX200Generic::ISNewNumber (dev, name, values, names, n);
207 void LX200Classic::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
210 int index=0;
212 // ignore if not ours //
213 if (strcmp (dev, thisDevice))
214 return;
216 // Star Catalog
217 if (!strcmp (name, StarCatalogSw.name))
219 if (checkPower(&StarCatalogSw))
220 return;
222 IUResetSwitches(&StarCatalogSw);
223 IUUpdateSwitches(&StarCatalogSw, states, names, n);
224 index = getOnSwitch(&StarCatalogSw);
226 currentCatalog = LX200_STAR_C;
228 if (selectSubCatalog(currentCatalog, index))
230 currentSubCatalog = index;
231 StarCatalogSw.s = IPS_OK;
232 IDSetSwitch(&StarCatalogSw, NULL);
234 else
236 StarCatalogSw.s = IPS_IDLE;
237 IDSetSwitch(&StarCatalogSw, "Catalog unavailable");
239 return;
242 // Deep sky catalog
243 if (!strcmp (name, DeepSkyCatalogSw.name))
245 if (checkPower(&DeepSkyCatalogSw))
246 return;
248 IUResetSwitches(&DeepSkyCatalogSw);
249 IUUpdateSwitches(&DeepSkyCatalogSw, states, names, n);
250 index = getOnSwitch(&DeepSkyCatalogSw);
252 if (index == LX200_MESSIER_C)
254 currentCatalog = index;
255 DeepSkyCatalogSw.s = IPS_OK;
256 IDSetSwitch(&DeepSkyCatalogSw, NULL);
257 return;
259 else
260 currentCatalog = LX200_DEEPSKY_C;
262 if (selectSubCatalog(currentCatalog, index))
264 currentSubCatalog = index;
265 DeepSkyCatalogSw.s = IPS_OK;
266 IDSetSwitch(&DeepSkyCatalogSw, NULL);
268 else
270 DeepSkyCatalogSw.s = IPS_IDLE;
271 IDSetSwitch(&DeepSkyCatalogSw, "Catalog unavailable");
273 return;
276 // Solar system
277 if (!strcmp (name, SolarSw.name))
280 if (checkPower(&SolarSw))
281 return;
283 IUResetSwitches(&SolarSw);
284 IUUpdateSwitches(&SolarSw, states, names, n);
285 index = getOnSwitch(&SolarSw);
287 // We ignore the first option : "Select item"
288 if (index == 0)
290 SolarSw.s = IPS_IDLE;
291 IDSetSwitch(&SolarSw, NULL);
292 return;
295 selectSubCatalog ( LX200_STAR_C, LX200_STAR);
296 selectCatalogObject( LX200_STAR_C, index + 900);
298 ObjectNo.s = IPS_OK;
299 SolarSw.s = IPS_OK;
301 getObjectInfo(ObjectInfo.tp[0].text);
302 IDSetNumber(&ObjectNo , "Object updated.");
303 IDSetSwitch(&SolarSw, NULL);
305 if (currentCatalog == LX200_STAR_C || currentCatalog == LX200_DEEPSKY_C)
306 selectSubCatalog( currentCatalog, currentSubCatalog);
308 getObjectRA(&targetRA);
309 getObjectDEC(&targetDEC);
311 handleCoordSet();
313 return;
316 LX200Generic::ISNewSwitch (dev, name, states, names, n);
320 void LX200Classic::ISPoll ()
323 LX200Generic::ISPoll();
327 void LX200Classic::getBasicData()
330 // process parent first
331 LX200Generic::getBasicData();