Skip to content

Commit 7ffab48

Browse files
Fix issues under demo mode
1 parent 5a806e4 commit 7ffab48

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

DSView/pv/toolbars/samplingbar.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ void SamplingBar::update_sample_count_selector()
529529
}
530530
_updating_sample_count = false;
531531

532-
if (dev_inst->dev_inst()->mode == DSO)
533-
update_sample_count_selector_value();
532+
update_sample_count_selector_value();
534533
connect(&_sample_count, SIGNAL(currentIndexChanged(int)),
535534
this, SLOT(on_samplecount_sel(int)));
536535
}
@@ -541,22 +540,36 @@ void SamplingBar::update_sample_count_selector_value()
541540
return;
542541

543542
GVariant* gvar;
544-
double hori_res;
545-
gvar = get_selected_device()->get_config(NULL, NULL, SR_CONF_TIMEBASE);
546-
if (gvar != NULL) {
547-
hori_res = g_variant_get_uint64(gvar);
548-
g_variant_unref(gvar);
543+
double duration;
544+
const shared_ptr<device::DevInst> dev_inst = get_selected_device();
545+
if (dev_inst->dev_inst()->mode == DSO) {
546+
gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TIMEBASE);
547+
if (gvar != NULL) {
548+
duration = g_variant_get_uint64(gvar);
549+
g_variant_unref(gvar);
550+
} else {
551+
qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
552+
return;
553+
}
549554
} else {
550-
qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
551-
return;
555+
gvar = dev_inst->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES);
556+
if (gvar != NULL) {
557+
duration = g_variant_get_uint64(gvar);
558+
g_variant_unref(gvar);
559+
} else {
560+
qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
561+
return;
562+
}
563+
const uint64_t samplerate = dev_inst->get_sample_rate();
564+
duration = duration / samplerate * SR_SEC(1);
552565
}
553566
assert(!_updating_sample_count);
554567
_updating_sample_count = true;
555568

556-
if (hori_res != _sample_count.itemData(
569+
if (duration != _sample_count.itemData(
557570
_sample_count.currentIndex()).value<double>()) {
558-
for (int i = _sample_count.count() - 1; i >= 0; i--) {
559-
if (hori_res == _sample_count.itemData(
571+
for (int i = 0; i < _sample_count.count(); i++) {
572+
if (duration >= _sample_count.itemData(
560573
i).value<double>()) {
561574
_sample_count.setCurrentIndex(i);
562575
break;
@@ -603,8 +616,6 @@ double SamplingBar::commit_hori_res()
603616
const double hori_res = _sample_count.itemData(
604617
_sample_count.currentIndex()).value<double>();
605618

606-
if (_session.get_capture_state() == SigSession::Running)
607-
_session.refresh(RefreshShort);
608619
const shared_ptr<device::DevInst> dev_inst = get_selected_device();
609620
const uint64_t sample_limit = dev_inst->get_sample_limit();
610621
GVariant* gvar;

DSView/pv/view/dsosignal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void DsoSignal::set_enable(bool enable)
170170
g_variant_new_boolean(enable));
171171

172172
if (running) {
173+
//_view->session().refresh(RefreshShort);
173174
_view->update_hori_res();
174175
_view->session().repeat_resume();
175176
}

libsigrok4DSL/hardware/demo/demo.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ static const uint64_t samplerates[] = {
276276
SR_MHZ(50),
277277
SR_MHZ(100),
278278
SR_MHZ(200),
279-
SR_MHZ(400),
280279
};
281280

282281
//static const uint64_t samplecounts[] = {
@@ -321,10 +320,10 @@ static const uint64_t samplecounts[] = {
321320

322321
/* We name the probes 0-7 on our demo driver. */
323322
static const char *probe_names[NUM_PROBES + 1] = {
324-
"CH0", "CH1", "CH2", "CH3",
325-
"CH4", "CH5", "CH6", "CH7",
326-
"CH8", "CH9", "CH10", "CH11",
327-
"CH12", "CH13", "CH14", "CH15",
323+
"0", "1", "2", "3",
324+
"4", "5", "6", "7",
325+
"8", "9", "10", "11",
326+
"12", "13", "14", "15",
328327
NULL,
329328
};
330329

@@ -714,8 +713,8 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
714713
devc->limit_samples_show = devc->limit_samples;
715714
} else if (sdi->mode == ANALOG) {
716715
num_probes = DS_MAX_ANALOG_PROBES_NUM;
717-
devc->cur_samplerate = SR_HZ(100);
718-
devc->limit_samples = SR_KB(1);
716+
devc->cur_samplerate = SR_KHZ(1);
717+
devc->limit_samples = SR_KB(2);
719718
devc->limit_samples_show = devc->limit_samples;
720719
} else {
721720
num_probes = 0;
@@ -765,6 +764,9 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
765764
ret = SR_OK;
766765
} else if (id == SR_CONF_PROBE_EN) {
767766
ch->enabled = g_variant_get_boolean(data);
767+
if (en_ch_num(sdi) != 0) {
768+
devc->limit_samples_show = DEMO_MAX_DSO_DEPTH / en_ch_num(sdi);
769+
}
768770
sr_dbg("%s: setting ENABLE of channel %d to %d", __func__,
769771
ch->index, ch->enabled);
770772
ret = SR_OK;
@@ -858,8 +860,15 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
858860
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
859861
// gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
860862
// ARRAY_SIZE(samplerates), sizeof(uint64_t));
861-
gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"),
862-
samplerates, ARRAY_SIZE(samplerates)*sizeof(uint64_t), TRUE, NULL, NULL);
863+
if (sdi->mode == ANALOG)
864+
gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"),
865+
samplerates, 16*sizeof(uint64_t), TRUE, NULL, NULL);
866+
else if (sdi->mode == LOGIC)
867+
gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"),
868+
samplerates, 19*sizeof(uint64_t), TRUE, NULL, NULL);
869+
else
870+
gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"),
871+
samplerates, ARRAY_SIZE(samplerates)*sizeof(uint64_t), TRUE, NULL, NULL);
863872
g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
864873
*data = g_variant_builder_end(&gvb);
865874
break;
@@ -1071,7 +1080,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
10711080
samples_to_send = MIN(samples_to_send,
10721081
devc->limit_samples - devc->pre_index);
10731082
} else if (sdi->mode == ANALOG) {
1074-
samples_to_send = ceil(samples_elaspsed/2);
1083+
samples_to_send = ceil(samples_elaspsed);
10751084
samples_to_send = MIN(samples_to_send,
10761085
devc->limit_samples - devc->pre_index);
10771086
} else {
@@ -1090,7 +1099,10 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
10901099

10911100
if (samples_to_send > 0 && !devc->stop) {
10921101
sending_now = MIN(samples_to_send, (sdi->mode == DSO ) ? DSO_BUFSIZE : BUFSIZE);
1093-
samples_generator(devc->buf, sending_now, sdi, devc);
1102+
if (sdi->mode == ANALOG)
1103+
samples_generator(devc->buf, sending_now*2, sdi, devc);
1104+
else
1105+
samples_generator(devc->buf, sending_now, sdi, devc);
10941106

10951107
if (devc->trigger_stage != 0) {
10961108
for (i = 0; i < sending_now; i++) {
@@ -1123,10 +1135,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
11231135
}
11241136
}
11251137

1126-
if (sdi->mode == ANALOG)
1127-
devc->samples_counter += sending_now/2;
1128-
else
1129-
devc->samples_counter += sending_now;
1138+
devc->samples_counter += sending_now;
11301139
if (sdi->mode == DSO && !devc->instant &&
11311140
devc->samples_counter > devc->limit_samples)
11321141
devc->samples_counter = devc->limit_samples;
@@ -1157,7 +1166,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
11571166
packet.type = SR_DF_ANALOG;
11581167
packet.payload = &analog;
11591168
analog.probes = sdi->channels;
1160-
analog.num_samples = sending_now / 2;
1169+
analog.num_samples = sending_now;
11611170
analog.unit_bits = 8;
11621171
analog.mq = SR_MQ_VOLTAGE;
11631172
analog.unit = SR_UNIT_VOLT;
@@ -1241,7 +1250,7 @@ static int hw_dev_acquisition_start(struct sr_dev_inst *sdi,
12411250
//std_session_send_df_header(cb_data, LOG_PREFIX);
12421251
std_session_send_df_header(sdi, LOG_PREFIX);
12431252

1244-
if (!(devc->buf = g_try_malloc(((sdi->mode == DSO ) ? DSO_BUFSIZE : BUFSIZE)*sizeof(uint16_t)))) {
1253+
if (!(devc->buf = g_try_malloc(((sdi->mode == DSO ) ? DSO_BUFSIZE : (sdi->mode == ANALOG ) ? 2*BUFSIZE : BUFSIZE)*sizeof(uint16_t)))) {
12451254
sr_err("buf for receive_data malloc failed.");
12461255
return FALSE;
12471256
}

0 commit comments

Comments
 (0)