From 47513f6a9ca96d3f6f49f48d34045ab8a32cdb35 Mon Sep 17 00:00:00 2001 From: Salvo Musumeci Date: Sat, 7 Nov 2026 17:31:25 +0000 Subject: [PATCH 1/4] feat: support Soomfon device (1500:3003) --- README.md | 1 + src/StreamDeck/DeviceManager.py | 2 + .../Devices/SoomfonStreamController.py | 139 ++++++++++++++++++ src/StreamDeck/ProductIDs.py | 2 + 4 files changed, 144 insertions(+) create mode 100644 src/StreamDeck/Devices/SoomfonStreamController.py diff --git a/README.md b/README.md index 92a6856..7e43e15 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ variants: This fork additionally supports: * Mirabox Stream Dock 293S +* Soomfon Stream Controller (XF-CN001) ## Package Installation: diff --git a/src/StreamDeck/DeviceManager.py b/src/StreamDeck/DeviceManager.py index c9fd97e..176e734 100644 --- a/src/StreamDeck/DeviceManager.py +++ b/src/StreamDeck/DeviceManager.py @@ -19,6 +19,7 @@ from .Devices.StreamDeckStudio import StreamDeckStudio from .Devices.StreamDeckXL import StreamDeckXL from .Devices.UlanziD200 import UlanziD200 +from .Devices.SoomfonStreamController import SoomfonStreamController from .ProductIDs import USBProductIDs, USBVendorIDs from .Transport import Transport from .Transport.Dummy import Dummy @@ -159,6 +160,7 @@ def _default_factory(self) -> list[StreamDeck]: (USBVendorIDs.USB_VID_ELGATO, USBProductIDs.USB_PID_STREAMDECK_PLUS_XL, StreamDeckPlusXL), (USBVendorIDs.USB_VID_MIRABOX, USBProductIDs.USB_PID_MIRABOX_STREAMDOCK_293S, Mirabox293S), (USBVendorIDs.USB_VID_ULANZI, USBProductIDs.USB_PID_ULANZI_D200, UlanziD200, 0), + (USBVendorIDs.USB_VID_SOOMFON, USBProductIDs.USB_PID_SOOMFON_STREAM_CONTROLLER, SoomfonStreamController, 0), ] streamdecks = list() diff --git a/src/StreamDeck/Devices/SoomfonStreamController.py b/src/StreamDeck/Devices/SoomfonStreamController.py new file mode 100644 index 0000000..6dff6b6 --- /dev/null +++ b/src/StreamDeck/Devices/SoomfonStreamController.py @@ -0,0 +1,139 @@ +# Python Stream Deck Library +# Released under the MIT license +# +# dean [at] fourwalledcubicle [dot] com +# www.fourwalledcubicle.com +# + +import io +import threading + +from .Mirabox293S import Mirabox293S +from .StreamDeck import ControlType +from ..Transport.Transport import TransportError + + +class SoomfonStreamController(Mirabox293S): + """ + Represents a physically attached Soomfon Stream Controller (model + XF-CN001, USB 1500:3003), a rebranded Mirabox 293S variant that speaks a + newer revision of the Mirabox protocol ("v3" in the mirajazz project). + + Differences from :class:`Mirabox293S`, verified on hardware: + + - output reports are 1024 bytes (plus report ID) instead of 512; + - key images are 95x95 JPEG; the three side-display tiles (keys 5, 11 and + 17) are 82x82 and are resized internally, so callers can keep using a + single key image format; + - the device reports distinct press and release events (byte 9 = key ID, + byte 10 = state), so no press/release emulation is needed; + - a ``CONNECT`` heartbeat is sent periodically while the deck is open. + + The deck exposes two HID interfaces under the same VID/PID; only + interface 0 speaks the deck protocol (interface 1 is a keyboard), see + the interface filter in :class:`DeviceManager`. + """ + + DECK_TYPE = "Soomfon Stream Controller" + + PACKET_LENGHT = 1024 + INPUT_REPORT_LENGTH = 512 + + KEY_PIXEL_WIDTH = 95 + KEY_PIXEL_HEIGHT = 95 + + SIDE_KEYS = (5, 11, 17) + SIDE_KEY_PIXEL_SIZE = 82 + + HEARTBEAT_INTERVAL = 8.0 + + _CMD_PREFIX = [0x43, 0x52, 0x54, 0x00, 0x00] # "CRT\0\0" + _CMD_CONNECT = _CMD_PREFIX + [0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54] # "CONNECT" + _CMD_STP = _CMD_PREFIX + [0x53, 0x54, 0x50] # "STP" + + def __init__(self, device): + super().__init__(device) + self._heartbeat_stop = threading.Event() + self._heartbeat_thread = None + + def _make_payload_for_report_id(self, report_id, payload_data): + payload = bytearray(self.PACKET_LENGHT + 1) + payload[0] = report_id + payload[1:1 + len(payload_data)] = payload_data + return payload + + def _send_command(self, command): + self.device.write(self._make_payload_for_report_id(0x00, command)) + + def _read_control_states(self): + data = self.device.read(self.INPUT_REPORT_LENGTH) + if not data or bytes(data[:3]) != b"ACK": + return None + + key_id, state = data[9], data[10] + if key_id not in self.KEY_DEVICE_KEY_ID_TO_NUM: + return None + + states = list(self.last_key_states) + states[self._convert_device_key_id_to_key_num(key_id)] = bool(state) + return {ControlType.KEY: states} + + def reset(self): + with self.update_lock: + super().reset() + self._send_command(self._CMD_STP) + + def _blank_image(self, size): + from PIL import Image + + with io.BytesIO() as buffer: + Image.new("RGB", (size, size), "black").save(buffer, "JPEG", quality=90) + return buffer.getvalue() + + def _fit_image(self, image, size): + from PIL import Image + + decoded = Image.open(io.BytesIO(image)) + if decoded.size == (size, size): + return image + + with io.BytesIO() as buffer: + decoded.convert("RGB").resize((size, size), Image.LANCZOS).save(buffer, "JPEG", quality=90) + return buffer.getvalue() + + def set_key_image(self, key, image): + if min(max(key, 0), self.KEY_COUNT - 1) != key: + raise IndexError("Invalid key index {}.".format(key)) + + size = self.SIDE_KEY_PIXEL_SIZE if key in self.SIDE_KEYS else self.KEY_PIXEL_WIDTH + image = self._fit_image(bytes(image), size) if image else self._blank_image(size) + + # Keep the BAT/data/STP sequence atomic with respect to the heartbeat. + with self.update_lock: + super().set_key_image(key, image) + + def _heartbeat_worker(self): + while not self._heartbeat_stop.wait(self.HEARTBEAT_INTERVAL): + try: + with self.update_lock: + self._send_command(self._CMD_CONNECT) + except TransportError: + # Device temporarily unavailable (e.g. host suspend); the read + # thread handles reconnection, keep trying until close(). + pass + + def open(self, resume_from_suspend: bool = True) -> None: + super().open(resume_from_suspend) + self._heartbeat_stop.clear() + if self._heartbeat_thread is None or not self._heartbeat_thread.is_alive(): + self._heartbeat_thread = threading.Thread( + target=self._heartbeat_worker, name="SoomfonHeartbeat", daemon=True + ) + self._heartbeat_thread.start() + + def close(self) -> None: + self._heartbeat_stop.set() + if self._heartbeat_thread is not None and self._heartbeat_thread is not threading.current_thread(): + self._heartbeat_thread.join(timeout=self.HEARTBEAT_INTERVAL) + self._heartbeat_thread = None + super().close() diff --git a/src/StreamDeck/ProductIDs.py b/src/StreamDeck/ProductIDs.py index e0a158a..7b4b98c 100644 --- a/src/StreamDeck/ProductIDs.py +++ b/src/StreamDeck/ProductIDs.py @@ -14,6 +14,7 @@ class USBVendorIDs: USB_VID_ELGATO = 0x0fd9 USB_VID_MIRABOX = 0x5548 USB_VID_ULANZI = 0x2207 + USB_VID_SOOMFON = 0x1500 class USBProductIDs: @@ -42,3 +43,4 @@ class USBProductIDs: USB_PID_MIRABOX_STREAMDOCK_293S = 0x6670 USB_PID_ULANZI_D200 = 0x0019 + USB_PID_SOOMFON_STREAM_CONTROLLER = 0x3003 From fd1f73c8106af5fc1486eed6a9ecad984c446a99 Mon Sep 17 00:00:00 2001 From: Salvo Musumeci Date: Sat, 7 Nov 2026 17:46:58 +0000 Subject: [PATCH 2/4] docs: add Soomfon Stream Controller device page --- doc/source/modules/devices.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/source/modules/devices.rst b/doc/source/modules/devices.rst index 7dc603e..14b2d1d 100644 --- a/doc/source/modules/devices.rst +++ b/doc/source/modules/devices.rst @@ -92,6 +92,15 @@ Mirabox Stream Dock 293S :show-inheritance: +========================= +Soomfon Stream Controller +========================= + +.. automodule:: StreamDeck.Devices.SoomfonStreamController + :members: + :show-inheritance: + + ============ Rotated Deck ============ From caad73ac8eba63f95113e2faea756f3aded9328b Mon Sep 17 00:00:00 2001 From: Salvo Musumeci Date: Sat, 7 Nov 2026 17:53:51 +0000 Subject: [PATCH 3/4] test: add example to test physical device --- doc/source/examples/soomfon.rst | 10 ++ doc/source/index.rst | 1 + src/example_soomfon.py | 192 ++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 doc/source/examples/soomfon.rst create mode 100644 src/example_soomfon.py diff --git a/doc/source/examples/soomfon.rst b/doc/source/examples/soomfon.rst new file mode 100644 index 0000000..3e85f4d --- /dev/null +++ b/doc/source/examples/soomfon.rst @@ -0,0 +1,10 @@ +*********************************************** +Example Script: Soomfon Stream Controller +*********************************************** + +The following is an example script to connect to the Soomfon Stream Controller, +print whenever its buttons are pushed and released, and use the three tiles of +its non-touch side display as a clock. + +.. literalinclude:: ../../../src/example_soomfon.py + :language: python diff --git a/doc/source/index.rst b/doc/source/index.rst index d9e9067..807b450 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -41,6 +41,7 @@ Index examples/plus.rst examples/neo.rst examples/studio.rst + examples/soomfon.rst examples/tiled.rst examples/animated.rst diff --git a/src/example_soomfon.py b/src/example_soomfon.py new file mode 100644 index 0000000..62f5e73 --- /dev/null +++ b/src/example_soomfon.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 + +# Python Stream Deck Library +# Released under the MIT license +# +# dean [at] fourwalledcubicle [dot] com +# www.fourwalledcubicle.com +# + +# Example script showing basic library usage with the Soomfon Stream Controller +# - updating key images with new tiles generated at runtime, responding to +# button state change events, and using the three tiles of the non-touch side +# display (keys 5, 11 and 17) as an information display (a clock). + +import os +import threading +import time + +from PIL import Image, ImageDraw, ImageFont + +from StreamDeck.DeviceManager import DeviceManager +from StreamDeck.Devices.SoomfonStreamController import SoomfonStreamController +from StreamDeck.ImageHelpers import PILHelper +from StreamDeck.Transport.Transport import TransportError + +# Folder location of image assets used by this example. +ASSETS_PATH = os.path.join(os.path.dirname(__file__), "Assets") +FONT_PATH = os.path.join(ASSETS_PATH, "Roboto-Regular.ttf") + +# The side display tiles can't be pressed, so the exit button is the last key +# of the main 5x3 grid instead of the last key index of the deck. +EXIT_KEY_INDEX = 16 + + +# Generates a custom tile with run-time generated text and custom image via the +# PIL module. +def render_key_image(deck, icon_filename, font_filename, label_text): + # Resize the source image asset to best-fit the dimensions of a single key, + # leaving a margin at the bottom so that we can draw the key title + # afterwards. + icon = Image.open(icon_filename) + image = PILHelper.create_scaled_key_image(deck, icon, margins=[0, 0, 20, 0]) + + # Load a custom TrueType font and use it to overlay the key index, draw key + # label onto the image a few pixels from the bottom of the key. + draw = ImageDraw.Draw(image) + font = ImageFont.truetype(font_filename, 14) + draw.text((image.width / 2, image.height - 5), text=label_text, font=font, anchor="ms", fill="white") + + return PILHelper.to_native_key_format(deck, image) + + +# Generates a text-only tile for the side display. The image is generated at +# the normal key size; the library scales it to the side tile size. +def render_side_image(deck, font_filename, text, font_size): + image = PILHelper.create_key_image(deck) + + draw = ImageDraw.Draw(image) + font = ImageFont.truetype(font_filename, font_size) + draw.text((image.width / 2, image.height / 2), text=text, font=font, anchor="mm", fill="white") + + return PILHelper.to_native_key_format(deck, image) + + +# Returns styling information for a key based on its position and state. +def get_key_style(deck, key, state): + if key == EXIT_KEY_INDEX: + name = "exit" + icon = "{}.png".format("Exit") + font = "Roboto-Regular.ttf" + label = "Bye" if state else "Exit" + else: + name = "emoji" + icon = "{}.png".format("Pressed" if state else "Released") + font = "Roboto-Regular.ttf" + label = "Pressed!" if state else f"Key {key}" + + return { + "name": name, + "icon": os.path.join(ASSETS_PATH, icon), + "font": os.path.join(ASSETS_PATH, font), + "label": label + } + + +# Creates a new key image based on the key index, style and current key state +# and updates the image on the StreamDeck. +def update_key_image(deck, key, state): + # Determine what icon and label to use on the generated key. + key_style = get_key_style(deck, key, state) + + # Generate the custom key with the requested image and label. + image = render_key_image(deck, key_style["icon"], key_style["font"], key_style["label"]) + + # Use a scoped-with on the deck to ensure we're the only thread using it + # right now. + with deck: + # Update requested key with the generated image. + deck.set_key_image(key, image) + + +# Updates the three side display tiles with the current time, date and day. +def update_side_display(deck): + now = time.localtime() + texts = [ + (time.strftime("%H:%M", now), 26), + (time.strftime("%d/%m", now), 26), + (time.strftime("%a", now), 26), + ] + + for key, (text, font_size) in zip(deck.SIDE_KEYS, texts): + image = render_side_image(deck, FONT_PATH, text, font_size) + with deck: + deck.set_key_image(key, image) + + +# Refreshes the side display once per minute until the deck is closed. +def side_display_worker(deck): + last_minute = None + while deck.is_open(): + minute = time.localtime().tm_min + if minute != last_minute: + try: + update_side_display(deck) + except TransportError: + break + last_minute = minute + time.sleep(1) + + +# Prints key state change information, updates the key image and performs any +# associated actions when a key is pressed. +def key_change_callback(deck, key, state): + # Print new key state + print(f"Deck {deck.id()} Key {key} = {state}", flush=True) + + # Update the key image based on the new key state. + update_key_image(deck, key, state) + + # Check if the key is changing to the pressed state. + if state: + key_style = get_key_style(deck, key, state) + + # When an exit button is pressed, close the application. + if key_style["name"] == "exit": + # Use a scoped-with on the deck to ensure we're the only thread + # using it right now. + with deck: + # Reset deck, clearing all button images. + deck.reset() + + # Close deck handle, terminating internal worker threads. + deck.close() + + +if __name__ == "__main__": + streamdecks = DeviceManager().enumerate() + + print(f"Found {len(streamdecks)} Stream Deck(s).\n") + + for index, deck in enumerate(streamdecks): + # This example only works with the Soomfon Stream Controller. + if not isinstance(deck, SoomfonStreamController): + continue + + deck.open() + deck.reset() + + print(f"Opened '{deck.deck_type()}' device (serial number: '{deck.get_serial_number()}')") + + # Set initial screen brightness to 30%. + deck.set_brightness(30) + + # Set initial key images for the pressable keys. + for key in range(deck.key_count()): + if key not in deck.SIDE_KEYS: + update_key_image(deck, key, False) + + # Show a clock on the side display, refreshed in a background thread. + update_side_display(deck) + threading.Thread(target=side_display_worker, args=(deck,), daemon=True).start() + + # Register callback function for when a key state changes. + deck.set_key_callback(key_change_callback) + + # Wait until all application threads have terminated (for this example, + # this is when all deck handles are closed). + for t in threading.enumerate(): + try: + t.join() + except (TransportError, RuntimeError): + pass From 974084eefaad9c20e3814f5dbcaef6db64985f83 Mon Sep 17 00:00:00 2001 From: Salvo Musumeci Date: Sat, 7 Nov 2026 19:04:10 +0100 Subject: [PATCH 4/4] chore: Improve input validation and update documentation Update input validation in SoomfonStreamController and fix heading in documentation. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- doc/source/modules/devices.rst | 2 +- src/StreamDeck/Devices/SoomfonStreamController.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/modules/devices.rst b/doc/source/modules/devices.rst index 14b2d1d..39afecc 100644 --- a/doc/source/modules/devices.rst +++ b/doc/source/modules/devices.rst @@ -93,7 +93,7 @@ Mirabox Stream Dock 293S ========================= -Soomfon Stream Controller +Soomfon Stream Controller ========================= .. automodule:: StreamDeck.Devices.SoomfonStreamController diff --git a/src/StreamDeck/Devices/SoomfonStreamController.py b/src/StreamDeck/Devices/SoomfonStreamController.py index 6dff6b6..469d27b 100644 --- a/src/StreamDeck/Devices/SoomfonStreamController.py +++ b/src/StreamDeck/Devices/SoomfonStreamController.py @@ -67,7 +67,7 @@ def _send_command(self, command): def _read_control_states(self): data = self.device.read(self.INPUT_REPORT_LENGTH) - if not data or bytes(data[:3]) != b"ACK": + if not data or len(data) < 11 or bytes(data[:3]) != b"ACK": return None key_id, state = data[9], data[10]