- data_offset = 0;
- for (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, where the
- * value is a point in the range represented by the vdiv
- * setting. There are 10 vertical divs, so e.g. 500mV/div
- * represents 5V peak-to-peak where 0 = -2.5V and 255 = +2.5V.
- */
- if (ch1_ena)
- analog.data[data_offset++] = (ch1_bit * *(buf + i * 2) - ch1_center);
- if (ch2_ena)
- analog.data[data_offset++] = (ch2_bit * *(buf + i * 2 + 1) - ch2_center);
- }
+ for (int ch = 0; ch < 2; ch++) {
+ if (!devc->ch_enabled[ch])
+ continue;
+
+ float vdivlog = log10f(ch_bit[ch]);
+ 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, where the
+ * value is a point in the range represented by the vdiv
+ * setting. There are 10 vertical divs, so e.g. 500mV/div
+ * represents 5V peak-to-peak where 0 = -2.5V and 255 = +2.5V.
+ */
+ ((float *)analog.data)[i] = ch_bit[ch] * *(buf + i * 2 + ch) - ch_center[ch];
+ }