... | ... | @@ -91,30 +91,28 @@ if (isBlinking) { |
|
|
```
|
|
|
if we are currently blinking, ie. alternating between red and green lights, we invert their supposed states every loop.
|
|
|
|
|
|
We then enter a `try`-block
|
|
|
We then enter a `for`-loop with a `try`/`catch`-block:
|
|
|
```java
|
|
|
for (ISubmodel light : greenLightSwitches) {
|
|
|
try {
|
|
|
if (isGreenOn) {
|
|
|
((IOperation) light.getSubmodelElement("activateLight")).invoke();
|
|
|
} else {
|
|
|
((IOperation) light.getSubmodelElement("deactivateLight")).invoke();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
For every Submodel in our list corresponding to green lights, we invoke either the activation or deactivation of said light, depending on the state we saved internally.
|
|
|
|
|
|
The same is done for the red lights, just by operating over the other list of lights.
|
|
|
|
|
|
```java
|
|
|
} catch (ResourceNotFoundException e) {
|
|
|
if (!isStale) {
|
|
|
System.out.println("Invoking a light switch failed. Lights will be updated on next update while active.");
|
|
|
logger.warn("Invoking a light switch failed. Lights will be updated on next update while active.");
|
|
|
}
|
|
|
isStale = true;
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
For every Submodel in our list corresponding to green lights, we invoke either the activation or deactivation of said light, depending on the state we saved internally.
|
|
|
If we could not successfully invoke an Operation on any saves light, a warning is issued and the lists will be updated on the next loop.
|
|
|
|
|
|
The same is done for the red lights, just by operating over the other list of lights.
|
|
|
|
|
|
```java
|
|
|
}).start();
|
|
|
```
|
... | ... | |