Instrument Neutral Distributed Interface INDI  1.5.0
indifilterinterface.cpp
Go to the documentation of this file.
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 "indifilterinterface.h"
22 
23 #include "indilogger.h"
24 
26 {
28  FilterNameT = nullptr;
29 }
30 
31 void INDI::FilterInterface::initFilterProperties(const char *deviceName, const char *groupName)
32 {
33  IUFillNumber(&FilterSlotN[0], "FILTER_SLOT_VALUE", "Filter", "%3.0f", 1.0, 12.0, 1.0, 1.0);
34  IUFillNumberVector(&FilterSlotNP, FilterSlotN, 1, deviceName, "FILTER_SLOT", "Filter Slot", groupName, IP_RW, 60,
35  IPS_IDLE);
36 }
37 
39 {
40  delete FilterNameTP;
41 }
42 
44 {
45  // The hardware has finished changing
46  // filters
47  FilterSlotN[0].value = f;
49  // Tell the clients we are done, and
50  // filter is now useable
51  IDSetNumber(&FilterSlotNP, nullptr);
52 }
53 
54 void INDI::FilterInterface::processFilterSlot(const char *deviceName, double values[], char *names[])
55 {
56  TargetFilter = values[0];
57 
58  INumber *np = IUFindNumber(&FilterSlotNP, names[0]);
59 
60  if (!np)
61  {
63  DEBUGFDEVICE(deviceName, Logger::DBG_ERROR, "Unknown error. %s is not a member of %s property.", names[0],
65  IDSetNumber(&FilterSlotNP, nullptr);
66  return;
67  }
68 
70  {
72  DEBUGFDEVICE(deviceName, Logger::DBG_ERROR, "Error: valid range of filter is from %g to %g", FilterSlotN[0].min,
73  FilterSlotN[0].max);
74  IDSetNumber(&FilterSlotNP, nullptr);
75  return;
76  }
77 
79  DEBUGFDEVICE(deviceName, Logger::DBG_SESSION, "Setting current filter to slot %d", TargetFilter);
80 
81  if (SelectFilter(TargetFilter) == false)
82  {
84  }
85 
86  IDSetNumber(&FilterSlotNP, nullptr);
87  return;
88 }
89 
90 void INDI::FilterInterface::processFilterName(const char *deviceName, char *texts[], char *names[], int n)
91 {
93  IUUpdateText(FilterNameTP, texts, names, n);
94 
95  if (SetFilterNames() == true)
96  IDSetText(FilterNameTP, nullptr);
97  else
98  {
100  DEBUGDEVICE(deviceName, Logger::DBG_ERROR, "Error updating names of filters.");
101  IDSetText(FilterNameTP, nullptr);
102  }
103 }
void processFilterSlot(const char *deviceName, double values[], char *names[])
Process client request to change filter position. Call this function in the filter wheel implementati...
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL...
Definition: indidriver.c:545
void IDSetText(const ITextVectorProperty *t, const char *msg,...)
Tell client to update an existing text vector property.
Definition: indidriver.c:1796
void SelectFilterDone(int newpos)
The child class calls this function when the hardware successfully finished selecting a new filter wh...
#define DEBUGDEVICE(device, priority, msg)
Definition: indilogger.h:59
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
Definition: indidriver.c:319
One number descriptor.
Definition: indiapi.h:246
virtual bool SelectFilter(int position)=0
Select a new filter position.
INumberVectorProperty FilterSlotNP
double max(void)
void processFilterName(const char *deviceName, char *texts[], char *names[], int n)
Process client request to change filter name(s). Call this function in the filter wheel implementatio...
Definition: indiapi.h:157
void IDSetNumber(const INumberVectorProperty *n, const char *msg,...)
Tell client to update an existing number vector property.
Definition: indidriver.c:1838
ITextVectorProperty * FilterNameTP
char name[MAXINDINAME]
Definition: indiapi.h:294
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL...
Definition: indidriver.c:420
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition: indicom.c:1234
void initFilterProperties(const char *deviceName, const char *groupName)
Initilize filter wheel properties. It is recommended to call this function within initProperties() of...
virtual bool SetFilterNames()=0
Set filter names as defined by the client for each filter position. The desired filter names are stor...
struct _ITextVectorProperty ITextVectorProperty
double min(void)
#define DEBUGFDEVICE(device, priority, msg,...)
Definition: indilogger.h:60
double value
Definition: indiapi.h:261