Class BabelSimpleChainableLedsRGBDemo
- All Implemented Interfaces:
BabelDemo
This is the stripped-down counterpart of BabelChainableLedsRGBDemo.
Where the fuller demo keeps a per-LED colour buffer and pushes the whole strip
in one batched request, this one carries no per-LED state: on each tick it
computes one colour and sends a separate SetChainableLEDColorRGBRequest
for every LED position. Read this first to see the bare register-then-drive
loop, then read the fuller demo to see the batched variant.
Devices & control protocols used. One Grove chainable
RGB LED strip (DeviceType.GROVE_CHAINABLE_RGB), driven through the
DigitalOutputControlProtocol (protocol id 2300).
The teaching point. The app never touches Pi4J or GPIO. It
registers the device, keeps the returned DeviceHandle, and drives the
strip purely by sending Babel requests; the control protocol does the GPIO
bit-banging.
To run: java -jar <jar> simpleLedsRGB (see
Main.java).
Configuration. The strip length is read from the
rgb.led.count property (via
DigitalOutputControlProtocol.RGB_LED_COUNT, default 1) and the GPIO
data line from led.line (default 24) — both in
paradigmshift.config.
Based on IoT-control demos originally developed at NOVA FCT for the TaRDIS project; provided and evolved independently by ParadigmShift.
-
Nested Class Summary
Nested classes/interfaces inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
pt.unl.fct.di.novasys.babel.core.GenericProtocol.ProtocolMetricsBabelMetrics -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfig key naming the GPIO data line the LED strip is wired to.static final StringDefault GPIO line (BCM 24) — coexists with a seated LoRa HAT.static final StringHuman-readable name we register the strip under, then verify in the reply.Fields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
babel, babelSecurityFields inherited from interface pt.unl.fct.di.tardis.babel.iot.demos.BabelDemo
PROTO_ID, PROTO_NAME -
Constructor Summary
ConstructorsConstructorDescriptionSets the protocol identity shared by all demos (BabelDemo.PROTO_NAME/BabelDemo.PROTO_ID). -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Entry point for this demo (called fromMain).voidhandleDemoTimer(DemoTimer t, long time) Periodic-timer handler: each tick simply advances the colour by repainting the strip.voidhandleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId) Reply handler for the device registration.voidinit(Properties props) Wires this protocol's event handlers and starts device registration.Methods inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
addSecret, addSecret, addSecret, addSecret, cancelTimer, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, createChannel, createSecureChannel, createSecureChannel, createSecureChannel, createSecureChannelWithAliases, createSecureChannelWithAliases, createSecureChannelWithIdentities, createSecureChannelWithIdentities, createSecureChannelWithProtoIdentities, enableGenericMetrics, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateSecret, generateSecret, generateSecret, generateSecret, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, getChannelOrThrow, getDefaultChannel, getDefaultProtoIdentity, getDefaultProtoIdentityCrypt, getDefaultProtoSecret, getMillisSinceBabelStart, getOrGenerateDefaultProtoIdentity, getProtoId, getProtoName, hasProtocolThreadStarted, openConnection, openConnection, openConnection, openConnection, registerChannelEventHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageSerializer, registerMetric, registerReplyHandler, registerRequestHandler, registerSharedChannel, registerTimerHandler, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendReply, sendRequest, setDefaultChannel, setDefaultProtoIdentity, setDefaultProtoIdentity, setDefaultProtoSecret, setupPeriodicTimer, setupTimer, startEventThread, subscribeNotification, triggerNotification, unsubscribeNotification
-
Field Details
-
LED_PORT
Config key naming the GPIO data line the LED strip is wired to.- See Also:
-
LED_PORT_DEFAULT
Default GPIO line (BCM 24) — coexists with a seated LoRa HAT.- See Also:
-
ledAlias
Human-readable name we register the strip under, then verify in the reply.- See Also:
-
-
Constructor Details
-
BabelSimpleChainableLedsRGBDemo
public BabelSimpleChainableLedsRGBDemo()Sets the protocol identity shared by all demos (BabelDemo.PROTO_NAME/BabelDemo.PROTO_ID). Babel handlers are wired later ininit(Properties).
-
-
Method Details
-
init
public void init(Properties props) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException Wires this protocol's event handlers and starts device registration.The reply and timer handlers are registered before the request is sent, so the
RegisterIoTDeviceReplycannot arrive before its handler is in place. We then ask theDigitalOutputControlProtocolto register a chainable RGB strip ondeviceLine; the handle comes back asynchronously inhandleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply, short).- Specified by:
initin classpt.unl.fct.di.novasys.babel.core.GenericProtocol- Throws:
pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationExceptionIOException
-
handleDemoTimer
Periodic-timer handler: each tick simply advances the colour by repainting the strip. Babel calls this on its event loop once the timer is armed inhandleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply, short). -
handleRegisterIoTDeviceReply
public void handleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId) Reply handler for the device registration. Babel routes theRegisterIoTDeviceReplyhere once the control protocol has claimed the hardware.The pattern: check
RegisterIoTDeviceReply.isSuccessful(); on failure, bail out. On success, keep theDeviceHandle(our only reference to the strip), paint an initial frame, and arm the periodic timer that drives the colour sweep. The alias check guards against a mismatched reply. -
execute
Entry point for this demo (called fromMain). Bootstraps Babel: grab theBabelsingleton, loadparadigmshift.config, instantiate the one control protocol this demo needs (DigitalOutputControlProtocol), register it plus this demo,initthem in dependency order (control protocol first so its handlers exist before we send to it), then start the event loop.
-