Class BabelMatrixDemo

java.lang.Object
pt.unl.fct.di.novasys.babel.core.GenericProtocol
pt.unl.fct.di.tardis.babel.iot.demos.BabelMatrixDemo
All Implemented Interfaces:
BabelDemo

public class BabelMatrixDemo extends pt.unl.fct.di.novasys.babel.core.GenericProtocol implements BabelDemo
Demo that cycles a sequence of images on the Grove RGB LED matrix: it spells out "TARDIS" letter by letter, then randomly alternates between built-in emojis, built-in animations, and another pass of the "TARDIS" spelling.

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 by LedMatrixUtils from a character);
  • ShowEmojiRequest / ShowAnimationRequest — built-in Emoji / Animation catalogue 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, babelSecurity

    Fields inherited from interface pt.unl.fct.di.tardis.babel.iot.demos.BabelDemo

    PROTO_ID, PROTO_NAME
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sets the protocol identity Babel uses to route events here and seeds the randomness.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Application bootstrap (the entry point Main calls for the LedMatrix demo).
    void
    handleDemoTimer(DemoTimer t, long time)
    Timer handler that paints one frame and reschedules itself.
    void
    handleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId)
    Reply handler for the device registration: keeps the matrix DeviceHandle and kicks off the animation loop.
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 in init(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 RegisterIoTDeviceReply handler that brings back the matrix's DeviceHandle, and only then send the RegisterIoTDeviceRequest to the I²C output protocol (2000). The reply handler must exist before the request is sent.

      Specified by:
      init in class pt.unl.fct.di.novasys.babel.core.GenericProtocol
      Throws:
      pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
      IOException
    • handleDemoTimer

      public void handleDemoTimer(DemoTimer t, long time)
      Timer handler that paints one frame and reschedules itself. While sequencePosition >= 0 it 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-shot DemoTimer sized 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 matrix DeviceHandle and kicks off the animation loop. Always checks RegisterIoTDeviceReply.isSuccessful() and verifies the alias before trusting the handle, then paints an initial green fill and arms the first DemoTimer that drives handleDemoTimer(pt.unl.fct.di.tardis.babel.iot.demos.events.DemoTimer, long).
    • execute

      public void execute() throws Exception
      Application bootstrap (the entry point Main calls for the LedMatrix demo). Standard Babel start-up: get the Babel singleton, load config, instantiate the one control protocol it needs (I2COutputControlProtocol), register both protocols, init them in dependency order (controller before demo), then b.start() to enter the event loop.
      Specified by:
      execute in interface BabelDemo
      Throws:
      Exception