Add support for setting a custom device name and per-board serial number for UVC

This commit is contained in:
Lorow
2025-06-17 22:20:20 +02:00
parent 39002e2335
commit ec4369df7f
17 changed files with 2740 additions and 102 deletions

View File

@@ -3,6 +3,30 @@ constexpr int UVC_MAX_FRAMESIZE_SIZE(75 * 1024);
static const char *UVC_STREAM_TAG = "[UVC DEVICE]";
extern "C" {
static char serial_number_str[13];
const char *get_uvc_device_name() {
return deviceConfig->getMDNSConfig().hostname.c_str();
}
const char *get_serial_number(void) {
if (serial_number_str[0] == '\0') {
uint8_t mac_address[6];
esp_err_t result = esp_efuse_mac_get_default(mac_address);
if (result != ESP_OK) {
ESP_LOGE(UVC_STREAM_TAG, "Failed to get MAC address of the board, returning default serial number");
return CONFIG_TUSB_SERIAL_NUM;
}
sniprintf(serial_number_str, sizeof(serial_number_str), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]
);
}
return serial_number_str;
}
}
static esp_err_t UVCStreamHelpers::camera_start_cb(uvc_format_t format, int width, int height, int rate, void *cb_ctx)
{
(void)cb_ctx;

View File

@@ -2,6 +2,7 @@
#ifndef UVCSTREAM_HPP
#define UVCSTREAM_HPP
#include "esp_timer.h"
#include "esp_mac.h"
#include "esp_camera.h"
#include <CameraManager.hpp>
#include <StateManager.hpp>
@@ -13,6 +14,18 @@
// we need access to the camera manager
// in order to update the frame settings
extern std::shared_ptr<CameraManager> cameraHandler;
extern std::shared_ptr<ProjectConfig> deviceConfig;
#ifdef __cplusplus
extern "C" {
#endif
const char *get_uvc_device_name();
const char *get_serial_number(void);
#ifdef __cplusplus
}
#endif
// we also need a way to inform the rest of the system of what's happening
extern QueueHandle_t eventQueue;