$ show fossasia/badgemagic-app
Badge Magic is a cross-platform Flutter application for programming LED name badges over Bluetooth Low Energy and for flashing their firmware over USB. In production, users compose text, freehand drawings, clipart, GIFs, and dozens of animations; apply flash/marquee/invert effects and speed/mode settings; then serialize the composed badge into a proprietary LED hex format and transmit it as BLE packets to a badge. The app also reads and writes badge slots, saves/loads badges as local JSON files, shares/imports badges via a gzip-compressed QR code scheme, and updates WCH microcontroller firmware on Android/Linux through a custom MethodChannel and OS-specific ISP binaries. Architecturally it is a standard Flutter app using Provider for state management and GetIt for service location, with a clear split between UI screens, state providers, and utility modules. The most interesting part is the protocol path: internal models are converted to LED-matrix hex data, then to BLE byte packets via DataToByteArrayConverter, and finally written through a scan/connect/write/completion BLE state machine using universal_ble. Unit tests cover byte utilities, converter logic, clipart processing, and packet generation. CI/CD spans Android, iOS, Linux, macOS, Windows, and web. Some areas show accumulated drift: several ARB locale files are empty, custom animation logic is duplicated between preview and transfer implementations, debug logging remains in production code, and the firmware release URL is hardcoded.
The LLM identified 4 files worth highlighting for reuse:
Encodes the internal badge model into the proprietary byte stream expected by LED badges, packing mode, speed, flash, and marquee flags alongside pixel data. It is a self-contained protocol encoder with unit tests and can be reused in any client that needs to drive compatible LED badges or as a reference for designing binary BLE payloads.
Abstract base class for BLE operation states, providing a clean template for scan, connect, write, completion, and retry control. The state boundary is narrow enough to be lifted into another Flutter BLE application needing a deterministic connection and transfer flow.
Contains reusable conversions from text and booleans to LED hex matrices, including TextPainter-based font rasterization and boolean-grid-to-LED-line conversion. The bitmap-to-LED conversion is independent of the Badge Magic UI and applies directly to any LED matrix rendering pipeline.
Small, low-coupling utility set for byte array manipulation and conversion used throughout the BLE transfer path. It is covered by unit tests and can be dropped into another project without modification whenever binary payloads need splitting, combining, or formatting.