Fix menu controls: wire up menu items in ctrl_enum_cb; document control commands

src/node/main.c: ctrl_enum_cb was discarding menu_count and menu_items,
causing empty dropdowns for all MENU/INTEGER_MENU controls. Added a
menu item pool (MAX_MENU_POOL=128 items) to Ctrl_Build; the callback now
copies items into the pool and sets menu_count/menu_items on the control.

docs/protocol.md: add missing sections — str8 primitive, ENUM_DEVICES,
ENUM_CONTROLS (with control type/flag tables and menu item notes),
GET_CONTROL, and SET_CONTROL schemas.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 02:00:18 +00:00
parent ab47729d74
commit 49e5076eea
2 changed files with 148 additions and 1 deletions

View File

@@ -195,9 +195,14 @@ static void build_device_list(struct Device_List *dl) {
* Control enumeration helpers
* ------------------------------------------------------------------------- */
#define MAX_MENU_POOL 128 /* total menu items across all controls */
struct Ctrl_Build {
struct Proto_Control_Info items[MAX_CONTROLS];
char names[MAX_CONTROLS][32];
struct Proto_Menu_Item menu_pool[MAX_MENU_POOL];
char menu_names[MAX_MENU_POOL][32];
int menu_pool_used;
int count;
};
@@ -206,7 +211,6 @@ static void ctrl_enum_cb(
uint32_t menu_count, const struct V4l2_Menu_Item *menu_items,
void *userdata)
{
(void)menu_count; (void)menu_items;
struct Ctrl_Build *b = userdata;
if (b->count >= MAX_CONTROLS) { return; }
@@ -225,6 +229,24 @@ static void ctrl_enum_cb(
b->items[i].current_val = desc->current_value;
b->items[i].menu_count = 0;
b->items[i].menu_items = NULL;
if (menu_count > 0 && menu_items) {
int avail = MAX_MENU_POOL - b->menu_pool_used;
uint8_t mc = (menu_count > (uint32_t)avail) ? (uint8_t)avail : (uint8_t)menu_count;
if (mc > 0) {
b->items[i].menu_items = &b->menu_pool[b->menu_pool_used];
b->items[i].menu_count = mc;
for (uint8_t j = 0; j < mc; j++) {
int slot = b->menu_pool_used + j;
strncpy(b->menu_names[slot], menu_items[j].name, 31);
b->menu_names[slot][31] = '\0';
b->menu_pool[slot].index = menu_items[j].index;
b->menu_pool[slot].name = b->menu_names[slot];
b->menu_pool[slot].int_value = menu_items[j].value;
}
b->menu_pool_used += mc;
}
}
}
/* -------------------------------------------------------------------------