|
24 | 24 | /** |
25 | 25 | * A factory for creating Link objects. |
26 | 26 | */ |
27 | | -public class LinkFactory implements IHardwareSyncPulseReciver,IHardwareSyncPulseProvider { |
| 27 | +public class LinkFactory implements IHardwareSyncPulseReciver, IHardwareSyncPulseProvider { |
28 | 28 | private static HashMap<String, INewLinkProvider> userLinkProviders = new HashMap<String, INewLinkProvider>(); |
29 | 29 |
|
30 | | - |
31 | 30 | /** The links. */ |
32 | 31 | private ArrayList<AbstractLink> links = new ArrayList<AbstractLink>(); |
33 | 32 |
|
@@ -155,63 +154,66 @@ private AbstractLink getLinkLocal(LinkConfiguration c) { |
155 | 154 | AbstractLink tmp = null; |
156 | 155 | // Log.info("Loading link: "+c.getName()+" type = "+c.getTypeEnum()+" device= |
157 | 156 | // "+c.getDeviceScriptingName()); |
158 | | - |
159 | | - switch (c.getTypeEnum()) { |
160 | | - |
161 | | - case ANALOG_PRISMATIC: |
162 | | - if (getDyio(c) != null) { |
163 | | - tmp = new AnalogPrismaticLink(new AnalogInputChannel(getDyio(c).getChannel(c.getHardwareIndex())), c); |
164 | | - tmp.setUseLimits(false); |
165 | | - } |
166 | | - break; |
167 | | - case ANALOG_ROTORY: |
168 | | - if (getDyio(c) != null) { |
169 | | - tmp = new AnalogRotoryLink(new AnalogInputChannel(getDyio(c).getChannel(c.getHardwareIndex())), c); |
170 | | - tmp.setUseLimits(false); |
171 | | - } |
172 | | - break; |
173 | | - case PID_TOOL: |
174 | | - case PID: |
175 | | - if (getPid(c) != null) { |
176 | | - tmp = new PidRotoryLink(getPid(c).getPIDChannel(c.getHardwareIndex()), c, false); |
177 | | - } |
178 | | - break; |
179 | | - case PID_PRISMATIC: |
180 | | - if (getPid(c) != null) { |
181 | | - tmp = new PidPrismaticLink(getPid(c).getPIDChannel(c.getHardwareIndex()), c, false); |
182 | | - } |
183 | | - break; |
184 | | - case DUMMY: |
185 | | - case VIRTUAL: |
186 | | - String myVirtualDevName = c.getDeviceScriptingName(); |
187 | | - tmp = new PidRotoryLink(getVirtual(myVirtualDevName).getPIDChannel(c.getHardwareIndex()), c, true); |
188 | | - break; |
189 | | - case GCODE_HEATER_TOOL: |
190 | | - if (getGCODE(c) != null) { |
191 | | - tmp = getGCODE(c).getHeater(c); |
192 | | - } |
193 | | - break; |
194 | | - case GCODE_STEPPER_PRISMATIC: |
195 | | - case GCODE_STEPPER_ROTORY: |
196 | | - case GCODE_STEPPER_TOOL: |
197 | | - if (getGCODE(c) != null) { |
198 | | - tmp = getGCODE(c).getLink(c); |
199 | | - } |
200 | | - break; |
201 | | - case USERDEFINED: |
202 | | - if (userLinkProviders.containsKey(c.getTypeString())) { |
203 | | - INewLinkProvider iNewLinkProvider = userLinkProviders.get(c.getTypeString()); |
204 | | - tmp = iNewLinkProvider.generate(c); |
205 | | - if(IHardwareSyncPulseProvider.class.isInstance(iNewLinkProvider)) { |
206 | | - IHardwareSyncPulseProvider r=(IHardwareSyncPulseProvider)iNewLinkProvider; |
207 | | - r.addIHardwareSyncPulseReciver(this); |
| 157 | + try { |
| 158 | + switch (c.getTypeEnum()) { |
| 159 | + |
| 160 | + case ANALOG_PRISMATIC: |
| 161 | + if (getDyio(c) != null) { |
| 162 | + tmp = new AnalogPrismaticLink(new AnalogInputChannel(getDyio(c).getChannel(c.getHardwareIndex())), |
| 163 | + c); |
| 164 | + tmp.setUseLimits(false); |
| 165 | + } |
| 166 | + break; |
| 167 | + case ANALOG_ROTORY: |
| 168 | + if (getDyio(c) != null) { |
| 169 | + tmp = new AnalogRotoryLink(new AnalogInputChannel(getDyio(c).getChannel(c.getHardwareIndex())), c); |
| 170 | + tmp.setUseLimits(false); |
208 | 171 | } |
| 172 | + break; |
| 173 | + case PID_TOOL: |
| 174 | + case PID: |
| 175 | + if (getPid(c) != null) { |
| 176 | + tmp = new PidRotoryLink(getPid(c).getPIDChannel(c.getHardwareIndex()), c, false); |
| 177 | + } |
| 178 | + break; |
| 179 | + case PID_PRISMATIC: |
| 180 | + if (getPid(c) != null) { |
| 181 | + tmp = new PidPrismaticLink(getPid(c).getPIDChannel(c.getHardwareIndex()), c, false); |
| 182 | + } |
| 183 | + break; |
| 184 | + case DUMMY: |
| 185 | + case VIRTUAL: |
| 186 | + String myVirtualDevName = c.getDeviceScriptingName(); |
| 187 | + tmp = new PidRotoryLink(getVirtual(myVirtualDevName).getPIDChannel(c.getHardwareIndex()), c, true); |
| 188 | + break; |
| 189 | + case GCODE_HEATER_TOOL: |
| 190 | + if (getGCODE(c) != null) { |
| 191 | + tmp = getGCODE(c).getHeater(c); |
| 192 | + } |
| 193 | + break; |
| 194 | + case GCODE_STEPPER_PRISMATIC: |
| 195 | + case GCODE_STEPPER_ROTORY: |
| 196 | + case GCODE_STEPPER_TOOL: |
| 197 | + if (getGCODE(c) != null) { |
| 198 | + tmp = getGCODE(c).getLink(c); |
| 199 | + } |
| 200 | + break; |
| 201 | + case USERDEFINED: |
| 202 | + if (userLinkProviders.containsKey(c.getTypeString())) { |
| 203 | + INewLinkProvider iNewLinkProvider = userLinkProviders.get(c.getTypeString()); |
| 204 | + tmp = iNewLinkProvider.generate(c); |
| 205 | + if (IHardwareSyncPulseProvider.class.isInstance(iNewLinkProvider)) { |
| 206 | + IHardwareSyncPulseProvider r = (IHardwareSyncPulseProvider) iNewLinkProvider; |
| 207 | + r.addIHardwareSyncPulseReciver(this); |
| 208 | + } |
| 209 | + } |
| 210 | + break; |
| 211 | + default: |
| 212 | + break; |
209 | 213 | } |
210 | | - break; |
211 | | - default: |
212 | | - break; |
| 214 | + } catch (Throwable t) { |
| 215 | + t.printStackTrace(); |
213 | 216 | } |
214 | | - |
215 | 217 | if (tmp == null) { |
216 | 218 | String myVirtualDevName = c.getDeviceScriptingName(); |
217 | 219 | if (!c.isPrismatic()) { |
@@ -407,21 +409,17 @@ public void deleteLink(int i) { |
407 | 409 | getLinkConfigurations().remove(i); |
408 | 410 | } |
409 | 411 |
|
410 | | - |
411 | | - |
412 | 412 | @Override |
413 | 413 | public void sync() { |
414 | 414 | doSync(); |
415 | 415 | } |
416 | 416 |
|
417 | 417 | public VirtualGenericPIDDevice getVirtual(String myVirtualDevName) { |
418 | | - return (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(myVirtualDevName, |
419 | | - () -> { |
420 | | - VirtualGenericPIDDevice virtualGenericPIDDevice = new VirtualGenericPIDDevice(myVirtualDevName); |
421 | | - virtualGenericPIDDevice.addIHardwareSyncPulseReciver(this); |
422 | | - return virtualGenericPIDDevice; |
423 | | - }); |
| 418 | + return (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(myVirtualDevName, () -> { |
| 419 | + VirtualGenericPIDDevice virtualGenericPIDDevice = new VirtualGenericPIDDevice(myVirtualDevName); |
| 420 | + virtualGenericPIDDevice.addIHardwareSyncPulseReciver(this); |
| 421 | + return virtualGenericPIDDevice; |
| 422 | + }); |
424 | 423 | } |
425 | 424 |
|
426 | | - |
427 | 425 | } |
0 commit comments