Instrument Neutral Distributed Interface INDI  2.0.2
manual_filter.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2018 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 
19 #include "manual_filter.h"
20 
21 #include <memory>
22 #include <cstring>
23 
24 // We declare an auto pointer to ManualFilter.
25 static std::unique_ptr<ManualFilter> manual_filter(new ManualFilter());
26 
28 {
29  return static_cast<const char *>("Manual Filter");
30 }
31 
32 void ManualFilter::ISGetProperties(const char *dev)
33 {
35 
36  defineProperty(&MaxFiltersNP);
37 }
38 
40 {
42 
43  // User Set Filter
44  IUFillSwitch(&FilterSetS[0], "FILTER_SET", "Filter is set", ISS_OFF);
45  IUFillSwitchVector(&FilterSetSP, FilterSetS, 1, getDeviceName(), "CONFIRM_FILTER_SET", "Confirm", MAIN_CONTROL_TAB, IP_RW,
46  ISR_ATMOST1, 60, IPS_IDLE);
47 
48  // Sync Filter Position. Sets current position to different position without actually changing filter.
49  IUFillNumber(&SyncN[0], "TARGET_FILTER", "Target Filter", "%.f", 1, 16, 1, 0);
50  IUFillNumberVector(&SyncNP, SyncN, 1, getDeviceName(), "SYNC_FILTER", "Sync", MAIN_CONTROL_TAB, IP_WO, 60, IPS_IDLE);
51 
52  // Max number of filters
53  double maxFilters = 5;
54  IUGetConfigNumber(getDeviceName(), "MAX_FILTERS", "MAX", &maxFilters);
55  // If names are already loaded, then we ignore all and use this instead.
56  if (FilterNameT)
57  maxFilters = FilterNameTP->ntp;
58  FilterSlotN[0].max = maxFilters;
59  IUFillNumber(&MaxFiltersN[0], "MAX", "Filters", "%.f", 1, 16, 1, maxFilters);
60  IUFillNumberVector(&MaxFiltersNP, MaxFiltersN, 1, getDeviceName(), "MAX_FILTERS", "Max.", MAIN_CONTROL_TAB, IP_RW, 60,
61  IPS_IDLE);
62 
63  return true;
64 }
65 
67 {
69 
70  if (isConnected())
71  {
72  deleteProperty(MaxFiltersNP.name);
73 
74  defineProperty(&SyncNP);
75  defineProperty(&FilterSetSP);
76  }
77  else
78  {
79  deleteProperty(SyncNP.name);
80  deleteProperty(FilterSetSP.name);
81 
82  defineProperty(&MaxFiltersNP);
83  }
84 
85  return true;
86 }
87 
88 bool ManualFilter::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
89 {
90  if (!strcmp(dev, getDeviceName()))
91  {
92  if (!strcmp(name, SyncNP.name))
93  {
94  IUUpdateNumber(&SyncNP, values, names, n);
95  CurrentFilter = SyncN[0].value;
96  FilterSlotN[0].value = CurrentFilter;
97  IDSetNumber(&FilterSlotNP, nullptr);
98  SyncNP.s = IPS_OK;
99  IDSetNumber(&SyncNP, nullptr);
100 
101  LOGF_INFO("Filter wheel is synced to slot %d", CurrentFilter);
102 
103  return true;
104  }
105  else if (!strcmp(MaxFiltersNP.name, name))
106  {
107  IUUpdateNumber(&MaxFiltersNP, values, names, n);
108  FilterSlotN[0].max = MaxFiltersN[0].value;
109  MaxFiltersNP.s = IPS_OK;
110  saveConfig(true, MaxFiltersNP.name);
111  IDSetNumber(&MaxFiltersNP, nullptr);
112 
113  return true;
114  }
115  }
116 
117  return INDI::FilterWheel::ISNewNumber(dev, name, values, names, n);
118 }
119 
120 bool ManualFilter::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
121 {
122  if (!strcmp(dev, getDeviceName()))
123  {
124  if (!strcmp(name, FilterSetSP.name))
125  {
127  FilterSetSP.s = IPS_OK;
128  IDSetSwitch(&FilterSetSP, nullptr);
129  return true;
130  }
131 
132  }
133 
134  return INDI::FilterWheel::ISNewSwitch(dev, name, states, names, n);
135 }
136 
138 {
139  return true;
140 }
141 
143 {
144  return true;
145 }
146 
148 {
149  CurrentFilter = f;
150 
151  FilterSetSP.s = IPS_BUSY;
152  IDSetSwitch(&FilterSetSP, nullptr);
153  LOGF_INFO("Please change filter to %s then click Filter is set when done.", FilterNameT[f - 1].text);
154  return true;
155 }
156 
158 {
160 
161  IUSaveConfigNumber(fp, &MaxFiltersNP);
162 
163  return true;
164 }
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
ITextVectorProperty * FilterNameTP
INumberVectorProperty FilterSlotNP
void SelectFilterDone(int newpos)
The child class calls this function when the hardware successfully finished selecting a new filter wh...
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Manual filter enables users from changing filter wheels manually.
Definition: manual_filter.h:27
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SelectFilter(int) override
Select a new filter position.
const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool Disconnect() override
Disconnect from device.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
@ IP_RW
Definition: indiapi.h:186
@ IP_WO
Definition: indiapi.h:185
@ IPS_BUSY
Definition: indiapi.h:163
@ IPS_IDLE
Definition: indiapi.h:161
@ IPS_OK
Definition: indiapi.h:162
@ ISR_ATMOST1
Definition: indiapi.h:174
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: indidevapi.c:272
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
Definition: indidevapi.c:15
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition: indidevapi.c:158
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: indidevapi.c:180
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidevapi.c:235
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
Definition: indidriver.c:1231
int IUGetConfigNumber(const char *dev, const char *property, const char *member, double *value)
IUGetConfigNumber Opens configuration file and reads single number property.
Definition: indidriver.c:831
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Definition: indidriver.c:1362
#define LOGF_INFO(fmt,...)
Definition: indilogger.h:82
char name[MAXINDINAME]
Definition: indiapi.h:323
char name[MAXINDINAME]
Definition: indiapi.h:371