Skip to content

Commit

Permalink
Merge PR IntelRealSense#25 from Nir: Alert when trigger manual CAH du…
Browse files Browse the repository at this point in the history
…ring auto CAH
  • Loading branch information
maloel committed Jul 15, 2020
2 parents 0625140 + 4a51f41 commit 05b7e15
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 56 deletions.
90 changes: 45 additions & 45 deletions common/cah-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@

using namespace rs2;

// This registration should happen once in the SW runtime life.
static bool global_registered_to_callback = false;

// This variable is global for protecting the case when the callback will be called when the device model no longer exist.
// TODO: Refactor for handling multiple L515 devices support.
static std::atomic<rs2_calibration_status> global_calib_status;

cah_model::cah_model() :_state(model_state_type::TRIGGER_MODAL),
_process_started(false), _process_timeout()
cah_model::cah_model(device_model & dev_model, viewer_model& viewer) :
_dev_model(dev_model),
_viewer(viewer),
_state(model_state_type::TRIGGER_MODAL),
_process_started(false),
_process_timeout()
{
global_calib_status = RS2_CALIBRATION_RETRY;
global_calib_status = RS2_CALIBRATION_NOT_NEEDED;

// Register AC status change callback
device_calibration dev_cal(dev_model.dev);
dev_cal.register_calibration_change_callback([&](rs2_calibration_status cal_status)
{
global_calib_status = cal_status;
});
}


bool cah_model::prompt_trigger_popup(device_model & dev_model, ux_window& window, viewer_model& viewer, const std::string& error_message)
bool cah_model::prompt_trigger_popup(ux_window& window, const std::string& error_message)
{
// This process is built from a 2 stages windows, first a yes/no window and then a process window
bool keep_showing = true;
Expand All @@ -34,66 +43,58 @@ bool cah_model::prompt_trigger_popup(device_model & dev_model, ux_window& window
{
// Make sure the firmware meets the minimal version for Trigger Camera Accuracy features
const std::string& min_fw_version("1.4.1.0");
auto fw_upgrade_needed = is_upgradeable(dev_model.dev.get_info(rs2_camera_info::RS2_CAMERA_INFO_FIRMWARE_VERSION), min_fw_version);
bool is_depth_streaming(false);
bool is_color_streaming(false);
auto fw_upgrade_needed = is_upgradeable(_dev_model.dev.get_info(rs2_camera_info::RS2_CAMERA_INFO_FIRMWARE_VERSION), min_fw_version);
bool is_depth_streaming = std::any_of(_dev_model.subdevices.begin(), _dev_model.subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming && sm->s->as<depth_sensor>(); });
bool is_color_streaming = std::any_of(_dev_model.subdevices.begin(), _dev_model.subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming && sm->s->as<color_sensor>(); });
bool auto_cah_is_working =
(RS2_CALIBRATION_SUCCESSFUL != global_calib_status) &&
(RS2_CALIBRATION_FAILED != global_calib_status) &&
(RS2_CALIBRATION_NOT_NEEDED != global_calib_status);

std::string message_text = "Camera Accuracy Health will ensure you get the highest accuracy from your camera.\n\n"
"This process may take several minutes and requires special setup to get good results.\n"
"While it is working, the viewer will not be usable.\n\n";
"While it is working, the viewer will not be usable.";

std::string disable_reason_text;
if (fw_upgrade_needed)
{
std::string fw_upgrade_message = "Camera Accuracy Health requires a minimal FW version of " + min_fw_version +
disable_reason_text = "Camera Accuracy Health requires a minimal FW version of " + min_fw_version +
"\n\nPlease update your firmware and try again. ";

message_text += fw_upgrade_message;
}
else if (!is_depth_streaming || !is_color_streaming)
{
disable_reason_text = "Camera Accuracy Health cannot be triggered : both depth & RGB streams must be active.";
}
else if (auto_cah_is_working)
{
disable_reason_text = "Camera Accuracy Health is already in progress in the background.\n"
"Please try again in a few minutes. ";
}
else
{
is_depth_streaming = std::any_of(dev_model.subdevices.begin(), dev_model.subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming && sm->s->as<depth_sensor>(); });
is_color_streaming = std::any_of(dev_model.subdevices.begin(), dev_model.subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming && sm->s->as<color_sensor>(); });

if (is_depth_streaming && is_color_streaming)
{
message_text += "Are you sure you want to continue?";
}
else
{
std::string stream_missing_message = "Camera Accuracy Health cannot be triggered : both depth & RGB streams must be active.";
message_text += stream_missing_message;
}

message_text += "\n\nAre you sure you want to continue?";
}

bool option_disabled = !is_depth_streaming || !is_color_streaming || fw_upgrade_needed;
if (yes_no_dialog("Camera Accuracy Health Trigger", message_text, yes_was_chosen, window, error_message, option_disabled))
bool option_disabled = !is_depth_streaming || !is_color_streaming || auto_cah_is_working || fw_upgrade_needed;
if (yes_no_dialog("Camera Accuracy Health Trigger", message_text, yes_was_chosen, window, error_message, option_disabled, disable_reason_text))
{
if (yes_was_chosen)
{

auto itr = std::find_if(dev_model.subdevices.begin(), dev_model.subdevices.end(), [](std::shared_ptr<subdevice_model> sub)
auto itr = std::find_if(_dev_model.subdevices.begin(), _dev_model.subdevices.end(), [](std::shared_ptr<subdevice_model> sub)
{
if (sub->s->as<depth_sensor>())
return true;
return false;
});


if (is_depth_streaming && is_color_streaming && itr != dev_model.subdevices.end())
if (is_depth_streaming && is_color_streaming && itr != _dev_model.subdevices.end())
{
auto sd = *itr;
global_calib_status = RS2_CALIBRATION_RETRY; // To indicate in progress state
sd->s->set_option(RS2_OPTION_TRIGGER_CAMERA_ACCURACY_HEALTH, 1.0f);
device_calibration dev_cal(dev_model.dev);
// Register AC status change callback
if (!global_registered_to_callback)
{
dev_cal.register_calibration_change_callback([&](rs2_calibration_status cal_status)
{
global_calib_status = cal_status;
});
global_registered_to_callback = true;
}

_state = model_state_type::PROCESS_MODAL;
// We switch to process state without a guarantee that the process really started,
// Set a timeout to make sure if it is not started we will allow closing the window.
Expand Down Expand Up @@ -158,13 +159,12 @@ bool cah_model::prompt_trigger_popup(device_model & dev_model, ux_window& window
if (!keep_showing)
{
_state = model_state_type::TRIGGER_MODAL;
global_calib_status = RS2_CALIBRATION_RETRY;
_process_started = false;
}
return keep_showing;
}

bool cah_model::prompt_reset_popup(device_model & dev_model, ux_window& window, const std::string& error_message)
bool cah_model::prompt_reset_popup(ux_window& window, const std::string& error_message)
{
bool keep_showing = true;
bool yes_was_chosen = false;
Expand All @@ -174,15 +174,15 @@ bool cah_model::prompt_reset_popup(device_model & dev_model, ux_window& window,
{
if (yes_was_chosen)
{
auto itr = std::find_if(dev_model.subdevices.begin(), dev_model.subdevices.end(), [](std::shared_ptr<subdevice_model> sub)
auto itr = std::find_if(_dev_model.subdevices.begin(), _dev_model.subdevices.end(), [](std::shared_ptr<subdevice_model> sub)
{
if (sub->s->as<depth_sensor>())
return true;
return false;
});


if (itr != dev_model.subdevices.end())
if (itr != _dev_model.subdevices.end())
{
auto sd = *itr;
// Trigger CAH process
Expand Down
9 changes: 5 additions & 4 deletions common/cah-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ namespace rs2
class cah_model // CAH = Camera Accuracy Health
{
public:
cah_model();

bool prompt_trigger_popup(device_model & dev_model, ux_window& window, viewer_model& viewer, const std::string& error_message);
bool prompt_reset_popup(device_model & dev_model, ux_window& window, const std::string& error_message);
cah_model(device_model & dev_model, viewer_model& viewer);

bool prompt_trigger_popup(ux_window& window, const std::string& error_message);
bool prompt_reset_popup(ux_window& window, const std::string& error_message);
private:

device_model & _dev_model;
viewer_model& _viewer;
enum class model_state_type { TRIGGER_MODAL, PROCESS_MODAL };
std::atomic<model_state_type> _state; // will be set from a different thread callback function
bool _process_started;
Expand Down
15 changes: 10 additions & 5 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,8 @@ namespace rs2
syncer(viewer.syncer),
_update_readonly_options_timer(std::chrono::seconds(6))
, _detected_objects(std::make_shared< atomic_objects_in_frame >()),
_updates(viewer.updates)
_updates(viewer.updates),
_accuracy_health_model(*this, viewer)
{
auto name = get_device_name(dev);
id = to_string() << name.first << ", " << name.second;
Expand Down Expand Up @@ -4126,7 +4127,7 @@ namespace rs2
return device_names;
}

bool yes_no_dialog(const std::string& title, const std::string& message_text, bool& approved, ux_window& window, const std::string& error_message, bool disabled)
bool yes_no_dialog(const std::string& title, const std::string& message_text, bool& approved, ux_window& window, const std::string& error_message, bool disabled, const std::string& disabled_reason)
{
ImGui_ScopePushFont(window.get_font());
ImGui_ScopePushStyleColor(ImGuiCol_Button, button_color);
Expand All @@ -4153,7 +4154,7 @@ namespace rs2
ImGui_ScopePushStyleColor(ImGuiCol_Text, light_grey);
ImGui::Separator();
ImGui::SetWindowFontScale(1.1f);
ImGui::Text("\n%s\n\n", message_text.c_str());
ImGui::Text("\n%s\n", message_text.c_str());

if (!disabled)
{
Expand All @@ -4179,6 +4180,10 @@ namespace rs2
else
{
ImGui::NewLine();
{
ImGui_ScopePushStyleColor(ImGuiCol_Text, red);
ImGui::Text("%s\n\n", disabled_reason.c_str());
}
auto window_width = ImGui::GetWindowWidth();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + window_width / 2.f - 30.f - ImGui::GetStyle().WindowPadding.x);
if (ImGui::Button("Close", ImVec2(60, 30)))
Expand Down Expand Up @@ -4968,12 +4973,12 @@ namespace rs2

if (show_trigger_camera_accuracy_health_popup)
{
show_trigger_camera_accuracy_health_popup = accuracy_health_model.prompt_trigger_popup(*this, window, viewer, error_message);
show_trigger_camera_accuracy_health_popup = _accuracy_health_model.prompt_trigger_popup(window, error_message);
}

if (show_reset_camera_accuracy_health_popup)
{
show_reset_camera_accuracy_health_popup = accuracy_health_model.prompt_reset_popup(*this, window, error_message);
show_reset_camera_accuracy_health_popup = _accuracy_health_model.prompt_reset_popup(window, error_message);
}

if (keep_showing_advanced_mode_modal)
Expand Down
4 changes: 2 additions & 2 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ namespace rs2
std::string icon[2];
};

bool yes_no_dialog(const std::string& title, const std::string& message_text, bool& approved, ux_window& window, const std::string& error_message, bool disabled = false);
bool yes_no_dialog(const std::string& title, const std::string& message_text, bool& approved, ux_window& window, const std::string& error_message, bool disabled = false, const std::string& disabled_reason = "");
bool status_dialog(const std::string& title, const std::string& process_topic_text, const std::string& process_status_text, bool enable_close, ux_window& window);

class tm2_model
Expand Down Expand Up @@ -810,7 +810,7 @@ namespace rs2
// Needed as a member for reseting the window memory on device disconnection.


cah_model accuracy_health_model;
cah_model _accuracy_health_model;
void draw_info_icon(ux_window& window, ImFont* font, const ImVec2& size);
int draw_seek_bar();
int draw_playback_controls(ux_window& window, ImFont* font, viewer_model& view);
Expand Down

0 comments on commit 05b7e15

Please sign in to comment.