mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-25 09:03:45 +02:00
Add command to set device mode between auto/uvc/wifi, add config to represent streaming mode, implement restart task, implement restart device command
This commit is contained in:
@@ -29,6 +29,7 @@ CommandResult saveConfigCommand(std::shared_ptr<DependencyRegistry> registry)
|
||||
projectConfig->save();
|
||||
return CommandResult::getSuccessResult("Config saved");
|
||||
}
|
||||
|
||||
CommandResult getConfigCommand(std::shared_ptr<DependencyRegistry> registry)
|
||||
{
|
||||
std::shared_ptr<ProjectConfig> projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||
|
||||
@@ -1,8 +1,33 @@
|
||||
#include "device_commands.hpp"
|
||||
|
||||
CommandResult restartDeviceCommand()
|
||||
{
|
||||
// todo implement this: https://github.com/EyeTrackVR/OpenIris/blob/master/ESP/lib/src/tasks/tasks.cpp
|
||||
// OpenIrisTasks::ScheduleRestart(2000);
|
||||
return CommandResult::getSuccessResult("Device restarted");
|
||||
}
|
||||
#include <cJSON.h>
|
||||
#include <ProjectConfig.hpp>
|
||||
|
||||
// Implementation inspired by SummerSigh work, initial PR opened in openiris repo, adapted to this rewrite
|
||||
CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload) {
|
||||
const auto parsedJson = cJSON_Parse(jsonPayload.data());
|
||||
if (parsedJson == nullptr) {
|
||||
return CommandResult::getErrorResult("Invalid payload");
|
||||
}
|
||||
|
||||
const auto modeObject = cJSON_GetObjectItem(parsedJson, "mode");
|
||||
if (modeObject == nullptr) {
|
||||
return CommandResult::getErrorResult("Invalid payload - missing mode");
|
||||
}
|
||||
|
||||
const auto mode = modeObject->valueint;
|
||||
|
||||
if (mode < 0 || mode > 2) {
|
||||
return CommandResult::getErrorResult("Invalid payload - unsupported mode");
|
||||
}
|
||||
|
||||
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||
projectConfig->setDeviceMode(static_cast<StreamingMode>(mode));
|
||||
|
||||
return CommandResult::getSuccessResult("Device mode set");
|
||||
}
|
||||
|
||||
CommandResult restartDeviceCommand() {
|
||||
OpenIrisTasks::ScheduleRestart(2000);
|
||||
return CommandResult::getSuccessResult("Device restarted");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#include "CommandResult.hpp"
|
||||
#include "OpenIrisTasks.hpp"
|
||||
#include "DependencyRegistry.hpp"
|
||||
|
||||
CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||
|
||||
CommandResult restartDeviceCommand();
|
||||
Reference in New Issue
Block a user