Instrument Neutral Distributed Interface INDI  0.9.8
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 #include "indilogger.h"
25 
26 INDI::FilterInterface::FilterInterface()
27 {
28  FilterNameTP = new ITextVectorProperty;
29  FilterNameT = NULL;
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 Slot",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::processFilterSlot(const char *deviceName, double values[], char *names[])
56 {
57  TargetFilter = values[0];
58 
59  INumber *np = IUFindNumber(&FilterSlotNP, names[0]);
60 
61  if (!np)
62  {
63  FilterSlotNP.s = IPS_ALERT;
64  DEBUGFDEVICE(deviceName, Logger::DBG_ERROR, "Unknown error. %s is not a member of %s property.", names[0], FilterSlotNP.name);
65  IDSetNumber(&FilterSlotNP, NULL);
66  return;
67  }
68 
69  if (TargetFilter < FilterSlotN[0].min || TargetFilter > FilterSlotN[0].max)
70  {
71  FilterSlotNP.s = IPS_ALERT;
72  DEBUGFDEVICE(deviceName, Logger::DBG_ERROR, "Error: valid range of filter is from %g to %g", FilterSlotN[0].min, FilterSlotN[0].max);
73  IDSetNumber(&FilterSlotNP, NULL);
74  return;
75  }
76 
77  FilterSlotNP.s = IPS_BUSY;
78  DEBUGFDEVICE(deviceName, Logger::DBG_SESSION, "Setting current filter to slot %d", TargetFilter);
79  IDSetNumber(&FilterSlotNP, NULL);
80 
81  SelectFilter(TargetFilter);
82 
83  return;
84 
85 }
86 
87 void INDI::FilterInterface::processFilterName(const char *deviceName, char *texts[], char *names[], int n)
88 {
89  int rc;
90  FilterNameTP->s=IPS_OK;
91  rc=IUUpdateText(FilterNameTP,texts,names,n);
92 
93  if (SetFilterNames() == true)
94  IDSetText(FilterNameTP,NULL);
95  else
96  {
97  FilterNameTP->s = IPS_ALERT;
98  DEBUGDEVICE(deviceName, Logger::DBG_ERROR, "Error updating names of filters.");
99  IDSetText(FilterNameTP, NULL);
100  }
101 
102 }
103 
104 
105 
106