ble
免费Bluetooth context for the Megahub project. Use when working on BLE GATT server, Classic Bluetooth HID host, Web Bluetooth API integration, btremote library, connection handling, or any Bluetooth-related firmware code.
中文简介正在准备中。当前显示原文说明。
Lua scripting context for the Megahub project. Use when working on Lua script execution, Lua bindings, libluahub, Lua error handling, Lua threads, or the Blockly-to-Lua code generation pipeline.
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
lib/megahub/src/libluahub.cpplib/megahub/src/megahub.cpp → newLuaState()BLE request (type 6, Lua code payload)
→ megahub.cpp: executeLUACode()
→ newLuaState() (~20ms, opens standard libs + registers custom bindings)
→ lua_pcall() (executes the script)
→ cleanup Lua state
From real device logs: execution of a motor control script completes in ~62ms.
libluahub.cpp)Key functions available in Lua scripts:
| Lua function | Purpose |
|---|---|
hub.init(fn) | Register initialization block (runs first) |
hub.startthread(name, fn, stackSize) | Start a FreeRTOS task running a Lua coroutine |
Threads: hub.startthread() creates a FreeRTOS task. Stack size is specified in bytes (e.g., 4096). The thread runs as a Lua coroutine and should yield periodically.
lua_pcall() — never use lua_call() in production codehub.startthread() consume both FreeRTOS stack and Lua VM heap// Safe Lua execution (in megahub.cpp)
lua_State* L = newLuaState();
if (!L) { ERROR("Failed to create Lua state"); return; }
int result = lua_pcall(L, 0, 0, 0);
if (result != LUA_OK) {
ERROR("Lua error: %s", lua_tostring(L, -1));
lua_pop(L, 1);
}
// Always close state when done
lua_close(L);
frontend/src/components/blockly/)executeLUACode()The generated Lua code always follows a structure with hub.init() and optionally hub.startthread() for background monitoring loops.
From device logs:
hub.startthread("Device monitor", fn, 4096) adds another ~4KB stack + Lua coroutine overhead还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Bluetooth context for the Megahub project. Use when working on BLE GATT server, Classic Bluetooth HID host, Web Bluetooth API integration, btremote library, connection handling, or any Bluetooth-related firmware code.
中文简介正在准备中。当前显示原文说明。
Blockly visual programming context for the Megahub project. Use when adding, modifying, or debugging custom Blockly blocks, the Lua code generator, the toolbox, block colors, or the BLOCKS.md documentation generation script.
中文简介正在准备中。当前显示原文说明。
Documentation structure and maintenance rules for the Megahub project. Use whenever making user-facing changes — adding features, changing behavior, fixing hardware compatibility, or modifying configuration. Describes which files to update, the README structure, and writing style.
中文简介正在准备中。当前显示原文说明。
Core firmware context for the Megahub ESP32 project. Use when working on PlatformIO configuration, build scripts, library structure, main.cpp, or general ESP32 firmware development. Covers build system, project structure, common pitfalls, and debugging.
中文简介正在准备中。当前显示原文说明。
Frontend development context for the Megahub project. Use when working on the web-based IDE, Vite build system, Blockly visual programming, Web Bluetooth API integration, JavaScript frontend code, CSS/styles, UI components, or anything in the /frontend/ directory.
中文简介正在准备中。当前显示原文说明。
LEGO Powered Up protocol context for the Megahub project. Use when working on LEGO device communication, lpfuart library, UART parsing, motor control, sensor modes, device initialization, or debugging UART noise/corruption issues.
中文简介正在准备中。当前显示原文说明。