From 93bb0a74e0c2cf127573c7321cbae64d0dd381e7 Mon Sep 17 00:00:00 2001 From: Mobilizes Date: Sat, 22 Jun 2024 02:28:33 +0700 Subject: [PATCH] refactor: use jitsuyo to load capture setting config --- src/shisen_cpp/camera/node/camera_node.cpp | 42 ++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index ae0c607..234389e 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "jitsuyo/config.hpp" #include #include @@ -206,27 +207,30 @@ void CameraNode::load_configuration(const std::string & path) CaptureSetting capture_setting; - // Get all config - for (auto & item : config.items()) { - try { - if (item.key() == "brightness") { - capture_setting.brightness.set(item.value()); - } else if (item.key() == "contrast") { - capture_setting.contrast.set(item.value()); - } else if (item.key() == "saturation") { - capture_setting.saturation.set(item.value()); - } else if (item.key() == "temperature") { - capture_setting.temperature.set(item.value()); - } else if (item.key() == "exposure") { - capture_setting.exposure.set(item.value()); - } else if (item.key() == "gain") { - capture_setting.gain.set(item.value()); - } - } catch (nlohmann::json::parse_error & ex) { - throw std::runtime_error("Parse error at byte `" + std::to_string(ex.byte) + "`!"); - } + int setting_brightness; + int setting_contrast; + int setting_saturation; + int setting_temperature; + int setting_exposure; + int setting_gain; + + if (!jitsuyo::assign_val(config, "brightness", setting_brightness) || + !jitsuyo::assign_val(config, "contrast", setting_contrast) || + !jitsuyo::assign_val(config, "saturation", setting_saturation) || + !jitsuyo::assign_val(config, "temperature", setting_temperature) || + !jitsuyo::assign_val(config, "exposure", setting_exposure) || + !jitsuyo::assign_val(config, "gain", setting_gain)) + { + throw std::runtime_error("Failed to load config file"); } + capture_setting.brightness.set(setting_brightness); + capture_setting.contrast.set(setting_contrast); + capture_setting.saturation.set(setting_saturation); + capture_setting.temperature.set(setting_temperature); + capture_setting.exposure.set(setting_exposure); + capture_setting.gain.set(setting_gain); + configure_capture_setting(capture_setting); }