Skip to content

Commit

Permalink
refactor: use jitsuyo to load capture setting config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobilizes committed Jun 21, 2024
1 parent a9b865a commit 93bb0a7
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/shisen_cpp/camera/node/camera_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <memory>
#include <nlohmann/json.hpp>
#include <shisen_cpp/camera/node/camera_node.hpp>
#include "jitsuyo/config.hpp"

#include <fstream>
#include <memory>
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 93bb0a7

Please sign in to comment.