]> sigrok.org Git - libsigrok.git/commitdiff
output: simplify trigger marker position calculation (readability)
authorGerhard Sittig <redacted>
Sun, 15 Jul 2018 18:11:58 +0000 (20:11 +0200)
committerGerhard Sittig <redacted>
Sun, 15 Jul 2018 18:47:08 +0000 (20:47 +0200)
This amends commit 67b345b981a5 which fixed the calculation of the
trigger marker's position. Improve readability of the formulae and
adjust comments.

src/output/ascii.c
src/output/bits.c
src/output/hex.c

index 3962fe9d80215fcde193e5556d78c3ab70f3ded1..9e04e768502a3e817048b8a7a34780e065c5b3ab 100644 (file)
@@ -200,10 +200,9 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                                        g_string_append_c(*out, '\n');
                                        if (j == ctx->num_enabled_channels - 1 && ctx->trigger > -1) {
                                                /*
-                                                * Each group of 8 bits occupies 8 bit positions
-                                                * and no separator. With this dense presentation
-                                                * the "calculation" of the trigger position is
-                                                * rather straight forward.
+                                                * Sample data lines have one character per bit and
+                                                * no separator between bytes. Align trigger marker
+                                                * to this layout.
                                                 */
                                                offset = ctx->trigger;
                                                g_string_append_printf(*out, "T:%*s^ %d\n", offset, "", ctx->trigger);
index 379f019be4ed038db70e514afecc8890d379ae3b..c3f2ef32dc26c53abf916c86b81d4c00eae07bcd 100644 (file)
@@ -169,13 +169,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                                        g_string_append_c(*out, '\n');
                                        if (j == ctx->num_enabled_channels - 1 && ctx->trigger > -1) {
                                                /*
-                                                * Each group of 8 bits occupies 8 bit positions
-                                                * plus 1 separator. Calculate the position of the
-                                                * byte which contains the trigger, then adjust for
-                                                * the trigger's bit position within that byte.
+                                                * Sample data lines have one character per bit,
+                                                * plus one separator per byte. Align trigger marker
+                                                * to this layout.
                                                 */
-                                               offset = ctx->trigger / 8 * (8 + 1);
-                                               offset += ctx->trigger % 8;
+                                               offset = ctx->trigger + ctx->trigger / 8;
                                                g_string_append_printf(*out, "T:%*s^ %d\n", offset, "", ctx->trigger);
                                                ctx->trigger = -1;
                                        }
index 89111446c65001c503329796802582cf40be0d8e..a1c09f81b4c4e4abe31f1ed4a13ddc8d877d49ef 100644 (file)
@@ -182,13 +182,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                                        g_string_append_c(*out, '\n');
                                        if (j == ctx->num_enabled_channels - 1 && ctx->trigger > -1) {
                                                /*
-                                                * Each group of 8 bits occupies 2 hex digits plus
-                                                * 1 separator. Calculate the position of the byte
-                                                * which contains the trigger, then adjust for the
-                                                * trigger's bit position within that byte.
+                                                * Sample data lines have one character per nibble,
+                                                * plus one separator per byte. Align trigger marker
+                                                * to this layout.
                                                 */
-                                               offset = ctx->trigger / 8 * (2 + 1);
-                                               offset += (ctx->trigger % 8) / 4;
+                                               offset = ctx->trigger / 4 + ctx->trigger / 8;
                                                g_string_append_printf(*out, "T:%*s^ %d\n", offset, "", ctx->trigger);
                                                ctx->trigger = -1;
                                        }