]> sigrok.org Git - libsigrok.git/commitdiff
demo: Set an initial mq, mq flag and digits to the analog package.
authorFrank Stettner <redacted>
Wed, 20 Feb 2019 17:58:13 +0000 (18:58 +0100)
committerUwe Hermann <redacted>
Fri, 29 Mar 2019 15:15:37 +0000 (16:15 +0100)
Without a measured quantity in packet.meaning->mq the C++ binding function
sigrok::Analog::mq() throws an exception and there is no way to check if
there is any measured quantity set in the analog package.

src/hardware/demo/api.c

index 7d3e08872d07c21b38832845a138d5cf2bd3fe80..52f30d4f14746ee55546b288d4df31fc4b662a68 100644 (file)
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-#define DEFAULT_NUM_LOGIC_CHANNELS     8
-#define DEFAULT_LOGIC_PATTERN          PATTERN_SIGROK
+#define DEFAULT_NUM_LOGIC_CHANNELS             8
+#define DEFAULT_LOGIC_PATTERN                  PATTERN_SIGROK
 
 
-#define DEFAULT_NUM_ANALOG_CHANNELS    4
-#define DEFAULT_ANALOG_AMPLITUDE       10
+#define DEFAULT_NUM_ANALOG_CHANNELS            4
+#define DEFAULT_ANALOG_ENCODING_DIGITS 4
+#define DEFAULT_ANALOG_SPEC_DIGITS             4
+#define DEFAULT_ANALOG_AMPLITUDE               10
 
 /* Note: No spaces allowed because of sigrok-cli. */
 static const char *logic_pattern_str[] = {
 
 /* Note: No spaces allowed because of sigrok-cli. */
 static const char *logic_pattern_str[] = {
@@ -185,9 +187,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
                        sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
                        ag->packet.meaning->channels = cg->channels;
                        ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
                        sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
                        ag->packet.meaning->channels = cg->channels;
-                       ag->packet.meaning->mq = 0;
-                       ag->packet.meaning->mqflags = 0;
+                       ag->packet.meaning->mq = SR_MQ_VOLTAGE;
+                       ag->packet.meaning->mqflags = SR_MQFLAG_DC;
                        ag->packet.meaning->unit = SR_UNIT_VOLT;
                        ag->packet.meaning->unit = SR_UNIT_VOLT;
+                       ag->packet.encoding->digits = DEFAULT_ANALOG_ENCODING_DIGITS;
+                       ag->packet.spec->spec_digits = DEFAULT_ANALOG_SPEC_DIGITS;
                        ag->packet.data = ag->pattern_data;
                        ag->pattern = pattern;
                        ag->avg_val = 0.0f;
                        ag->packet.data = ag->pattern_data;
                        ag->pattern = pattern;
                        ag->avg_val = 0.0f;