Instrument Neutral Distributed Interface INDI  0.9.8
indifocuser.cpp
1 /*******************************************************************************
2  Copyright(c) 2013 Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #include "indifocuser.h"
20 
21 #include <string.h>
22 
23 INDI::Focuser::Focuser()
24 {
25 
26 }
27 
28 INDI::Focuser::~Focuser()
29 {
30 }
31 
33 {
34  DefaultDevice::initProperties(); // let the base class flesh in what it wants
35 
36  initFocuserProperties(getDeviceName(), MAIN_CONTROL_TAB);
37 
38  /* Port */
39  IUFillText(&PortT[0], "PORT", "Port", "/dev/ttyUSB0");
40  IUFillTextVector(&PortTP, PortT, 1, getDeviceName(), "DEVICE_PORT", "Ports", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE);
41 
42  // Presets
43  IUFillNumber(&PresetN[0], "Preset 1", "", "%6.2f", 0, 60000, 1000, 0);
44  IUFillNumber(&PresetN[1], "Preset 2", "", "%6.2f", 0, 60000, 1000, 0);
45  IUFillNumber(&PresetN[2], "Preset 3", "", "%6.2f", 0, 60000, 1000, 0);
46  IUFillNumberVector(&PresetNP, PresetN, 3, getDeviceName(), "Presets", "", "Presets", IP_RW, 0, IPS_IDLE);
47 
48  //Preset GOTO
49  IUFillSwitch(&PresetGotoS[0], "Preset 1", "", ISS_OFF);
50  IUFillSwitch(&PresetGotoS[1], "Preset 2", "", ISS_OFF);
51  IUFillSwitch(&PresetGotoS[2], "Preset 3", "", ISS_OFF);
52  IUFillSwitchVector(&PresetGotoSP, PresetGotoS, 3, getDeviceName(), "Goto", "", "Presets", IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
53 
54  addDebugControl();
55 
56  return true;
57 }
58 
59 void INDI::Focuser::ISGetProperties (const char *dev)
60 {
61  // First we let our parent populate
63 
64  defineText(&PortTP);
65 
66  return;
67 }
68 
70 {
71  if(isConnected())
72  {
73  // Now we add our focusser specific stuff
74  defineSwitch(&FocusMotionSP);
75 
76  if (variableSpeed)
77  {
78  defineNumber(&FocusSpeedNP);
79  defineNumber(&FocusTimerNP);
80  }
81  if (canRelMove)
82  defineNumber(&FocusRelPosNP);
83  if (canAbsMove)
84  defineNumber(&FocusAbsPosNP);
85  if (canAbort)
86  defineSwitch(&AbortSP);
87  if (canAbsMove)
88  {
89  defineNumber(&PresetNP);
90  defineSwitch(&PresetGotoSP);
91  }
92  } else
93  {
94  deleteProperty(FocusMotionSP.name);
95  if (variableSpeed)
96  {
97  deleteProperty(FocusSpeedNP.name);
98  deleteProperty(FocusTimerNP.name);
99  }
100  if (canRelMove)
101  deleteProperty(FocusRelPosNP.name);
102  if (canAbsMove)
103  deleteProperty(FocusAbsPosNP.name);
104  if (canAbort)
105  deleteProperty(AbortSP.name);
106  if (canAbsMove)
107  {
108  deleteProperty(PresetNP.name);
109  deleteProperty(PresetGotoSP.name);
110  }
111  }
112  return true;
113 }
114 
115 
116 bool INDI::Focuser::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
117 {
118  // first check if it's for our device
119  if(strcmp(dev,getDeviceName())==0)
120  {
121  if (!strcmp(name, PresetNP.name))
122  {
123  IUUpdateNumber(&PresetNP, values, names, n);
124  PresetNP.s = IPS_OK;
125  IDSetNumber(&PresetNP, NULL);
126 
127  saveConfig();
128 
129  return true;
130  }
131 
132  if (strstr(name, "FOCUS_"))
133  return processFocuserNumber(dev, name, values, names, n);
134 
135  }
136 
137 
138  return DefaultDevice::ISNewNumber(dev,name,values,names,n);
139 }
140 
141 bool INDI::Focuser::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
142 {
143 
144  if(strcmp(dev,getDeviceName())==0)
145  {
146  if (!strcmp(PresetGotoSP.name, name))
147  {
148  IUUpdateSwitch(&PresetGotoSP, states, names, n);
149  int index = IUFindOnSwitchIndex(&PresetGotoSP);
150  int rc = MoveAbs(PresetN[index].value);
151  if (rc >= 0)
152  {
153  PresetGotoSP.s = IPS_OK;
154  DEBUGF(INDI::Logger::DBG_SESSION, "Moving to Preset %d with position %g.", index+1, PresetN[index].value);
155  IDSetSwitch(&PresetGotoSP, NULL);
156  return true;
157  }
158 
159  PresetGotoSP.s = IPS_ALERT;
160  IDSetSwitch(&PresetGotoSP, NULL);
161  return false;
162  }
163 
164  if (strstr(name, "FOCUS_"))
165  return processFocuserSwitch(dev, name, states, names, n);
166 
167  }
168 
169  // Nobody has claimed this, so, ignore it
170  return DefaultDevice::ISNewSwitch(dev,name,states,names,n);
171 }
172 
173 bool INDI::Focuser::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
174 {
175  if(strcmp(dev,getDeviceName())==0)
176  {
177  if (!strcmp(name, PortTP.name))
178  {
179  IUUpdateText(&PortTP, texts, names, n);
180  PortTP.s = IPS_OK;
181  IDSetText(&PortTP, NULL);
182  return true;
183  }
184  }
185 
186  return DefaultDevice::ISNewText(dev, name, texts, names, n);
187 }
188 
189 bool INDI::Focuser::ISSnoopDevice (XMLEle *root)
190 {
192 }
193 
195 {
196  IUSaveConfigText(fp, &PortTP);
197  IUSaveConfigNumber(fp, &PresetNP);
198 
199  return true;
200 }
201