Hi.

Since a week or so, I own an Openbench Logic Sniffer. I've pretty much
given up on the recommended Java-based software, and was very happy to
find sigrok.

I (of course) tried to scan for my sniffer, but sigrok crashed. I dug
around a bit, and realized there was no support for non-list forms of
the samplerate device info.

So I implemented a trivial 1-2-5-based loop to generate a few data
points in the supported interval. The patch is attached, I hope it can
be of use (at least until something better can be implemented).

I also couldn't stop myself from correcting the unit in
sigrok_samplerate_string(), it's not correct to have a capital 'k' for
kilo.

Please keep up the good work, sigrok is a very interesting project. My
Bus Pirate is on order ... :)

Regards,

/Emil
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index b32aa6a..8873226 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -261,12 +261,32 @@ void MainWindow::on_actionScan_triggered()
 
 	/* Populate the combobox with supported samplerates. */
 	ui->comboBoxSampleRate->clear();
-	/* TODO: Samplerate steps support. */
-	for (int i = 0; samplerates->list[i]; ++i) {
-		/* TODO: Free return value of sigrok_samplerate_string(). */
-		s = QString(sigrok_samplerate_string(samplerates->list[i]));
-		ui->comboBoxSampleRate->addItem(s,
-				     QVariant::fromValue(samplerates->list[i]));
+	if (samplerates->list != NULL)
+	{
+		for (int i = 0; samplerates->list[i]; ++i) {
+			char *str = sigrok_samplerate_string(samplerates->list[i]); 
+			s = QString(str);
+			ui->comboBoxSampleRate->addItem(s,
+						 QVariant::fromValue(samplerates->list[i]));
+			free(str);
+		}
+	}
+	else
+	{
+		const static float mult[] = { 2.f, 2.5f, 2.f };
+		int pos = 0;
+
+		for (uint64_t r = samplerates->low; r < samplerates->high; ) {
+			char *str = sigrok_samplerate_string(r); 
+			s = QString(str);
+			ui->comboBoxSampleRate->addItem(s,
+						 QVariant::fromValue(r));
+			free(str);
+			r *= mult[pos];
+			pos++;
+			if (pos > 2)
+				pos = 0;
+		}
 	}
 
 	/* FIXME */
diff --git a/libsigrok/output/common.c b/libsigrok/output/common.c
index 69338f0..cebddc0 100644
--- a/libsigrok/output/common.c
+++ b/libsigrok/output/common.c
@@ -26,7 +26,7 @@
 /**
  * Convert a numeric samplerate value to its "natural" string representation.
  *
- * E.g. a value of 3000000 would be converted to "3 MHz", 20000 to "20 KHz".
+ * E.g. a value of 3000000 would be converted to "3 MHz", 20000 to "20 kHz".
  *
  * @param samplerate The samplerate in Hz.
  * @return A malloc()ed string representation of the samplerate value,
@@ -46,7 +46,7 @@ char *sigrok_samplerate_string(uint64_t samplerate)
 	else if (samplerate >= MHZ(1))
 		r = snprintf(o, 30, "%" PRIu64 " MHz", samplerate / 1000000);
 	else if (samplerate >= KHZ(1))
-		r = snprintf(o, 30, "%" PRIu64 " KHz", samplerate / 1000);
+		r = snprintf(o, 30, "%" PRIu64 " kHz", samplerate / 1000);
 	else
 		r = snprintf(o, 30, "%" PRIu64 " Hz", samplerate);
 
@@ -58,3 +58,4 @@ char *sigrok_samplerate_string(uint64_t samplerate)
 
 	return o;
 }
+
------------------------------------------------------------------------------

_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to