]> sigrok.org Git - libsigrok.git/blobdiff - output/output_text.c
add DF_ANALOG, and an analog output module
[libsigrok.git] / output / output_text.c
index f6d9357a7902ce68d84d60076721d50276c06e9c..cc3cb4e19a406e413f4542bdc09fd1689851fc6c 100644 (file)
@@ -88,8 +88,9 @@ static int init(struct output *o, int default_spl)
 
        for (l = o->device->probes; l; l = l->next) {
                probe = l->data;
-               if (probe->enabled)
-                       ctx->probelist[ctx->num_enabled_probes++] = probe->name;
+               if (!probe->enabled)
+                       continue;
+               ctx->probelist[ctx->num_enabled_probes++] = probe->name;
        }
 
        ctx->probelist[ctx->num_enabled_probes] = 0;
@@ -180,12 +181,15 @@ static int data_bits(struct output *o, char *data_in, uint64_t length_in,
 {
        struct context *ctx;
        unsigned int outsize, offset, p;
+       int max_linelen;
        uint64_t sample;
-       char *outbuf;
+       char *outbuf, c;
 
        ctx = o->internal;
-       outsize = length_in / ctx->unitsize * ctx->num_enabled_probes *
-                 ctx->samples_per_line + 4096;
+       max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
+                       + ctx->samples_per_line / 8;
+       outsize = length_in / ctx->unitsize * ctx->num_enabled_probes
+                       / ctx->samples_per_line * max_linelen + 512;
 
        if (!(outbuf = calloc(1, outsize + 1)))
                return SIGROK_ERR_MALLOC;
@@ -203,12 +207,9 @@ static int data_bits(struct output *o, char *data_in, uint64_t length_in,
                     offset += ctx->unitsize) {
                        memcpy(&sample, data_in + offset, ctx->unitsize);
                        for (p = 0; p < ctx->num_enabled_probes; p++) {
-                               if (sample & ((uint64_t) 1 << p))
-                                       ctx->linebuf[p * ctx->linebuf_len +
-                                                    ctx->line_offset] = '1';
-                               else
-                                       ctx->linebuf[p * ctx->linebuf_len +
-                                                    ctx->line_offset] = '0';
+                               c = (sample & ((uint64_t) 1 << p)) ? '1' : '0';
+                               ctx->linebuf[p * ctx->linebuf_len +
+                                            ctx->line_offset] = c;
                        }
                        ctx->line_offset++;
                        ctx->spl_cnt++;
@@ -248,12 +249,15 @@ static int data_hex(struct output *o, char *data_in, uint64_t length_in,
 {
        struct context *ctx;
        unsigned int outsize, offset, p;
+       int max_linelen;
        uint64_t sample;
        char *outbuf;
 
        ctx = o->internal;
-       outsize = length_in / ctx->unitsize * ctx->num_enabled_probes *
-                 ctx->samples_per_line + 4096;
+       max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
+                       + ctx->samples_per_line / 2;
+       outsize = length_in / ctx->unitsize * ctx->num_enabled_probes
+                       / ctx->samples_per_line * max_linelen + 512;
 
        if (!(outbuf = calloc(1, outsize + 1)))
                return SIGROK_ERR_MALLOC;
@@ -303,6 +307,7 @@ static int data_hex(struct output *o, char *data_in, uint64_t length_in,
 struct output_format output_text_bits = {
        "bits",
        "Text (bits)",
+       DF_LOGIC,
        init_bits,
        data_bits,
        event,
@@ -311,6 +316,7 @@ struct output_format output_text_bits = {
 struct output_format output_text_hex = {
        "hex",
        "Text (hexadecimal)",
+       DF_LOGIC,
        init_hex,
        data_hex,
        event,