X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fanalog.c;h=72d1eb87efa744756f02fe9ae747c17006706cf5;hb=580b94e4d762d21a018b3cf535fe8764c9cb1c6f;hp=ed480ca0335385af204804cad0f5d0003b228da6;hpb=2c24077466a299ead689c90f01f55f6d86c7386b;p=libsigrok.git diff --git a/src/output/analog.c b/src/output/analog.c index ed480ca0..72d1eb87 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -31,6 +31,7 @@ struct context { int num_enabled_channels; GPtrArray *channellist; int digits; + float *fdata; }; enum { @@ -64,6 +65,7 @@ static int init(struct sr_output *o, GHashTable *options) g_ptr_array_add(ctx->channellist, ch->name); ctx->num_enabled_channels++; } + ctx->fdata = NULL; return SR_OK; } @@ -271,6 +273,8 @@ static void fancyprint(int unit, int mqflags, float value, GString *out) g_string_append_printf(out, " REF"); if (mqflags & SR_MQFLAG_UNSTABLE) g_string_append_printf(out, " UNSTABLE"); + if (mqflags & SR_MQFLAG_FOUR_WIRE) + g_string_append_printf(out, " 4-WIRE"); g_string_append_c(out, '\n'); } @@ -316,9 +320,10 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p case SR_DF_ANALOG: analog = packet->payload; num_channels = g_slist_length(analog->meaning->channels); - if (!(fdata = g_try_malloc( + if (!(fdata = g_try_realloc(ctx->fdata, analog->num_samples * num_channels * sizeof(float)))) return SR_ERR_MALLOC; + ctx->fdata = fdata; if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK) return ret; *out = g_string_sized_new(512); @@ -352,21 +357,6 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p return SR_OK; } -static int cleanup(struct sr_output *o) -{ - struct context *ctx; - - if (!o || !o->sdi) - return SR_ERR_ARG; - ctx = o->priv; - - g_ptr_array_free(ctx->channellist, 1); - g_free(ctx); - o->priv = NULL; - - return SR_OK; -} - static struct sr_option options[] = { { "digits", "Digits", "Digits to show", NULL, NULL }, ALL_ZERO @@ -385,6 +375,24 @@ static const struct sr_option *get_options(void) return options; } +static int cleanup(struct sr_output *o) +{ + struct context *ctx; + + if (!o || !o->sdi) + return SR_ERR_ARG; + ctx = o->priv; + + g_ptr_array_free(ctx->channellist, 1); + g_variant_unref(options[0].def); + g_slist_free_full(options[0].values, (GDestroyNotify)g_variant_unref); + g_free(ctx->fdata); + g_free(ctx); + o->priv = NULL; + + return SR_OK; +} + SR_PRIV struct sr_output_module output_analog = { .id = "analog", .name = "Analog",