Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/CameraManager/CameraManager/CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ void CameraManager::setupCameraSensor()
0); // 0 = disable , 1 = enable
camera_sensor->set_aec2(camera_sensor, 0); // 0 = disable , 1 = enable
camera_sensor->set_ae_level(camera_sensor, 0); // -2 to 2
camera_sensor->set_aec_value(camera_sensor, 300); // 0 to 1200
camera_sensor->set_aec_value(camera_sensor, 600); // 0 to 1200

// controls the gain
camera_sensor->set_gain_ctrl(camera_sensor, 0); // 0 = disable , 1 = enable

// automatic gain control gain, controls by how much the resulting image
// should be amplified
camera_sensor->set_agc_gain(camera_sensor, 2); // 0 to 30
camera_sensor->set_agc_gain(camera_sensor, 0); // 0 to 30
camera_sensor->set_gainceiling(camera_sensor, static_cast<gainceiling_t>(6)); // 0 to 6

// black and white pixel correction, averages the white and black spots
Expand All @@ -132,7 +132,7 @@ void CameraManager::setupCameraSensor()
// gamma correction
camera_sensor->set_raw_gma(
camera_sensor,
1); // 0 = disable , 1 = enable (makes much lighter and noisy)
0); // 0 = disable , 1 = enable (makes much lighter and noisy)

camera_sensor->set_lenc(camera_sensor, 0); // 0 = disable , 1 = enable // 0 =
// disable , 1 = enable
Expand Down
4 changes: 4 additions & 0 deletions components/CommandManager/CommandManager/CommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
{"get_wifi_status", CommandType::GET_WIFI_STATUS},
{"connect_wifi", CommandType::CONNECT_WIFI},
{"switch_mode", CommandType::SWITCH_MODE},
{"switch_mode_and_restart", CommandType::SWITCH_MODE_AND_RESTART},
{"get_device_mode", CommandType::GET_DEVICE_MODE},
{"set_led_duty_cycle", CommandType::SET_LED_DUTY_CYCLE},
{"get_led_duty_cycle", CommandType::GET_LED_DUTY_CYCLE},
Expand Down Expand Up @@ -87,6 +88,9 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
case CommandType::SWITCH_MODE:
return [this, json]
{ return switchModeCommand(this->registry, json); };
case CommandType::SWITCH_MODE_AND_RESTART:
return [this, json]
{ return switchModeAndRestartCommand(this->registry, json); };
case CommandType::GET_DEVICE_MODE:
return [this]
{ return getDeviceModeCommand(this->registry); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum class CommandType
GET_WIFI_STATUS,
CONNECT_WIFI,
SWITCH_MODE,
SWITCH_MODE_AND_RESTART,
GET_DEVICE_MODE,
SET_LED_DUTY_CYCLE,
GET_LED_DUTY_CYCLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,10 @@ CommandResult getLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registr

CommandResult startStreamingCommand()
{
// since we're trying to kill the serial handler
// from *inside* the serial handler, we'd deadlock.
// we can just pass nullptr to the vtaskdelete(),
// but then we won't get any response, so we schedule a timer instead
esp_timer_create_args_t args{
.callback = activateStreaming,
.arg = nullptr,
.name = "activateStreaming"};

esp_timer_handle_t activateStreamingTimer;
esp_timer_create(&args, &activateStreamingTimer);
esp_timer_start_once(activateStreamingTimer, pdMS_TO_TICKS(150));
// streamServer.startStreamServer();
return CommandResult::getSuccessResult("Streaming starting");
// Start the stream server directly without going through mode-based logic
// This allows starting streaming in SETUP mode without changing modes
startStreamServerOnly();
return CommandResult::getSuccessResult("Streaming started");
}

CommandResult switchModeCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json)
Expand Down Expand Up @@ -154,6 +144,51 @@ CommandResult switchModeCommand(std::shared_ptr<DependencyRegistry> registry, co
return CommandResult::getSuccessResult("Device mode switched, restart to apply");
}

CommandResult switchModeAndRestartCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json)
{
if (!json.contains("mode") || !json["mode"].is_string())
{
return CommandResult::getErrorResult("Invalid payload - missing mode");
}

auto modeStr = json["mode"].get<std::string>();
StreamingMode newMode;

ESP_LOGI("[DEVICE_COMMANDS]", "Switch mode and restart command received with mode: %s", modeStr.c_str());

if (modeStr == "uvc")
{
newMode = StreamingMode::UVC;
}
else if (modeStr == "wifi")
{
newMode = StreamingMode::WIFI;
}
else if (modeStr == "setup" || modeStr == "auto")
{
newMode = StreamingMode::SETUP;
}
else
{
return CommandResult::getErrorResult("Invalid mode - use 'uvc', 'wifi', or 'auto'");
}

const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
StreamingMode currentMode = projectConfig->getDeviceMode();

if (currentMode == newMode)
{
ESP_LOGI("[DEVICE_COMMANDS]", "Device already in mode: %d, no restart needed", (int)currentMode);
return CommandResult::getSuccessResult("Device already in requested mode");
}

ESP_LOGI("[DEVICE_COMMANDS]", "Setting device mode to: %d and scheduling restart", (int)newMode);
projectConfig->setDeviceMode(newMode);
Comment on lines +149 to +186
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea behind this command and why it's needed, I completely agree with that. But do we have to duplicate the already existing switchModeCommand()? Is there something preventing us from just calling that command in here and then scheduling the restart right away, while returning what switchModeCommand returned?


OpenIrisTasks::ScheduleRestart(2000);
return CommandResult::getSuccessResult("Device mode switched, restarting...");
}

CommandResult getDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry)
{
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CommandResult restartDeviceCommand();
CommandResult startStreamingCommand();

CommandResult switchModeCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json);
CommandResult switchModeAndRestartCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json);

CommandResult getDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry);

Expand Down
8 changes: 8 additions & 0 deletions components/Helpers/Helpers/main_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// used to force starting the stream setup process via commands
extern void force_activate_streaming();
// used to start just the stream server without mode changes
extern void force_start_stream_server();

static bool s_startupCommandReceived = false;
bool getStartupCommandReceived()
Expand Down Expand Up @@ -33,6 +35,12 @@ void activateStreaming(void *arg)
force_activate_streaming();
}

// Function to start just the stream server
void startStreamServerOnly()
{
force_start_stream_server();
}

// USB handover state
static bool s_usbHandoverDone = false;
bool getUsbHandoverDone() { return s_usbHandoverDone; }
Expand Down
3 changes: 3 additions & 0 deletions components/Helpers/Helpers/main_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// so that the serial manager has time to return the response
void activateStreaming(void *arg);

// Starts only the stream server (used by startStreamingCommand in SETUP mode)
void startStreamServerOnly();

bool getStartupCommandReceived();
void setStartupCommandReceived(bool startupCommandReceived);

Expand Down
2 changes: 1 addition & 1 deletion dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies:
idf:
source:
type: idf
version: 5.4.2
version: 5.5.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love me the update, thanks for upping the version. I'll have to copy the sdkconfig into the sdkconfig.base_defaults in boards/ later

direct_dependencies:
- espressif/cmake_utilities
- espressif/esp32-camera
Expand Down
14 changes: 13 additions & 1 deletion main/openiris_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ void force_activate_streaming()
launch_streaming();
}

// Start just the stream server directly (for SETUP mode startStreamingCommand)
void force_start_stream_server()
{
#ifdef CONFIG_GENERAL_ENABLE_WIRELESS
ESP_LOGI("[MAIN]", "Starting stream server directly via command.");
streamServer.startStreamServer();
#else
ESP_LOGW("[MAIN]", "Wireless is disabled; cannot start stream server.");
#endif
}

void startWiredMode(bool shouldCloseSerialManager)
{
#ifndef CONFIG_GENERAL_INCLUDE_UVC_MODE
Expand Down Expand Up @@ -222,7 +233,8 @@ void startWiFiMode()
mdnsManager.start();
restAPI->begin();
StreamingMode mode = deviceConfig->getDeviceMode();
// don't enable in SETUP mode
// Only auto-start stream server in WIFI mode, not SETUP mode
// In SETUP mode, use startStreamingCommand to manually start streaming
if (mode == StreamingMode::WIFI)
{
streamServer.startStreamServer();
Expand Down
Loading