mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 06:23:44 +02:00
Added PWM live control and get_led_duty_cycle
This commit is contained in:
@@ -24,6 +24,7 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
|
||||
{"switch_mode", CommandType::SWITCH_MODE},
|
||||
{"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},
|
||||
};
|
||||
|
||||
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, std::string_view json) const
|
||||
@@ -93,6 +94,9 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
|
||||
case CommandType::SET_LED_DUTY_CYCLE:
|
||||
return [this, json]
|
||||
{ return updateLEDDutyCycleCommand(this->registry, json); };
|
||||
case CommandType::GET_LED_DUTY_CYCLE:
|
||||
return [this]
|
||||
{ return getLEDDutyCycleCommand(this->registry); };
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ enum class CommandType
|
||||
SWITCH_MODE,
|
||||
GET_DEVICE_MODE,
|
||||
SET_LED_DUTY_CYCLE,
|
||||
GET_LED_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
class CommandManager
|
||||
|
||||
@@ -8,7 +8,8 @@ enum class DependencyType
|
||||
{
|
||||
project_config,
|
||||
camera_manager,
|
||||
wifi_manager
|
||||
wifi_manager,
|
||||
led_manager
|
||||
};
|
||||
|
||||
class DependencyRegistry
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "device_commands.hpp"
|
||||
#include "LEDManager.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)
|
||||
@@ -96,6 +97,13 @@ CommandResult updateLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> regi
|
||||
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||
projectConfig->setLEDDUtyCycleConfig(dutyCycle);
|
||||
|
||||
// Try to apply the change live via LEDManager if available
|
||||
auto ledMgr = registry->resolve<LEDManager>(DependencyType::led_manager);
|
||||
if (ledMgr)
|
||||
{
|
||||
ledMgr->setExternalLEDDutyCycle(static_cast<uint8_t>(dutyCycle));
|
||||
}
|
||||
|
||||
cJSON_Delete(parsedJson);
|
||||
|
||||
return CommandResult::getSuccessResult("LED duty cycle set");
|
||||
@@ -107,6 +115,15 @@ CommandResult restartDeviceCommand()
|
||||
return CommandResult::getSuccessResult("Device restarted");
|
||||
}
|
||||
|
||||
CommandResult getLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registry)
|
||||
{
|
||||
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||
const auto deviceCfg = projectConfig->getDeviceConfig();
|
||||
int duty = deviceCfg.led_external_pwm_duty_cycle;
|
||||
auto result = std::format("{{ \"led_external_pwm_duty_cycle\": {} }}", duty);
|
||||
return CommandResult::getSuccessResult(result);
|
||||
}
|
||||
|
||||
CommandResult startStreamingCommand()
|
||||
{
|
||||
activateStreaming(false); // Don't disable setup interfaces by default
|
||||
|
||||
@@ -14,6 +14,7 @@ CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry,
|
||||
CommandResult updateOTACredentialsCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||
|
||||
CommandResult updateLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||
CommandResult getLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registry);
|
||||
|
||||
CommandResult restartDeviceCommand();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user