Esempio n. 1
0
 def get_node(self) -> BusNode:
     """
     Subclasses MUST override and ``super()`` this method.
     Returns a ``BusNode`` representing the device and all its properties.
     """
     return BusNode(
         name=self.name,
         type=self.device,
         properties={"address": BusProperty(name="Address")},
     )
Esempio n. 2
0
 def get_node(self) -> BusNode:
     """
     Returns a ``BusNode`` representing this array.
     """
     return BusNode(
         name=self._name,
         type="LED Array",
         properties={
             "animation": BusProperty(
                 name="Animation", settable=True, callback="anim_message"
             ),
             "count": BusProperty(name="LED Count", datatype=DataType.INT),
             "leds-per-pixel": BusProperty(
                 name="LEDs per Pixel", datatype=DataType.INT
             ),
             "fps": BusProperty(name="Frames per second", datatype=DataType.INT),
         },
     )
Esempio n. 3
0
def load(config_raw: t.Dict[str, t.Any]) -> bool:
    """
    This function runs on the main process after the module is imported. It should parse
    and validate the configuration and create any dynamic nodes or properties. Do not start
    any threads or long running tasks here, they should go in the ``start`` function.
    Limit memory usage here as much as possible.
    """
    config_data = parse_config(config_raw, CONF_OPTIONS, log)
    del config_raw
    if config_data:
        log.debug("Config loaded successfully")
        CONFIG.update(config_data)
        del config_data
        # verify config

        # generate dynamic nodes
        nodes["my-node"] = BusNode(
            name="My Node",
            type="module",
            properties={
                # This property is a string type that this module can publish to
                "my-property":
                BusProperty(name="Read-Only Property"),
                # This property is an integer that outside systems can set
                "my-writable-property":
                BusProperty(
                    name="Writable Property",
                    datatype=DataType.INT,
                    settable=True,
                    # This function will be called when a message arrives. Topic/path
                    # matching depends on the communication module.
                    # Must be a string, object references do not cross process borders
                    # Don't forget to import it in the package '__init__.py' as it will
                    # be called by name as 'interface_pkg_template.message_callback'
                    callback="message_callback",
                ),
            },
        )

        return True
    else:
        log.error("Error loading config")
        return False
Esempio n. 4
0
                "selection": {}
            },
        },
    ),
])

log = logger.get_logger("gpio")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "gpio":
    BusNode(
        name="GPIO",
        type="Module",
        properties={
            "poll-all":
            BusProperty(name="Poll All Pins",
                        settable=True,
                        callback="poll_message"),
            "polling-interval":
            BusProperty(name="Polling Interval",
                        datatype=DataType.FLOAT,
                        unit="s"),
            # from pin.digital
            "pulse":
            BusProperty(name="Pulse", settable=True, callback="pulse_message"),
        },
    )
}
Esempio n. 5
0
    ]
)

log = logger.get_logger("i2c")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "i2c":
    BusNode(
        name="I2C",
        type="Module",
        properties={
            "poll-all":
            BusProperty(name="Poll All",
                        settable=True,
                        callback="poll_message"),
            "polling-interval":
            BusProperty(name="Polling Interval",
                        datatype=DataType.INT,
                        unit="s"),
        },
    )
}


def validateAddress(address: t.Any) -> t.Union[int, None]:
    """
    Validates I2C address.
    Returns ``None`` if address is invalid.
    """
    if not isinstance(address, int):
Esempio n. 6
0
        "type": list
    }),
])

log = logger.get_logger("xset")
CONFIG: t.Dict[str, t.Any] = {}

publish_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
subscribe_queue: "mproc.Queue[BusMessage]" = None  # type: ignore
nodes: t.Dict[str, BusNode] = {
    "xset":
    BusNode(
        name="XSET",
        type="Module",
        properties={
            "command": BusProperty(name="XSET Command", settable=True),
            "stdout": BusProperty(name="stdout"),
            "stderr": BusProperty(name="stderr"),
        },
    )
}


def load(config_raw: t.Dict[str, t.Any] = {}) -> bool:
    """
    Initializes the module
    """
    config_data = parse_config(config_raw, CONF_OPTIONS, log)
    del config_raw
    if config_data:
        log.debug("Config loaded")