Class BabelMatrixDemo
- All Implemented Interfaces:
BabelDemo
It drives a single output device — the LED matrix — through
I2COutputControlProtocol (id 2000). The matrix is an I²C peripheral,
so RegisterIoTDeviceRequest carries only a device type and an alias
(no GPIO line). Once registered, the demo paints frames with three typed
requests served by that protocol:
ShowDisplayRequest— a raw 8×8 colour bitmap (here built byLedMatrixUtilsfrom a character);ShowEmojiRequest/ShowAnimationRequest— built-inEmoji/Animationcatalogue entries;SetDisplayColorRequest— fills the whole panel with one colour.
The Babel concept on show is a self-rescheduling one-shot timer: each
frame arms a fresh DemoTimer with its own delay (a long animation gets
more time than a static glyph), so the cadence adapts to what was just shown.
Contrast this with the fixed-rate setupPeriodicTimer used by the LCD
demo.
The application never touches Pi4J or the I²C bus directly — it only sends
Babel requests; I2COutputControlProtocol does the hardware work.
Run with the LedMatrix command-line name (see Main).
-
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
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 Babel uses to route events here and seeds the randomness. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Application bootstrap (the entry pointMaincalls for theLedMatrixdemo).voidhandleDemoTimer(DemoTimer t, long time) Timer handler that paints one frame and reschedules itself.voidhandleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId) Reply handler for the device registration: keeps the matrixDeviceHandleand kicks off the animation loop.voidinit(Properties props) Babel lifecycle hook: register handlers, then request the device.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
-
Constructor Details
-
BabelMatrixDemo
public BabelMatrixDemo()Sets the protocol identity Babel uses to route events here and seeds the randomness. No hardware is touched yet — registration happens ininit(java.util.Properties).
-
-
Method Details
-
init
public void init(Properties props) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException Babel lifecycle hook: register handlers, then request the device.Canonical IoT bootstrap, in order: register the timer handler that will paint frames, register the
RegisterIoTDeviceReplyhandler that brings back the matrix'sDeviceHandle, and only then send theRegisterIoTDeviceRequestto the I²C output protocol (2000). The reply handler must exist before the request is sent.- Specified by:
initin classpt.unl.fct.di.novasys.babel.core.GenericProtocol- Throws:
pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationExceptionIOException
-
handleDemoTimer
Timer handler that paints one frame and reschedules itself. WhilesequencePosition >= 0it spells the next "TARDIS" letter (with a randomly chosen glyph encoding); once the word is done it flips to the random emoji/animation/respell branch. Each branch arms a new one-shotDemoTimersized to how long that frame should linger — the adaptive-cadence pattern this demo illustrates. -
handleRegisterIoTDeviceReply
public void handleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId) Reply handler for the device registration: keeps the matrixDeviceHandleand kicks off the animation loop. Always checksRegisterIoTDeviceReply.isSuccessful()and verifies the alias before trusting the handle, then paints an initial green fill and arms the firstDemoTimerthat driveshandleDemoTimer(pt.unl.fct.di.tardis.babel.iot.demos.events.DemoTimer, long). -
execute
Application bootstrap (the entry pointMaincalls for theLedMatrixdemo). Standard Babel start-up: get theBabelsingleton, load config, instantiate the one control protocol it needs (I2COutputControlProtocol), register both protocols,initthem in dependency order (controller before demo), thenb.start()to enter the event loop.
-