]> sigrok.org Git - pulseview.git/commitdiff
Show a 1-2-5 list for the sample count widget
authorJoel Holdsworth <redacted>
Sun, 19 Jan 2014 14:49:45 +0000 (14:49 +0000)
committerJoel Holdsworth <redacted>
Sun, 19 Jan 2014 22:06:51 +0000 (22:06 +0000)
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index 79dd7a1a37a68e4c5790171b409fdf66242e8808..036294bcf063a850029c854021890e9d6db36f0a 100644 (file)
 #include <pv/popups/deviceoptions.h>
 #include <pv/popups/probes.h>
 
+using std::max;
+using std::min;
 using std::string;
 
 namespace pv {
 namespace toolbars {
 
-const uint64_t SamplingBar::DefaultRecordLength = 1000000;
+const uint64_t SamplingBar::MinSampleCount = 100ULL;
+const uint64_t SamplingBar::MaxSampleCount = 1000000000000ULL;
+const uint64_t SamplingBar::DefaultSampleCount = 1000000;
 
 SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
        QToolBar("Sampling Bar", parent),
@@ -223,24 +227,41 @@ void SamplingBar::update_sample_count_selector()
 {
        sr_dev_inst *const sdi = get_selected_device();
        GVariant *gvar;
-       uint64_t samplecount = 0;
 
        assert(sdi);
 
-       if (_sample_count_supported)
-               _sample_count.show_min_max_step(0, UINT64_MAX, 1);
-       else
-               _sample_count.show_none();
+       _updating_sample_count = true;
 
-       if (sr_config_get(sdi->driver, sdi, NULL,
-               SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK)
+       if (_sample_count_supported)
        {
-               samplecount = g_variant_get_uint64(gvar);
-               g_variant_unref(gvar);
+               uint64_t sample_count = DefaultSampleCount;
+               uint64_t max_sample_count = MaxSampleCount;
+
+               if (sr_config_get(sdi->driver, sdi, NULL,
+                       SR_CONF_MAX_UNCOMPRESSED_SAMPLES, &gvar) == SR_OK) {
+                       max_sample_count = g_variant_get_uint64(gvar);
+                       g_variant_unref(gvar);
+               }
+
+               _sample_count.show_125_list(MinSampleCount, max_sample_count);
+
+               if (sr_config_get(sdi->driver, sdi, NULL,
+                       SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK)
+               {
+                       sample_count = g_variant_get_uint64(gvar);
+                       if (sample_count == 0)
+                               sample_count = DefaultSampleCount;
+                       sample_count = min(max(sample_count, MinSampleCount),
+                               max_sample_count);
+
+                       g_variant_unref(gvar);
+               }
+
+               _sample_count.set_value(sample_count);
        }
+       else
+               _sample_count.show_none();
 
-       _updating_sample_count = true;
-       _sample_count.set_value(samplecount);
        _updating_sample_count = false;
 }
 
@@ -328,11 +349,6 @@ void SamplingBar::on_device_selected()
        // Update sweep timing widgets.
        update_sample_count_selector();
        update_sample_rate_selector();
-
-       if (_sample_count_supported && _sample_count.value() == 0) {
-               _sample_count.set_value(DefaultRecordLength);
-               commit_sample_count();
-       }
 }
 
 void SamplingBar::on_sample_count_changed()
@@ -349,6 +365,7 @@ void SamplingBar::on_sample_rate_changed()
 
 void SamplingBar::on_run_stop()
 {
+       commit_sample_count();
        commit_sample_rate();   
        run_stop();
 }
index db4c10e48fa4065221cb3004c250a00abc1a222f..6fc8abd38e0fcdce4bcd6a45f2a4a36233f0b424 100644 (file)
@@ -48,7 +48,9 @@ class SamplingBar : public QToolBar
        Q_OBJECT
 
 private:
-       static const uint64_t DefaultRecordLength;
+       static const uint64_t MinSampleCount;
+       static const uint64_t MaxSampleCount;
+       static const uint64_t DefaultSampleCount;
 
 public:
        SamplingBar(SigSession &session, QWidget *parent);