mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-05-04 21:26:04 +02:00
Add get device name command for displaying the current name in the setup tool
This commit is contained in:
@@ -6,11 +6,11 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
|
|||||||
{"pause", CommandType::PAUSE},
|
{"pause", CommandType::PAUSE},
|
||||||
{"set_wifi", CommandType::SET_WIFI},
|
{"set_wifi", CommandType::SET_WIFI},
|
||||||
{"update_wifi", CommandType::UPDATE_WIFI},
|
{"update_wifi", CommandType::UPDATE_WIFI},
|
||||||
{"set_streaming_mode", CommandType::SET_STREAMING_MODE},
|
|
||||||
{"update_ota_credentials", CommandType::UPDATE_OTA_CREDENTIALS},
|
{"update_ota_credentials", CommandType::UPDATE_OTA_CREDENTIALS},
|
||||||
{"delete_network", CommandType::DELETE_NETWORK},
|
{"delete_network", CommandType::DELETE_NETWORK},
|
||||||
{"update_ap_wifi", CommandType::UPDATE_AP_WIFI},
|
{"update_ap_wifi", CommandType::UPDATE_AP_WIFI},
|
||||||
{"set_mdns", CommandType::SET_MDNS},
|
{"set_mdns", CommandType::SET_MDNS},
|
||||||
|
{"get_mdns_name", CommandType::GET_MDNS_NAME},
|
||||||
{"update_camera", CommandType::UPDATE_CAMERA},
|
{"update_camera", CommandType::UPDATE_CAMERA},
|
||||||
{"restart_camera", CommandType::RESTART_CAMERA},
|
{"restart_camera", CommandType::RESTART_CAMERA},
|
||||||
{"save_config", CommandType::SAVE_CONFIG},
|
{"save_config", CommandType::SAVE_CONFIG},
|
||||||
@@ -24,8 +24,8 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
|
|||||||
{"switch_mode", CommandType::SWITCH_MODE},
|
{"switch_mode", CommandType::SWITCH_MODE},
|
||||||
{"get_device_mode", CommandType::GET_DEVICE_MODE},
|
{"get_device_mode", CommandType::GET_DEVICE_MODE},
|
||||||
{"set_led_duty_cycle", CommandType::SET_LED_DUTY_CYCLE},
|
{"set_led_duty_cycle", CommandType::SET_LED_DUTY_CYCLE},
|
||||||
{"get_led_duty_cycle", CommandType::GET_LED_DUTY_CYCLE},
|
{"get_led_duty_cycle", CommandType::GET_LED_DUTY_CYCLE},
|
||||||
{"get_serial", CommandType::GET_SERIAL},
|
{"get_serial", CommandType::GET_SERIAL},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, std::string_view json) const
|
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, std::string_view json) const
|
||||||
@@ -37,9 +37,8 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
|
|||||||
case CommandType::PAUSE:
|
case CommandType::PAUSE:
|
||||||
return [json]
|
return [json]
|
||||||
{ return PauseCommand(json); };
|
{ return PauseCommand(json); };
|
||||||
case CommandType::SET_STREAMING_MODE:
|
return [json]
|
||||||
return [this, json]
|
{ return PauseCommand(json); };
|
||||||
{ return setDeviceModeCommand(this->registry, json); };
|
|
||||||
case CommandType::UPDATE_OTA_CREDENTIALS:
|
case CommandType::UPDATE_OTA_CREDENTIALS:
|
||||||
return [this, json]
|
return [this, json]
|
||||||
{ return updateOTACredentialsCommand(this->registry, json); };
|
{ return updateOTACredentialsCommand(this->registry, json); };
|
||||||
@@ -58,6 +57,9 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
|
|||||||
case CommandType::SET_MDNS:
|
case CommandType::SET_MDNS:
|
||||||
return [this, json]
|
return [this, json]
|
||||||
{ return setMDNSCommand(this->registry, json); };
|
{ return setMDNSCommand(this->registry, json); };
|
||||||
|
case CommandType::GET_MDNS_NAME:
|
||||||
|
return [this]
|
||||||
|
{ return getMDNSNameCommand(this->registry); };
|
||||||
case CommandType::UPDATE_CAMERA:
|
case CommandType::UPDATE_CAMERA:
|
||||||
return [this, json]
|
return [this, json]
|
||||||
{ return updateCameraCommand(this->registry, json); };
|
{ return updateCameraCommand(this->registry, json); };
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ enum class CommandType
|
|||||||
PAUSE,
|
PAUSE,
|
||||||
SET_WIFI,
|
SET_WIFI,
|
||||||
UPDATE_OTA_CREDENTIALS,
|
UPDATE_OTA_CREDENTIALS,
|
||||||
SET_STREAMING_MODE,
|
|
||||||
UPDATE_WIFI,
|
UPDATE_WIFI,
|
||||||
DELETE_NETWORK,
|
DELETE_NETWORK,
|
||||||
UPDATE_AP_WIFI,
|
UPDATE_AP_WIFI,
|
||||||
SET_MDNS,
|
SET_MDNS,
|
||||||
|
GET_MDNS_NAME,
|
||||||
UPDATE_CAMERA,
|
UPDATE_CAMERA,
|
||||||
RESTART_CAMERA,
|
RESTART_CAMERA,
|
||||||
SAVE_CONFIG,
|
SAVE_CONFIG,
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
#include <format>
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
|
||||||
|
|
||||||
CommandResult updateOTACredentialsCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
CommandResult updateOTACredentialsCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||||
|
|
||||||
CommandResult updateLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
CommandResult updateLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||||
|
|||||||
@@ -31,3 +31,12 @@ CommandResult setMDNSCommand(std::shared_ptr<DependencyRegistry> registry, std::
|
|||||||
|
|
||||||
return CommandResult::getSuccessResult("Config updated");
|
return CommandResult::getSuccessResult("Config updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandResult getMDNSNameCommand(std::shared_ptr<DependencyRegistry> registry)
|
||||||
|
{
|
||||||
|
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||||
|
auto mdnsConfig = projectConfig->getMDNSConfig();
|
||||||
|
|
||||||
|
auto result = std::format("{{ \"hostname\": \"{}\" }}", mdnsConfig.hostname);
|
||||||
|
return CommandResult::getSuccessResult(result);
|
||||||
|
}
|
||||||
@@ -8,4 +8,5 @@
|
|||||||
#include "DependencyRegistry.hpp"
|
#include "DependencyRegistry.hpp"
|
||||||
|
|
||||||
std::optional<MDNSPayload> parseMDNSCommandPayload(std::string_view jsonPayload);
|
std::optional<MDNSPayload> parseMDNSCommandPayload(std::string_view jsonPayload);
|
||||||
CommandResult setMDNSCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
CommandResult setMDNSCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||||
|
CommandResult getMDNSNameCommand(std::shared_ptr<DependencyRegistry> registry);
|
||||||
+23
-3
@@ -410,14 +410,31 @@ class OpenIrisDevice:
|
|||||||
print(f"❌ Failed to parse mode response: {e}")
|
print(f"❌ Failed to parse mode response: {e}")
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
def get_mdns_name(self) -> str:
|
||||||
|
"""Get the current MDNS name"""
|
||||||
|
response = self.send_command("get_mdns_name")
|
||||||
|
if "error" in response:
|
||||||
|
print(f"❌ Failed to get device name: {response['error']}")
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
|
try:
|
||||||
|
results = response.get("results", [])
|
||||||
|
if results:
|
||||||
|
result_data = json.loads(results[0])
|
||||||
|
name_data = json.loads(result_data["result"])
|
||||||
|
return name_data.get("hostname", "unknown")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Failed to parse name response: {e}")
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
def set_led_duty_cycle(self, duty_cycle):
|
def set_led_duty_cycle(self, duty_cycle):
|
||||||
"""Sets the PWN duty cycle of the LED"""
|
"""Sets the PWN duty cycle of the LED"""
|
||||||
print(f"🌟 Setting LED duty cycle to {duty_cycle}%...")
|
print(f"🌟 Setting LED duty cycle to {duty_cycle}%...")
|
||||||
response = self.send_command("set_led_duty_cycle", {"dutyCycle": duty_cycle})
|
response = self.send_command("set_led_duty_cycle", {"dutyCycle": duty_cycle})
|
||||||
if "error" in response:
|
if "error" in response:
|
||||||
print(f"❌ Failed to set LED duty cycle: {response['error']}")
|
print(f"❌ Failed to set LED duty cycle: {response['error']}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print("✅ LED duty cycle set successfully")
|
print("✅ LED duty cycle set successfully")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -689,10 +706,13 @@ def configure_wifi(device: OpenIrisDevice, args = None):
|
|||||||
|
|
||||||
|
|
||||||
def configure_mdns(device: OpenIrisDevice, args = None):
|
def configure_mdns(device: OpenIrisDevice, args = None):
|
||||||
|
current_name = device.get_mdns_name()
|
||||||
|
print(f"\n📍 Current device name: {current_name} \n")
|
||||||
print("💡 Please enter your preferred device name, your board will be accessible under http://<name>.local/")
|
print("💡 Please enter your preferred device name, your board will be accessible under http://<name>.local/")
|
||||||
print("💡 Please avoid spaces and special characters")
|
print("💡 Please avoid spaces and special characters")
|
||||||
print(" To back out, enter `back`")
|
print(" To back out, enter `back`")
|
||||||
print("\n Note, this will also modify the name of the UVC device")
|
print("\n Note, this will also modify the name of the UVC device")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
name_choice = input("\nDevice name: ").strip()
|
name_choice = input("\nDevice name: ").strip()
|
||||||
if any(space in name_choice for space in string.whitespace):
|
if any(space in name_choice for space in string.whitespace):
|
||||||
@@ -910,7 +930,7 @@ def set_led_duty_cycle(device: OpenIrisDevice, args=None):
|
|||||||
input_data = input("Enter LED external PWM duty cycle (0-100) or `back` to exit: \n")
|
input_data = input("Enter LED external PWM duty cycle (0-100) or `back` to exit: \n")
|
||||||
if input_data.lower() == "back":
|
if input_data.lower() == "back":
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
duty_cycle = int(input_data)
|
duty_cycle = int(input_data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
Reference in New Issue
Block a user