From 5f923711369883dbeed0d77e95b852ea332fb6f0 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Thu, 30 Sep 2021 17:45:10 +0300 Subject: [PATCH 01/13] protect repeated option set --- common/model-views.cpp | 51 ++++++++++++++++++++++++++++++++---------- common/model-views.h | 7 +++++- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 63de8ecea0..7e2f6fd644 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -772,7 +772,9 @@ namespace rs2 { // TODO: Round to step? model.add_log(to_string() << "Setting " << opt << " to " << int_value); - set_option(opt, static_cast(int_value), error_message); + auto set_ok = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(100)); + if (set_ok) + model.add_log(to_string() << opt << " was set to " << int_value); *invalidate_flag = true; res = true; } @@ -824,7 +826,9 @@ namespace rs2 tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); - set_option(opt, tmp_value, error_message); + auto set_ok = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(100)); + if (set_ok) + model.add_log(to_string() << opt << " was set to " << tmp_value); *invalidate_flag = true; res = true; } @@ -2307,19 +2311,42 @@ namespace rs2 return draw(error_message, model); } - void option_model::set_option(rs2_option opt, float req_value, std::string &error_message) + bool option_model::set_option( rs2_option opt, + float req_value, + std::string & error_message, + std::chrono::steady_clock::duration duplicated_set_delay ) { - try - { - endpoint->set_option(opt, req_value); - } - catch (const error& e) + bool option_was_set = false; + + // Only set the value if the value is dofferent that the last requested value or + // `duplicated_set_delay` time past since last option set + if( last_set_stopwatch.get_elapsed() > duplicated_set_delay + || req_value != last_requested_value ) { - error_message = error_to_string(e); + try + { + endpoint->set_option( opt, req_value ); + last_set_stopwatch.reset(); + last_requested_value = req_value; + option_was_set = true; + } + catch( const error & e ) + { + error_message = error_to_string( e ); + } + + // Only update the cached value once set_option is done! That way, if it doesn't change + // anything... + try + { + value = endpoint->get_option( opt ); + } + catch( ... ) + { + } } - // Only update the cached value once set_option is done! That way, if it doesn't change anything... - try { value = endpoint->get_option(opt); } - catch (...) {} + + return option_was_set; } stream_model::stream_model() diff --git a/common/model-views.h b/common/model-views.h index 95ad9e2af9..8672735020 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -314,13 +314,18 @@ namespace rs2 void update_supported(std::string& error_message); void update_read_only_status(std::string& error_message); void update_all_fields(std::string& error_message, notifications_model& model); - void set_option(rs2_option opt, float value, std::string &error_message); + bool set_option( rs2_option opt, + float value, + std::string & error_message, + std::chrono::steady_clock::duration duplicated_set_delay = std::chrono::seconds( 0 ) ); bool draw_option(bool update_read_only_options, bool is_streaming, std::string& error_message, notifications_model& model); rs2_option opt; option_range range; std::shared_ptr endpoint; + float last_requested_value = 0; + utilities::time::stopwatch last_set_stopwatch; bool* invalidate_flag = nullptr; bool supported = false; bool read_only = false; From 2e9eac4cc30ba521b64d5f16d6d9adc7060338d6 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Thu, 30 Sep 2021 17:55:20 +0300 Subject: [PATCH 02/13] merge option set logs --- common/model-views.cpp | 57 +++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 7e2f6fd644..5fe123ef2b 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -771,10 +771,8 @@ namespace rs2 static_cast(range.step))) { // TODO: Round to step? - model.add_log(to_string() << "Setting " << opt << " to " << int_value); auto set_ok = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(100)); - if (set_ok) - model.add_log(to_string() << opt << " was set to " << int_value); + if (set_ok) model.add_log(to_string() << "Setting " << opt << " to " << int_value ); *invalidate_flag = true; res = true; } @@ -825,10 +823,8 @@ namespace rs2 tmp_value = (loffset < roffset) ? tmp_value + loffset : tmp_value - roffset; tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; - model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); auto set_ok = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(100)); - if (set_ok) - model.add_log(to_string() << opt << " was set to " << tmp_value); + if (set_ok) model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); *invalidate_flag = true; res = true; } @@ -2317,33 +2313,32 @@ namespace rs2 std::chrono::steady_clock::duration duplicated_set_delay ) { bool option_was_set = false; - - // Only set the value if the value is dofferent that the last requested value or - // `duplicated_set_delay` time past since last option set - if( last_set_stopwatch.get_elapsed() > duplicated_set_delay - || req_value != last_requested_value ) + // Only set the value if the value is different than the last requested value or + // `duplicated_set_delay` time past since last set_option() call + if ( last_set_stopwatch.get_elapsed() < duplicated_set_delay && + req_value == last_requested_value ) + return option_was_set; + + try { - try - { - endpoint->set_option( opt, req_value ); - last_set_stopwatch.reset(); - last_requested_value = req_value; - option_was_set = true; - } - catch( const error & e ) - { - error_message = error_to_string( e ); - } + endpoint->set_option( opt, req_value ); + last_set_stopwatch.reset(); + last_requested_value = req_value; + option_was_set = true; + } + catch( const error & e ) + { + error_message = error_to_string( e ); + } - // Only update the cached value once set_option is done! That way, if it doesn't change - // anything... - try - { - value = endpoint->get_option( opt ); - } - catch( ... ) - { - } + // Only update the cached value once set_option is done! That way, if it doesn't change + // anything... + try + { + value = endpoint->get_option( opt ); + } + catch( ... ) + { } return option_was_set; From 76880d5a573fed781fe9cfc354e71ce7b9adb178 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 09:20:38 +0300 Subject: [PATCH 03/13] add delayed set --- common/model-views.cpp | 72 +++++++++++++++++++++++++++++++++++------- common/model-views.h | 2 +- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 5fe123ef2b..36976ecdd1 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -771,11 +771,39 @@ namespace rs2 static_cast(range.step))) { // TODO: Round to step? - auto set_ok = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(100)); - if (set_ok) model.add_log(to_string() << "Setting " << opt << " to " << int_value ); + auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(100)); + if( option_was_set ) + { + delay_set = false; + model.add_log( to_string() << "Setting " << opt << " to " << int_value ); + } + else + { + delay_set = true; + last_requested_value = static_cast< float >( int_value ); + } *invalidate_flag = true; res = true; } + else + { + // Slider unselected, if last value was ignored, set with last + // value. + if( delay_set ) + { + auto option_was_set + = set_option( opt, + last_requested_value, + error_message, + std::chrono::milliseconds( 100 ) ); + if( option_was_set ) + { + model.add_log( to_string() << "Setting " << opt << " to " + << last_requested_value ); + delay_set = false; + } + } + } } else { @@ -811,6 +839,7 @@ namespace rs2 std::stringstream formatting_ss; formatting_ss << "%." << num_of_decimal_digits_displayed << "f"; + if (ImGui::SliderFloat(id.c_str(), &temp_value_displayed, min_range_displayed, max_range_displayed, formatting_ss.str().c_str())) { @@ -823,11 +852,35 @@ namespace rs2 tmp_value = (loffset < roffset) ? tmp_value + loffset : tmp_value - roffset; tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; - auto set_ok = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(100)); - if (set_ok) model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); + auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(100)); + // if the set gets delayed save the value for later + if (option_was_set) + { + delay_set = false; + model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); + } + else + { + delay_set = true; + last_requested_value = tmp_value; + } *invalidate_flag = true; res = true; } + else + { + // Slider unselected, if last value was ignored, set with last value. + if (delay_set) + { + auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); + if (set_ok) + { + model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + delay_set = false; + } + + } + } } } catch (const error& e) @@ -2310,20 +2363,17 @@ namespace rs2 bool option_model::set_option( rs2_option opt, float req_value, std::string & error_message, - std::chrono::steady_clock::duration duplicated_set_delay ) + std::chrono::steady_clock::duration ignore_period ) { bool option_was_set = false; - // Only set the value if the value is different than the last requested value or - // `duplicated_set_delay` time past since last set_option() call - if ( last_set_stopwatch.get_elapsed() < duplicated_set_delay && - req_value == last_requested_value ) - return option_was_set; + // Only set the value if `ignore_period` time past since last set_option() call for this option + if ( last_set_stopwatch.get_elapsed() < ignore_period ) + return false; try { endpoint->set_option( opt, req_value ); last_set_stopwatch.reset(); - last_requested_value = req_value; option_was_set = true; } catch( const error & e ) diff --git a/common/model-views.h b/common/model-views.h index 8672735020..c09dacad15 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -317,7 +317,7 @@ namespace rs2 bool set_option( rs2_option opt, float value, std::string & error_message, - std::chrono::steady_clock::duration duplicated_set_delay = std::chrono::seconds( 0 ) ); + std::chrono::steady_clock::duration ignore_period = std::chrono::seconds( 0 ) ); bool draw_option(bool update_read_only_options, bool is_streaming, std::string& error_message, notifications_model& model); From 8866b5262f53aaab7d0c739aa85784d3d7cd0a61 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 09:30:01 +0300 Subject: [PATCH 04/13] add delayed set --- common/model-views.cpp | 4 ++-- common/model-views.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 36976ecdd1..d58fa969a8 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -532,6 +532,8 @@ namespace rs2 option.label = options->get_option_name(opt) + std::string("##") + ss.str(); option.invalidate_flag = options_invalidated; option.dev = model; + option.range = { 0, 1, 0, 0 }; + option.value = 0; option.supported = options->supports(opt); if (option.supported) @@ -544,8 +546,6 @@ namespace rs2 } catch (const error& e) { - option.range = { 0, 1, 0, 0 }; - option.value = 0; error_message = error_to_string(e); } } diff --git a/common/model-views.h b/common/model-views.h index c09dacad15..c4fa95a683 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -325,6 +325,7 @@ namespace rs2 option_range range; std::shared_ptr endpoint; float last_requested_value = 0; + bool delay_set = false; utilities::time::stopwatch last_set_stopwatch; bool* invalidate_flag = nullptr; bool supported = false; From b358d30e714312bbced621e787763a48c8180fa4 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 11:39:52 +0300 Subject: [PATCH 05/13] increase set delay to 150 ms --- common/model-views.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index d58fa969a8..f0229df9d5 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -771,7 +771,7 @@ namespace rs2 static_cast(range.step))) { // TODO: Round to step? - auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(100)); + auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(150)); if( option_was_set ) { delay_set = false; @@ -795,7 +795,7 @@ namespace rs2 = set_option( opt, last_requested_value, error_message, - std::chrono::milliseconds( 100 ) ); + std::chrono::milliseconds( 150 ) ); if( option_was_set ) { model.add_log( to_string() << "Setting " << opt << " to " From 64f0aaf376f9ca8c537299a1db4b0d625d4ee673 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 12:03:09 +0300 Subject: [PATCH 06/13] try set once on button unclick --- common/model-views.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index f0229df9d5..97d9049edb 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -791,15 +791,10 @@ namespace rs2 // value. if( delay_set ) { - auto option_was_set - = set_option( opt, - last_requested_value, - error_message, - std::chrono::milliseconds( 150 ) ); - if( option_was_set ) + auto set_ok = set_option( opt, last_requested_value, error_message, std::chrono::milliseconds(150)); + if (set_ok) { - model.add_log( to_string() << "Setting " << opt << " to " - << last_requested_value ); + model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); delay_set = false; } } @@ -852,7 +847,7 @@ namespace rs2 tmp_value = (loffset < roffset) ? tmp_value + loffset : tmp_value - roffset; tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; - auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(100)); + auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(150)); // if the set gets delayed save the value for later if (option_was_set) { @@ -870,9 +865,9 @@ namespace rs2 else { // Slider unselected, if last value was ignored, set with last value. - if (delay_set) + if ( delay_set ) { - auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); + auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(150)); if (set_ok) { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); @@ -2372,9 +2367,9 @@ namespace rs2 try { - endpoint->set_option( opt, req_value ); - last_set_stopwatch.reset(); option_was_set = true; + last_set_stopwatch.reset(); + endpoint->set_option( opt, req_value ); } catch( const error & e ) { From 142032675bccc3d05c4377173f73386997f4d0e4 Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 16:45:47 +0300 Subject: [PATCH 07/13] set delayed option only if changed --- common/model-views.cpp | 37 ++++++++++++++++++++++++------------- common/model-views.h | 1 + 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 97d9049edb..1abea93c42 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -771,10 +771,11 @@ namespace rs2 static_cast(range.step))) { // TODO: Round to step? - auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(150)); + auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(200)); if( option_was_set ) { delay_set = false; + last_set_value = static_cast(int_value); model.add_log( to_string() << "Setting " << opt << " to " << int_value ); } else @@ -787,16 +788,20 @@ namespace rs2 } else { - // Slider unselected, if last value was ignored, set with last - // value. + // Slider unselected, if last value was ignored, set with last value if the value was changed. if( delay_set ) { - auto set_ok = set_option( opt, last_requested_value, error_message, std::chrono::milliseconds(150)); - if (set_ok) + if (last_set_value != last_requested_value) { - model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); - delay_set = false; + auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); + if (set_ok) + { + model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + delay_set = false; + } } + else + delay_set = false; } } } @@ -847,11 +852,12 @@ namespace rs2 tmp_value = (loffset < roffset) ? tmp_value + loffset : tmp_value - roffset; tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; - auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(150)); + auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(200)); // if the set gets delayed save the value for later if (option_was_set) { delay_set = false; + last_set_value = tmp_value; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); } else @@ -864,15 +870,20 @@ namespace rs2 } else { - // Slider unselected, if last value was ignored, set with last value. + // Slider unselected, if last value was ignored, set with last value if the value was changed. if ( delay_set ) { - auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(150)); - if (set_ok) + if (last_set_value != last_requested_value) { - model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); - delay_set = false; + auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); + if (set_ok) + { + model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + delay_set = false; + } } + else + delay_set = false; } } diff --git a/common/model-views.h b/common/model-views.h index c4fa95a683..110e19231e 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -325,6 +325,7 @@ namespace rs2 option_range range; std::shared_ptr endpoint; float last_requested_value = 0; + float last_set_value = 0; bool delay_set = false; utilities::time::stopwatch last_set_stopwatch; bool* invalidate_flag = nullptr; From b17033e2d6a7391a937bd0ba036dc2e44d155edd Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 4 Oct 2021 20:50:14 +0300 Subject: [PATCH 08/13] invalidate options only after set --- common/model-views.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 1abea93c42..f70cc05570 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -776,6 +776,7 @@ namespace rs2 { delay_set = false; last_set_value = static_cast(int_value); + *invalidate_flag = true; model.add_log( to_string() << "Setting " << opt << " to " << int_value ); } else @@ -783,7 +784,7 @@ namespace rs2 delay_set = true; last_requested_value = static_cast< float >( int_value ); } - *invalidate_flag = true; + res = true; } else @@ -798,6 +799,7 @@ namespace rs2 { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); delay_set = false; + *invalidate_flag = true; } } else @@ -858,6 +860,7 @@ namespace rs2 { delay_set = false; last_set_value = tmp_value; + *invalidate_flag = true; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); } else @@ -865,7 +868,7 @@ namespace rs2 delay_set = true; last_requested_value = tmp_value; } - *invalidate_flag = true; + res = true; } else @@ -879,6 +882,7 @@ namespace rs2 if (set_ok) { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + *invalidate_flag = true; delay_set = false; } } From ef75fce6c56f99149d1e644bcea229c67666ac8e Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Tue, 5 Oct 2021 11:56:21 +0300 Subject: [PATCH 09/13] move res close to set --- common/model-views.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index f70cc05570..8b54aa0233 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -778,14 +778,13 @@ namespace rs2 last_set_value = static_cast(int_value); *invalidate_flag = true; model.add_log( to_string() << "Setting " << opt << " to " << int_value ); + res = true; } else { delay_set = true; last_requested_value = static_cast< float >( int_value ); } - - res = true; } else { @@ -800,6 +799,7 @@ namespace rs2 model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); delay_set = false; *invalidate_flag = true; + res = true; } } else @@ -862,14 +862,14 @@ namespace rs2 last_set_value = tmp_value; *invalidate_flag = true; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); + res = true; } else { delay_set = true; last_requested_value = tmp_value; + res = true; } - - res = true; } else { From bb2425179100b17a6fe3e32318f8c85dcb08df5c Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Wed, 6 Oct 2021 10:50:52 +0300 Subject: [PATCH 10/13] invalidate options only when unclicking slider --- common/model-views.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 8b54aa0233..c5e830084d 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -776,7 +776,6 @@ namespace rs2 { delay_set = false; last_set_value = static_cast(int_value); - *invalidate_flag = true; model.add_log( to_string() << "Setting " << opt << " to " << int_value ); res = true; } @@ -798,13 +797,14 @@ namespace rs2 { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); delay_set = false; - *invalidate_flag = true; res = true; } } else delay_set = false; } + + if (res) *invalidate_flag = true; } } else @@ -860,7 +860,6 @@ namespace rs2 { delay_set = false; last_set_value = tmp_value; - *invalidate_flag = true; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); res = true; } @@ -868,7 +867,6 @@ namespace rs2 { delay_set = true; last_requested_value = tmp_value; - res = true; } } else @@ -882,14 +880,16 @@ namespace rs2 if (set_ok) { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); - *invalidate_flag = true; delay_set = false; + res = true; } } else delay_set = false; } + + if (res) *invalidate_flag = true; } } } From 5104956e8faa1cb27e3048d5507e738a4ba0ce3a Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Wed, 6 Oct 2021 11:46:53 +0300 Subject: [PATCH 11/13] invalidate on set --- common/model-views.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index c5e830084d..1ec559dab6 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -776,6 +776,7 @@ namespace rs2 { delay_set = false; last_set_value = static_cast(int_value); + *invalidate_flag = true; model.add_log( to_string() << "Setting " << opt << " to " << int_value ); res = true; } @@ -796,6 +797,8 @@ namespace rs2 if (set_ok) { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + *invalidate_flag = true; + last_set_value = last_requested_value; delay_set = false; res = true; } @@ -803,8 +806,6 @@ namespace rs2 else delay_set = false; } - - if (res) *invalidate_flag = true; } } else @@ -861,6 +862,7 @@ namespace rs2 delay_set = false; last_set_value = tmp_value; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); + *invalidate_flag = true; res = true; } else @@ -880,6 +882,8 @@ namespace rs2 if (set_ok) { model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + *invalidate_flag = true; + last_set_value = last_requested_value; delay_set = false; res = true; } @@ -888,8 +892,6 @@ namespace rs2 delay_set = false; } - - if (res) *invalidate_flag = true; } } } From b8028d291921233940548c6f6cc3e79cf0ccba5e Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Wed, 6 Oct 2021 15:38:18 +0300 Subject: [PATCH 12/13] CR fixes --- common/model-views.cpp | 46 ++++++++++++++++++------------------------ common/model-views.h | 5 ++--- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index 1ec559dab6..dcf1c363fd 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -774,37 +774,35 @@ namespace rs2 auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(200)); if( option_was_set ) { - delay_set = false; - last_set_value = static_cast(int_value); + have_unset_value = false; *invalidate_flag = true; model.add_log( to_string() << "Setting " << opt << " to " << int_value ); res = true; } else { - delay_set = true; - last_requested_value = static_cast< float >( int_value ); + have_unset_value = true; + unset_value = static_cast< float >( int_value ); } } else { // Slider unselected, if last value was ignored, set with last value if the value was changed. - if( delay_set ) + if( have_unset_value ) { - if (last_set_value != last_requested_value) + if (value != unset_value) { - auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); + auto set_ok = set_option(opt, unset_value, error_message, std::chrono::milliseconds(100)); if (set_ok) { - model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + model.add_log(to_string() << "Setting " << opt << " to " << unset_value); *invalidate_flag = true; - last_set_value = last_requested_value; - delay_set = false; + have_unset_value = false; res = true; } } else - delay_set = false; + have_unset_value = false; } } } @@ -859,37 +857,35 @@ namespace rs2 // if the set gets delayed save the value for later if (option_was_set) { - delay_set = false; - last_set_value = tmp_value; + have_unset_value = false; model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); *invalidate_flag = true; res = true; } else { - delay_set = true; - last_requested_value = tmp_value; + have_unset_value = true; + unset_value = tmp_value; } } else { // Slider unselected, if last value was ignored, set with last value if the value was changed. - if ( delay_set ) + if ( have_unset_value ) { - if (last_set_value != last_requested_value) + if (value != unset_value) { - auto set_ok = set_option(opt, last_requested_value, error_message, std::chrono::milliseconds(100)); - if (set_ok) + auto set_ok = set_option(opt, unset_value, error_message, std::chrono::milliseconds(100)); + if ( set_ok ) { - model.add_log(to_string() << "Setting " << opt << " to " << last_requested_value); + model.add_log(to_string() << "Setting " << opt << " to " << unset_value); *invalidate_flag = true; - last_set_value = last_requested_value; - delay_set = false; + have_unset_value = false; res = true; } } else - delay_set = false; + have_unset_value = false; } } @@ -2377,14 +2373,12 @@ namespace rs2 std::string & error_message, std::chrono::steady_clock::duration ignore_period ) { - bool option_was_set = false; // Only set the value if `ignore_period` time past since last set_option() call for this option if ( last_set_stopwatch.get_elapsed() < ignore_period ) return false; try { - option_was_set = true; last_set_stopwatch.reset(); endpoint->set_option( opt, req_value ); } @@ -2403,7 +2397,7 @@ namespace rs2 { } - return option_was_set; + return true; } stream_model::stream_model() diff --git a/common/model-views.h b/common/model-views.h index 110e19231e..8b680eb3a2 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -324,9 +324,8 @@ namespace rs2 rs2_option opt; option_range range; std::shared_ptr endpoint; - float last_requested_value = 0; - float last_set_value = 0; - bool delay_set = false; + float unset_value = 0; + bool have_unset_value = false; utilities::time::stopwatch last_set_stopwatch; bool* invalidate_flag = nullptr; bool supported = false; From f64ef8e8b4f160910804b753908bdcce52e81d1c Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Wed, 6 Oct 2021 16:09:23 +0300 Subject: [PATCH 13/13] move duplicated code into functions --- common/model-views.cpp | 124 ++++++++++++++++++++--------------------- common/model-views.h | 9 +++ 2 files changed, 69 insertions(+), 64 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index dcf1c363fd..f6a6581594 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -771,39 +771,11 @@ namespace rs2 static_cast(range.step))) { // TODO: Round to step? - auto option_was_set = set_option(opt, static_cast(int_value), error_message, std::chrono::milliseconds(200)); - if( option_was_set ) - { - have_unset_value = false; - *invalidate_flag = true; - model.add_log( to_string() << "Setting " << opt << " to " << int_value ); - res = true; - } - else - { - have_unset_value = true; - unset_value = static_cast< float >( int_value ); - } + res = slider_selected( opt, static_cast< float >( int_value ), error_message, model ); } else { - // Slider unselected, if last value was ignored, set with last value if the value was changed. - if( have_unset_value ) - { - if (value != unset_value) - { - auto set_ok = set_option(opt, unset_value, error_message, std::chrono::milliseconds(100)); - if (set_ok) - { - model.add_log(to_string() << "Setting " << opt << " to " << unset_value); - *invalidate_flag = true; - have_unset_value = false; - res = true; - } - } - else - have_unset_value = false; - } + res = slider_unselected( opt, static_cast< float >( int_value ), error_message, model ); } } else @@ -840,7 +812,7 @@ namespace rs2 std::stringstream formatting_ss; formatting_ss << "%." << num_of_decimal_digits_displayed << "f"; - + if (ImGui::SliderFloat(id.c_str(), &temp_value_displayed, min_range_displayed, max_range_displayed, formatting_ss.str().c_str())) { @@ -853,41 +825,12 @@ namespace rs2 tmp_value = (loffset < roffset) ? tmp_value + loffset : tmp_value - roffset; tmp_value = (tmp_value < range.min) ? range.min : tmp_value; tmp_value = (tmp_value > range.max) ? range.max : tmp_value; - auto option_was_set = set_option(opt, tmp_value, error_message, std::chrono::milliseconds(200)); - // if the set gets delayed save the value for later - if (option_was_set) - { - have_unset_value = false; - model.add_log(to_string() << "Setting " << opt << " to " << tmp_value); - *invalidate_flag = true; - res = true; - } - else - { - have_unset_value = true; - unset_value = tmp_value; - } + + res = slider_selected( opt, tmp_value, error_message, model ); } else - { - // Slider unselected, if last value was ignored, set with last value if the value was changed. - if ( have_unset_value ) - { - if (value != unset_value) - { - auto set_ok = set_option(opt, unset_value, error_message, std::chrono::milliseconds(100)); - if ( set_ok ) - { - model.add_log(to_string() << "Setting " << opt << " to " << unset_value); - *invalidate_flag = true; - have_unset_value = false; - res = true; - } - } - else - have_unset_value = false; - - } + { + res = slider_unselected( opt, tmp_value, error_message, model ); } } } @@ -1068,6 +1011,59 @@ namespace rs2 return true; } + bool option_model::slider_selected( rs2_option opt, + float value, + std::string & error_message, + notifications_model & model ) + { + bool res = false; + auto option_was_set + = set_option( opt, value, error_message, std::chrono::milliseconds( 200 ) ); + if( option_was_set ) + { + have_unset_value = false; + *invalidate_flag = true; + model.add_log( to_string() << "Setting " << opt << " to " << value ); + res = true; + } + else + { + have_unset_value = true; + unset_value = value; + } + return res; + } + bool option_model::slider_unselected( rs2_option opt, + float value, + std::string & error_message, + notifications_model & model ) + { + bool res = false; + // Slider unselected, if last value was ignored, set with last value if the value was + // changed. + if( have_unset_value ) + { + if( value != unset_value ) + { + auto set_ok = set_option( opt, + unset_value, + error_message, + std::chrono::milliseconds( 100 ) ); + if( set_ok ) + { + model.add_log( to_string() << "Setting " << opt << " to " << unset_value ); + *invalidate_flag = true; + have_unset_value = false; + res = true; + } + } + else + have_unset_value = false; + } + return res; + } + + void subdevice_model::populate_options(std::map& opt_container, const std::string& opt_base_label, subdevice_model* model, diff --git a/common/model-views.h b/common/model-views.h index 8b680eb3a2..68e94cfcf4 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -342,6 +342,15 @@ namespace rs2 bool is_enum() const; bool is_checkbox() const; bool allow_change(float val, std::string& error_message) const; + bool slider_selected( rs2_option opt, + float value, + std::string& error_message, + notifications_model& model); + + bool slider_unselected(rs2_option opt, + float value, + std::string& error_message, + notifications_model& model); }; class frame_queues