Instrument Neutral Distributed Interface INDI  0.9.6
indifilterinterface.cpp
1 /*
2  Filter Interface
3  Copyright (C) 2011 Jasem Mutlaq (mutlaqja@ikarustech.com)
4 
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.
9 
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.
14 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #include <string.h>
22 
23 #include "indifilterinterface.h"
24 
25 INDI::FilterInterface::FilterInterface()
26 {
27  FilterNameTP = new ITextVectorProperty;
28  FilterNameT = NULL;
29  MinFilter = MaxFilter = 0;
30 }
31 
32 void INDI::FilterInterface::initFilterProperties(const char *deviceName, const char* groupName)
33 {
34  IUFillNumber(&FilterSlotN[0],"FILTER_SLOT_VALUE","Filter","%3.0f",1.0,12.0,1.0,1.0);
35  IUFillNumberVector(&FilterSlotNP,FilterSlotN,1,deviceName,"FILTER_SLOT","Filter",groupName,IP_RW,60,IPS_IDLE);
36 }
37 
38 INDI::FilterInterface::~FilterInterface()
39 {
40 
41  delete FilterNameTP;
42 }
43 
45 {
46  // The hardware has finished changing
47  // filters
48  FilterSlotN[0].value=f;
49  FilterSlotNP.s=IPS_OK;
50  // Tell the clients we are done, and
51  // filter is now useable
52  IDSetNumber(&FilterSlotNP,NULL);
53 }
54 
55 void INDI::FilterInterface::processFilterProperties(const char *name, double values[], char *names[], int n)
56 {
57 
58  if (!strcmp(FilterSlotNP.name, name))
59  {
60 
61  TargetFilter = values[0];
62 
63  INumber *np = IUFindNumber(&FilterSlotNP, names[0]);
64 
65  if (!np)
66  {
67  FilterSlotNP.s = IPS_ALERT;
68  IDSetNumber(&FilterSlotNP, "Unknown error. %s is not a member of %s property.", names[0], name);
69  return;
70  }
71 
72  if (TargetFilter < MinFilter || TargetFilter > MaxFilter)
73  {
74  FilterSlotNP.s = IPS_ALERT;
75  IDSetNumber(&FilterSlotNP, "Error: valid range of filter is from %d to %d", MinFilter, MaxFilter);
76  return;
77  }
78 
79  FilterSlotNP.s = IPS_BUSY;
80  IDSetNumber(&FilterSlotNP, "Setting current filter to slot %d", TargetFilter);
81 
82  SelectFilter(TargetFilter);
83 
84  return;
85 
86  }
87 }
88 
89 
90 
91