source: BAORadio/libindi/libindi/drivers/focuser/focus_simulator.cpp @ 698

Last change on this file since 698 was 698, checked in by frichard, 12 years ago
File size: 5.4 KB
Line 
1/*******************************************************************************
2  Copyright(c) 2012 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#include "focus_simulator.h"
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <math.h>
24#include <string.h>
25
26#include <memory>
27
28
29// We declare an auto pointer to focusSim.
30std::auto_ptr<FocusSim> focusSim(0);
31
32#define SIM_SEEING  0
33#define SIM_FWHM    1
34
35
36void ISPoll(void *p);
37
38
39void ISInit()
40{
41   static int isInit =0;
42
43   if (isInit == 1)
44       return;
45
46    isInit = 1;
47    if(focusSim.get() == 0) focusSim.reset(new FocusSim());
48
49}
50
51void ISGetProperties(const char *dev)
52{
53        ISInit();
54        focusSim->ISGetProperties(dev);
55}
56
57void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int num)
58{
59        ISInit();
60        focusSim->ISNewSwitch(dev, name, states, names, num);
61}
62
63void ISNewText( const char *dev, const char *name, char *texts[], char *names[], int num)
64{
65        ISInit();
66        focusSim->ISNewText(dev, name, texts, names, num);
67}
68
69void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int num)
70{
71        ISInit();
72        focusSim->ISNewNumber(dev, name, values, names, num);
73}
74
75void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
76{
77  INDI_UNUSED(dev);
78  INDI_UNUSED(name);
79  INDI_UNUSED(sizes);
80  INDI_UNUSED(blobsizes);
81  INDI_UNUSED(blobs);
82  INDI_UNUSED(formats);
83  INDI_UNUSED(names);
84  INDI_UNUSED(n);
85}
86
87void ISSnoopDevice (XMLEle *root)
88{
89    ISInit();
90    focusSim->ISSnoopDevice(root);
91}
92
93FocusSim::FocusSim()
94{
95
96}
97
98bool FocusSim::SetupParms()
99{
100    IDSetNumber(&FWHMNP, NULL);
101    return true;
102}
103
104bool FocusSim::Connect()
105{
106    SetTimer(1000);     //  start the timer
107    return true;
108}
109
110FocusSim::~FocusSim()
111{
112    //dtor
113}
114
115const char * FocusSim::getDefaultName()
116{
117        return (char *)"Focuser Simulator";
118}
119
120bool FocusSim::initProperties()
121{
122    //  Most hardware layers wont actually have indi properties defined
123    //  but the simulators are a special case
124    INDI::Focuser::initProperties();
125
126    IUFillNumber(&SeeingN[0],"SIM_SEEING","arcseconds","%4.2f",0,60,0,3.5);
127    IUFillNumberVector(&SeeingNP,SeeingN,1,getDeviceName(),"SEEING_SETTINGS","Seeing",MAIN_CONTROL_TAB,IP_RW,60,IPS_IDLE);
128
129    IUFillNumber(&FWHMN[0],"SIM_FWHM","arcseconds","%4.2f",0,60,0,7.5);
130    IUFillNumberVector(&FWHMNP,FWHMN,1,getDeviceName(), "FWHM","FWHM",MAIN_CONTROL_TAB,IP_RO,60,IPS_IDLE);
131
132    ticks = sqrt(FWHMN[0].value - SeeingN[0].value) / 0.75;
133
134    IDLog("Initial Ticks is %g\n", ticks);
135
136    return true;
137}
138
139void FocusSim::ISGetProperties (const char *dev)
140{
141    //  First we let our parent populate
142    INDI::Focuser::ISGetProperties(dev);
143
144
145
146    return;
147}
148
149bool FocusSim::updateProperties()
150{
151
152    INDI::Focuser::updateProperties();
153
154    if (isConnected())
155    {
156        defineNumber(&SeeingNP);
157        defineNumber(&FWHMNP);
158        SetupParms();
159    }
160    else
161    {
162        deleteProperty(SeeingNP.name);
163        deleteProperty(FWHMNP.name);
164    }
165
166    return true;
167}
168
169
170bool FocusSim::Disconnect()
171{
172    return true;
173}
174
175
176void FocusSim::TimerHit()
177{
178    int nexttimer=1000;
179
180    if(isConnected() == false) return;  //  No need to reset timer if we are not connected anymore
181
182    SetTimer(nexttimer);
183    return;
184}
185
186bool FocusSim::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
187{
188    if(strcmp(dev,getDeviceName())==0)
189    {
190        if(strcmp(name,"SEEING_SETTINGS")==0)
191        {
192            SeeingNP.s = IPS_OK;
193            IUUpdateNumber(&SeeingNP, values, names, n);
194
195            IDSetNumber(&SeeingNP,NULL);
196            saveConfig();
197
198            return true;
199
200        }
201
202    }
203
204    //  if we didn't process it, continue up the chain, let somebody else
205    //  give it a shot
206    return INDI::Focuser::ISNewNumber(dev,name,values,names,n);
207}
208
209
210bool FocusSim::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
211{
212
213    //  Nobody has claimed this, so, ignore it
214    return INDI::Focuser::ISNewSwitch(dev,name,states,names,n);
215}
216
217bool FocusSim::Move(FocusDirection dir, int speed, int duration)
218{
219    double targetTicks = (speed * duration) / (FocusSpeedN[0].max * FocusTimerN[0].max);
220
221    IDLog("Current ticks: %g - target Ticks: %g\n", ticks, targetTicks);
222
223    if (dir == FOCUS_INWARD)
224        ticks -= targetTicks;
225    else
226        ticks += targetTicks;
227
228    IDLog("Current ticks: %g\n", ticks);
229
230    FWHMN[0].value = 0.5625*ticks*ticks +  SeeingN[0].value;
231
232    if (FWHMN[0].value < SeeingN[0].value)
233        FWHMN[0].value = SeeingN[0].value;
234
235    IDSetNumber(&FWHMNP, NULL);
236
237    return true;
238
239}
240
Note: See TracBrowser for help on using the repository browser.