1 | /******************************************************************************* |
---|
2 | Copyright(c) 2010 Gerry Rozema. All rights reserved. |
---|
3 | |
---|
4 | This program is free software; you can redistribute it and/or modify it |
---|
5 | under the terms of the GNU General Public License as published by the Free |
---|
6 | Software Foundation; either version 2 of the License, or (at your option) |
---|
7 | any later version. |
---|
8 | |
---|
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
12 | more details. |
---|
13 | |
---|
14 | You should have received a copy of the GNU General Public License along with |
---|
15 | this program; if not, write to the Free Software Foundation, Inc., 59 |
---|
16 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | |
---|
18 | The full GNU General Public License is included in this distribution in the |
---|
19 | file called LICENSE. |
---|
20 | *******************************************************************************/ |
---|
21 | |
---|
22 | #include "indifilterwheel.h" |
---|
23 | |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | INDI::FilterWheel::FilterWheel() |
---|
27 | { |
---|
28 | //ctor |
---|
29 | MaxFilter=12; |
---|
30 | } |
---|
31 | |
---|
32 | INDI::FilterWheel::~FilterWheel() |
---|
33 | { |
---|
34 | //dtor |
---|
35 | } |
---|
36 | |
---|
37 | bool INDI::FilterWheel::initProperties() |
---|
38 | { |
---|
39 | DefaultDriver::initProperties(); // let the base class flesh in what it wants |
---|
40 | |
---|
41 | IUFillNumber(&FilterSlotN[0],"FILTER_SLOT_VALUE","Filter","%3.0f",1.0,12.0,1.0,1.0); |
---|
42 | IUFillNumberVector(&FilterSlotNV,FilterSlotN,1,deviceName(),"FILTER_SLOT","Filter","Main Control",IP_RW,60,IPS_IDLE); |
---|
43 | |
---|
44 | IUFillText(&FilterNameT[0],"FILTER1","1",""); |
---|
45 | IUFillText(&FilterNameT[1],"FILTER2","2",""); |
---|
46 | IUFillText(&FilterNameT[2],"FILTER3","3",""); |
---|
47 | IUFillText(&FilterNameT[3],"FILTER4","4",""); |
---|
48 | IUFillText(&FilterNameT[4],"FILTER5","5",""); |
---|
49 | IUFillText(&FilterNameT[5],"FILTER6","6",""); |
---|
50 | IUFillText(&FilterNameT[6],"FILTER7","7",""); |
---|
51 | IUFillText(&FilterNameT[7],"FILTER8","8",""); |
---|
52 | IUFillText(&FilterNameT[8],"FILTER9","9",""); |
---|
53 | IUFillText(&FilterNameT[9],"FILTER10","10",""); |
---|
54 | IUFillText(&FilterNameT[10],"FILTER11","11",""); |
---|
55 | IUFillText(&FilterNameT[11],"FILTER12","12",""); |
---|
56 | IUFillTextVector(&FilterNameTV,FilterNameT,12,deviceName(),"FILTER_NAME","Filter","Filters",IP_RW,60,IPS_IDLE); |
---|
57 | |
---|
58 | return 0; |
---|
59 | } |
---|
60 | |
---|
61 | void INDI::FilterWheel::ISGetProperties (const char *dev) |
---|
62 | { |
---|
63 | // First we let our parent populate |
---|
64 | //IDLog("INDI::FilterWheel::ISGetProperties %s\n",dev); |
---|
65 | DefaultDriver::ISGetProperties(dev); |
---|
66 | if(isConnected()) |
---|
67 | { |
---|
68 | defineNumber(&FilterSlotNV); |
---|
69 | defineText(&FilterNameTV); |
---|
70 | } |
---|
71 | return; |
---|
72 | } |
---|
73 | |
---|
74 | bool INDI::FilterWheel::updateProperties() |
---|
75 | { |
---|
76 | // Define more properties after we are connected |
---|
77 | // first we want to update the values to reflect our actual wheel |
---|
78 | |
---|
79 | if(isConnected()) |
---|
80 | { |
---|
81 | IUFillNumber(&FilterSlotN[0],"FILTER_SLOT_VALUE","Filter","%3.0f",MinFilter,MaxFilter,1.0,CurrentFilter); |
---|
82 | defineNumber(&FilterSlotNV); |
---|
83 | IUFillTextVector(&FilterNameTV,FilterNameT,MaxFilter,deviceName(),"FILTER_NAME","Filter","Filters",IP_RW,60,IPS_IDLE); |
---|
84 | defineText(&FilterNameTV); |
---|
85 | //LoadFilterNames(); |
---|
86 | } else |
---|
87 | { |
---|
88 | deleteProperty(FilterSlotNV.name); |
---|
89 | deleteProperty(FilterNameTV.name); |
---|
90 | } |
---|
91 | |
---|
92 | return true; |
---|
93 | } |
---|
94 | |
---|
95 | bool INDI::FilterWheel::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) |
---|
96 | { |
---|
97 | // first check if it's for our device |
---|
98 | //IDLog("INDI::FilterWheel::ISNewNumber %s\n",name); |
---|
99 | if(strcmp(dev,deviceName())==0) { |
---|
100 | // This is for our device |
---|
101 | // Now lets see if it's something we process here |
---|
102 | |
---|
103 | if(strcmp(name,"FILTER_SLOT")==0) { |
---|
104 | |
---|
105 | int f; |
---|
106 | |
---|
107 | f=-1; |
---|
108 | for(int x=0; x<n; x++) { |
---|
109 | if(strcmp(names[x],"FILTER_SLOT_VALUE")==0) { |
---|
110 | // This is the new filter number we are being asked |
---|
111 | // to set as active |
---|
112 | f=values[x]; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | if(f != -1) { |
---|
117 | //IDLog("Filter wheel got a filter slot change\n"); |
---|
118 | // tell the client we are busy changing the filter |
---|
119 | FilterSlotNV.s=IPS_BUSY; |
---|
120 | IDSetNumber(&FilterSlotNV,NULL); |
---|
121 | // Tell the hardware to change |
---|
122 | SelectFilter(f); |
---|
123 | // tell the caller we processed this |
---|
124 | return true; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | // if we didn't process it, continue up the chain, let somebody else |
---|
129 | // give it a shot |
---|
130 | return DefaultDriver::ISNewNumber(dev,name,values,names,n); |
---|
131 | } |
---|
132 | |
---|
133 | bool INDI::FilterWheel::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) |
---|
134 | { |
---|
135 | // Ok, lets see if this is a property wer process |
---|
136 | //IDLog("INDI::FilterWheel got %d new text items name %s\n",n,name); |
---|
137 | // first check if it's for our device |
---|
138 | if(strcmp(dev,deviceName())==0) { |
---|
139 | // This is for our device |
---|
140 | // Now lets see if it's something we process here |
---|
141 | if(strcmp(name,FilterNameTV.name)==0) { |
---|
142 | // This is our port, so, lets process it |
---|
143 | |
---|
144 | // Some clients insist on sending a port |
---|
145 | // and they may not be configured for the |
---|
146 | // correct port |
---|
147 | // If we are already connected |
---|
148 | // and running, it makes absolutely no sense |
---|
149 | // to accept a new port value |
---|
150 | // so lets just lie to them and say |
---|
151 | // we did this, but, dont actually change anything |
---|
152 | //if(Connected) return true; |
---|
153 | |
---|
154 | int rc; |
---|
155 | //IDLog("calling update text\n"); |
---|
156 | FilterNameTV.s=IPS_OK; |
---|
157 | rc=IUUpdateText(&FilterNameTV,texts,names,n); |
---|
158 | //IDLog("update text returns %d\n",rc); |
---|
159 | // Update client display |
---|
160 | IDSetText(&FilterNameTV,NULL); |
---|
161 | //SaveConfig(); |
---|
162 | |
---|
163 | // We processed this one, so, tell the world we did it |
---|
164 | return true; |
---|
165 | } |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | return DefaultDriver::ISNewText(dev,name,texts,names,n); |
---|
170 | } |
---|
171 | |
---|
172 | int INDI::FilterWheel::SelectFilterDone(int f) |
---|
173 | { |
---|
174 | // The hardware has finished changing |
---|
175 | // filters |
---|
176 | FilterSlotN[0].value=f; |
---|
177 | FilterSlotNV.s=IPS_OK; |
---|
178 | // Tell the clients we are done, and |
---|
179 | // filter is now useable |
---|
180 | IDSetNumber(&FilterSlotNV,NULL); |
---|
181 | return 0; |
---|
182 | } |
---|
183 | |
---|
184 | int INDI::FilterWheel::SelectFilter(int) |
---|
185 | { |
---|
186 | return -1; |
---|
187 | } |
---|
188 | |
---|
189 | int INDI::FilterWheel::QueryFilter() |
---|
190 | { |
---|
191 | return -1; |
---|
192 | } |
---|
193 | |
---|
194 | |
---|