- analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_channels);
- data_offset = 0;
- for (i = 0; i < analog.num_samples; i++) {
- /*
- * The device always sends data for both channels. If a channel
- * is disabled, it contains a copy of the enabled channel's
- * data. However, we only send the requested channels to
- * the bus.
- *
- * Voltage values are encoded as a value 0-255 (0-512 on the
- * DSO-5200*), where the value is a point in the range
- * represented by the vdiv setting. There are 8 vertical divs,
- * so e.g. 500mV/div represents 4V peak-to-peak where 0 = -2V
- * and 255 = +2V.
- */
- /* TODO: Support for DSO-5xxx series 9-bit samples. */
- if (devc->ch1_enabled) {
- range = ((float)vdivs[devc->voltage[0]][0] / vdivs[devc->voltage[0]][1]) * 8;
- ch1 = range / 255 * *(buf + i * 2 + 1);
- /* Value is centered around 0V. */
- ch1 -= range / 2;
- analog.data[data_offset++] = ch1;
- }
- if (devc->ch2_enabled) {
- range = ((float)vdivs[devc->voltage[1]][0] / vdivs[devc->voltage[1]][1]) * 8;
- ch2 = range / 255 * *(buf + i * 2);
- ch2 -= range / 2;
- analog.data[data_offset++] = ch2;
+ analog.data = g_try_malloc(num_samples * sizeof(float));
+
+ for (int ch = 0; ch < NUM_CHANNELS; ch++) {
+ if (!devc->ch_enabled[ch])
+ continue;
+
+ float range = ((float)vdivs[devc->voltage[ch]][0] / vdivs[devc->voltage[ch]][1]) * 8;
+ float vdivlog = log10f(range / 255);
+ int digits = -(int)vdivlog + (vdivlog < 0.0);
+ analog.encoding->digits = digits;
+ analog.spec->spec_digits = digits;
+ analog.meaning->channels = g_slist_append(NULL, channels->data);
+
+ for (int i = 0; i < num_samples; i++) {
+ /*
+ * The device always sends data for both channels. If a channel
+ * is disabled, it contains a copy of the enabled channel's
+ * data. However, we only send the requested channels to
+ * the bus.
+ *
+ * Voltage values are encoded as a value 0-255 (0-512 on the
+ * DSO-5200*), where the value is a point in the range
+ * represented by the vdiv setting. There are 8 vertical divs,
+ * so e.g. 500mV/div represents 4V peak-to-peak where 0 = -2V
+ * and 255 = +2V.
+ */
+ /* TODO: Support for DSO-5xxx series 9-bit samples. */
+ ((float *)analog.data)[i] = range / 255 * *(buf + i * 2 + 1 - ch) - range / 2;