X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fanalog.c;h=5c624e050033729273b0972fb4c6c580cecd80c8;hb=09c650d5e910d841c49e7b1e86e4126cecd7e060;hp=f5d23e6fc085b896e0a18246bf51e2134041294a;hpb=688e44ae06610d64ef90b720cd61262e5b606d55;p=libsigrok.git diff --git a/src/output/analog.c b/src/output/analog.c index f5d23e6f..5c624e05 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -27,6 +27,8 @@ #define LOG_PREFIX "output/analog" +#define BIN_TO_DEC_DIGITS (log(2) / log(10)) + struct context { int num_enabled_channels; GPtrArray *channellist; @@ -113,8 +115,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p g_string_append_printf(*out, "%f", g_variant_get_double(src->data)); } else if (srci->datatype == SR_T_UINT64) { - g_string_append_printf(*out, "%" PRIu64, + g_string_append_printf(*out, "%" + G_GUINT64_FORMAT, g_variant_get_uint64(src->data)); + } else if (srci->datatype == SR_T_STRING) { + g_string_append_printf(*out, "%s", + g_variant_get_string(src->data, NULL)); } g_string_append(*out, "\n"); } @@ -129,15 +135,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK) return ret; *out = g_string_sized_new(512); - if (analog->encoding->is_digits_decimal) { - if (ctx->digits == DIGITS_ALL) - digits = analog->encoding->digits; - else - digits = analog->spec->spec_digits; - } else { - /* TODO we don't know how to print by number of bits yet. */ - digits = 6; - } + if (ctx->digits == DIGITS_ALL) + digits = analog->encoding->digits; + else + digits = analog->spec->spec_digits; + if (!analog->encoding->is_digits_decimal) + digits = copysign(ceil(abs(digits) * BIN_TO_DEC_DIGITS), digits); gboolean si_friendly = sr_analog_si_prefix_friendly(analog->meaning->unit); sr_analog_unit_to_string(analog, &suffix); for (i = 0; i < analog->num_samples; i++) { @@ -204,7 +207,7 @@ static int cleanup(struct sr_output *o) SR_PRIV struct sr_output_module output_analog = { .id = "analog", .name = "Analog", - .desc = "Analog data and types", + .desc = "ASCII analog data values and units", .exts = NULL, .flags = 0, .options = get_options,