Last active
November 22, 2015 14:10
-
-
Save ajurasz/f50837631a74e2c34956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static class ScannerRoute extends RouteBuilder { | |
@Override | |
public void configure() throws Exception { | |
from("bluetooth://scan?consumer.delay=1000") | |
.to("pi4j-gpio://1?mode=DIGITAL_OUTPUT&state=LOW&action=BLINK") | |
.choice() | |
.when(deviceWithName(DEVICE_NAME)) | |
.process(p -> p.getIn().setHeader(DEVICE_FOUND, true)) | |
.otherwise() | |
.process(p -> p.getIn().setHeader(DEVICE_NOT_FOUND, true)) | |
.end() | |
.multicast().to("direct:green", "direct:red"); | |
from("direct:green") | |
.process(exchange -> checkHeaderAndSetAction(DEVICE_FOUND, exchange)) | |
.to("pi4j-gpio://2?mode=DIGITAL_OUTPUT&state=LOW"); | |
from("direct:red") | |
.process(exchange -> checkHeaderAndSetAction(DEVICE_NOT_FOUND, exchange)) | |
.to("pi4j-gpio://3?mode=DIGITAL_OUTPUT&state=LOW"); | |
} | |
private void checkHeaderAndSetAction(String headerKey, Exchange exchange) { | |
if (exchange.getIn().getHeader(headerKey) != null) { | |
exchange.getIn().setHeader(Pi4jConstants.CAMEL_RBPI_PIN_ACTION, GPIOAction.HIGH); | |
} else { | |
exchange.getIn().setHeader(Pi4jConstants.CAMEL_RBPI_PIN_ACTION, GPIOAction.LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment