Instrument Neutral Distributed Interface INDI  0.9.6
indifocuser.cpp
1 /*******************************************************************************
2  Copyright(c) 2011 Gerry Rozema. 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 INDI::Focuser::~Focuser()
28 {
29 }
30 
32 {
33  DefaultDevice::initProperties(); // let the base class flesh in what it wants
34 
35  IUFillNumber(&FocusSpeedN[0],"FOCUS_SPEED_VALUE","Focus Speed","%3.0f",0.0,255.0,1.0,255.0);
36  IUFillNumberVector(&FocusSpeedNP,FocusSpeedN,1,getDeviceName(),"FOCUS_SPEED","Speed",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
37 
38  IUFillNumber(&FocusTimerN[0],"FOCUS_TIMER_VALUE","Focus Timer","%4.0f",0.0,1000.0,10.0,1000.0);
39  IUFillNumberVector(&FocusTimerNP,FocusTimerN,1,getDeviceName(),"FOCUS_TIMER","Timer",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
40 
41 
42  IUFillSwitch(&FocusMotionS[0],"FOCUS_INWARD","Focus In",ISS_ON);
43  IUFillSwitch(&FocusMotionS[1],"FOCUS_OUTWARD","Focus Out",ISS_OFF);
44  IUFillSwitchVector(&FocusMotionSP,FocusMotionS,2,getDeviceName(),"FOCUS_MOTION","Direction",MAIN_CONTROL_TAB,IP_RW,ISR_1OFMANY,60,IPS_OK);
45 
46  // Driver can define those to clients if there is support
47  IUFillNumber(&FocusAbsPosN[0],"FOCUS_ABSOLUTE_POSITION","Ticks","%4.0f",0.0,100000.0,1000.0,50000.0);
48  IUFillNumberVector(&FocusAbsPosNP,FocusAbsPosN,1,getDeviceName(),"ABS_FOCUS_POSITION","Absolute Position",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
49 
50  IUFillNumber(&FocusRelPosN[0],"RELATIVE_ABSOLUTE_POSITION","Ticks","%4.0f",0.0,100000.0,1000.0,50000.0);
51  IUFillNumberVector(&FocusRelPosNP,FocusRelPosN,1,getDeviceName(),"REL_FOCUS_POSITION","Relative Position",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
52 
53  addDebugControl();
54 
55  return true;
56 }
57 
58 void INDI::Focuser::ISGetProperties (const char *dev)
59 {
60  // First we let our parent populate
62 
63  return;
64 }
65 
67 {
68  if(isConnected())
69  {
70  // Now we add our focusser specific stuff
71  defineSwitch(&FocusMotionSP);
72  defineNumber(&FocusSpeedNP);
73  defineNumber(&FocusTimerNP);
74  } else
75  {
76  deleteProperty(FocusMotionSP.name);
77  deleteProperty(FocusSpeedNP.name);
78  deleteProperty(FocusTimerNP.name);
79  }
80  return true;
81 }
82 
83 
84 bool INDI::Focuser::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
85 {
86  // first check if it's for our device
87  if(strcmp(dev,getDeviceName())==0)
88  {
89  // This is for our device
90  // Now lets see if it's something we process here
91  if(strcmp(name,"FOCUS_TIMER")==0)
92  {
93  // Ok, gotta move the focusser now
94  FocusDirection dir;
95  int speed;
96  int t;
97 
98  //IDLog(")
99  // first we get all the numbers just sent to us
100  FocusTimerNP.s=IPS_OK;
101  IUUpdateNumber(&FocusTimerNP,values,names,n);
102 
103  // Now lets find what we need for this move
104  speed=FocusSpeedN[0].value;
105  if(FocusMotionS[0].s==ISS_ON) dir=FOCUS_INWARD;
106  else dir=FOCUS_OUTWARD;
107  t=FocusTimerN[0].value;
108 
109  if (Move(dir,speed,t) == false)
110  FocusTimerNP.s = IPS_ALERT;
111 
112  IDSetNumber(&FocusTimerNP,NULL);
113  return true;
114  }
115 
116 
117  if(strcmp(name,"FOCUS_SPEED")==0)
118  {
119  FocusSpeedNP.s=IPS_OK;
120  IUUpdateNumber(&FocusSpeedNP,values,names,n);
121 
122 
123 
124  // Update client display
125  IDSetNumber(&FocusSpeedNP,NULL);
126  return true;
127  }
128 
129  if(strcmp(name,"ABS_FOCUS_POSITION")==0)
130  {
131 
132  int newPos = (int) values[0];
133  int ret =0;
134 
135  if ( (ret = MoveAbs(newPos)) == 0)
136  {
137  FocusAbsPosNP.s=IPS_OK;
138  IUUpdateNumber(&FocusAbsPosNP,values,names,n);
139  IDSetNumber(&FocusAbsPosNP, "Focuser moved to position %d", newPos);
140  return true;
141  }
142  else if (ret == 1)
143  {
144  FocusAbsPosNP.s=IPS_BUSY;
145  IDSetNumber(&FocusAbsPosNP, "Focuser is moving to position %d", newPos);
146  return true;
147  }
148 
149 
150  FocusAbsPosNP.s = IPS_ALERT;
151  IDSetNumber(&FocusAbsPosNP, "Focuser failed to move to new requested position.");
152  return false;
153  }
154 
155 
156  if(strcmp(name,"REL_FOCUS_POSITION")==0)
157  {
158  int newPos = (int) values[0];
159  int ret =0;
160 
161  if ( (ret=MoveRel( (FocusMotionS[0].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD), newPos)) == 0)
162  {
163  FocusRelPosNP.s=IPS_OK;
164  IUUpdateNumber(&FocusRelPosNP,values,names,n);
165  IDSetNumber(&FocusRelPosNP, "Focuser moved %d steps", newPos);
166  IDSetNumber(&FocusAbsPosNP, NULL);
167  return true;
168  }
169  else if (ret == 1)
170  {
171  FocusRelPosNP.s=IPS_BUSY;
172  IDSetNumber(&FocusAbsPosNP, "Focuser is moving %d steps...", newPos);
173  return true;
174  }
175 
176  FocusRelPosNP.s = IPS_ALERT;
177  IDSetNumber(&FocusRelPosNP, "Focuser failed to move to new requested position.");
178  return false;
179  }
180 
181  }
182 
183 
184  return DefaultDevice::ISNewNumber(dev,name,values,names,n);
185 }
186 
187 bool INDI::Focuser::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
188 {
189 
190  if(strcmp(dev,getDeviceName())==0)
191  {
192  // This one is for us
193  if(strcmp(name,"FOCUS_MOTION")==0)
194  {
195  // client is telling us what to do with focus direction
196  FocusMotionSP.s=IPS_OK;
197  IUUpdateSwitch(&FocusMotionSP,states,names,n);
198  // Update client display
199  IDSetSwitch(&FocusMotionSP,NULL);
200 
201  return true;
202  }
203 
204  }
205 
206  // Nobody has claimed this, so, ignore it
207  return DefaultDevice::ISNewSwitch(dev,name,states,names,n);
208 }
209 
210 bool INDI::Focuser::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
211 {
212  return DefaultDevice::ISNewText(dev, name, texts, names, n);
213 }
214 
215 bool INDI::Focuser::Move(FocusDirection dir, int speed, int duration)
216 {
217  // This should be a virtual function, because the low level hardware class
218  // must override this
219  // but it's much easier early development if the method actually
220  // exists for now
221  return false;
222 }
223 
224 int INDI::Focuser::MoveRel(FocusDirection dir, unsigned int ticks)
225 {
226  // This should be a virtual function, because the low level hardware class
227  // must override this
228  // but it's much easier early development if the method actually
229  // exists for now
230  return -1;
231 }
232 
234 {
235  // This should be a virtual function, because the low level hardware class
236  // must override this
237  // but it's much easier early development if the method actually
238  // exists for now
239  return -1;
240 }
241 
242 
243 bool INDI::Focuser::ISSnoopDevice (XMLEle *root)
244 {
246 }
247