source: BAORadio/libindi/libindi/libs/indibase/indifocuser.cpp @ 642

Last change on this file since 642 was 642, checked in by frichard, 12 years ago

-Alignement des antennes
-Version 0.0.9 de libindi

File size: 5.1 KB
Line 
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
23INDI::Focuser::Focuser()
24{
25    FocusSpeedNP  = new INumberVectorProperty;
26    FocusTimerNP  = new INumberVectorProperty;
27    FocusMotionSP = new ISwitchVectorProperty;
28}
29
30INDI::Focuser::~Focuser()
31{
32    delete FocusSpeedNP;
33    delete FocusTimerNP;
34    delete FocusMotionSP;
35
36}
37
38bool INDI::Focuser::initProperties()
39{
40    DefaultDriver::initProperties();   //  let the base class flesh in what it wants
41
42    IUFillNumber(&FocusSpeedN[0],"FOCUS_SPEED_VALUE","Focus Speed","%3.0f",0.0,255.0,1.0,255.0);
43    IUFillNumberVector(FocusSpeedNP,FocusSpeedN,1,deviceName(),"FOCUS_SPEED","Speed",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
44
45    IUFillNumber(&FocusTimerN[0],"FOCUS_TIMER_VALUE","Focus Timer","%4.0f",0.0,1000.0,10.0,1000.0);
46    IUFillNumberVector(FocusTimerNP,FocusTimerN,1,deviceName(),"FOCUS_TIMER","Timer",MAIN_CONTROL_TAB,IP_RW,60,IPS_OK);
47
48    IUFillSwitch(&FocusMotionS[0],"FOCUS_INWARD","Focus In",ISS_ON);
49    IUFillSwitch(&FocusMotionS[1],"FOCUS_OUTWARD","Focus Out",ISS_OFF);
50    IUFillSwitchVector(FocusMotionSP,FocusMotionS,2,deviceName(),"FOCUS_MOTION","Direction",MAIN_CONTROL_TAB,IP_RW,ISR_1OFMANY,60,IPS_OK);
51
52    return 0;
53}
54
55void INDI::Focuser::ISGetProperties (const char *dev)
56{
57    //  First we let our parent populate
58    DefaultDriver::ISGetProperties(dev);
59
60    return;
61}
62
63bool INDI::Focuser::updateProperties()
64{
65    if(isConnected())
66    {
67        //  Now we add our focusser specific stuff
68        defineSwitch(FocusMotionSP);
69        defineNumber(FocusSpeedNP);
70        defineNumber(FocusTimerNP);
71    } else
72    {
73        deleteProperty(FocusMotionSP->name);
74        deleteProperty(FocusSpeedNP->name);
75        deleteProperty(FocusTimerNP->name);
76    }
77    return true;
78}
79
80
81bool INDI::Focuser::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
82{
83    //  first check if it's for our device
84    if(strcmp(dev,deviceName())==0)
85    {
86        //  This is for our device
87        //  Now lets see if it's something we process here
88        if(strcmp(name,"FOCUS_TIMER")==0)
89        {
90            //  Ok, gotta move the focusser now
91            FocusDirection dir;
92            int speed;
93            int t;
94
95            //IDLog(")
96            //  first we get all the numbers just sent to us
97            FocusTimerNP->s=IPS_OK;
98            IUUpdateNumber(FocusTimerNP,values,names,n);
99
100            //  Now lets find what we need for this move
101            speed=FocusSpeedN[0].value;
102            if(FocusMotionS[0].s==ISS_ON) dir=FOCUS_INWARD;
103            else dir=FOCUS_OUTWARD;
104            t=FocusTimerN[0].value;
105
106            if (Move(dir,speed,t) == false)
107                FocusTimerNP->s = IPS_ALERT;
108
109            IDSetNumber(FocusTimerNP,NULL);
110            return true;
111        }
112
113
114        if(strcmp(name,"FOCUS_SPEED")==0)
115        {
116            FocusSpeedNP->s=IPS_OK;
117            IUUpdateNumber(FocusSpeedNP,values,names,n);
118
119
120
121            //  Update client display
122            IDSetNumber(FocusSpeedNP,NULL);
123            return true;
124        }
125
126    }
127
128
129    return DefaultDriver::ISNewNumber(dev,name,values,names,n);
130}
131
132bool INDI::Focuser::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
133{
134
135    if(strcmp(dev,deviceName())==0)
136    {
137        //  This one is for us
138        if(strcmp(name,"FOCUS_MOTION")==0)
139        {
140            //  client is telling us what to do with focus direction
141            FocusMotionSP->s=IPS_OK;
142            IUUpdateSwitch(FocusMotionSP,states,names,n);
143            //  Update client display
144            IDSetSwitch(FocusMotionSP,NULL);
145
146            return true;
147        }
148
149    }
150
151    //  Nobody has claimed this, so, ignore it
152    return DefaultDriver::ISNewSwitch(dev,name,states,names,n);
153}
154
155bool INDI::Focuser::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
156{
157    return DefaultDriver::ISNewText(dev, name, texts, names, n);
158}
159
160void INDI::Focuser::ISSnoopDevice (XMLEle *root)
161{
162 return;
163}
164
165bool INDI::Focuser::Move(FocusDirection dir, int speed, int duration)
166{
167    //  This should be a virtual function, because the low level hardware class
168    //  must override this
169    //  but it's much easier early development if the method actually
170    //  exists for now
171    return false;
172}
173
Note: See TracBrowser for help on using the repository browser.