From f1e4e1b61d322c960c8fe8c234a03542e0b901b9 Mon Sep 17 00:00:00 2001 From: portersky <24420859+portersky@users.noreply.github.com> Date: Sun, 14 Jun 2026 23:12:41 +0200 Subject: [PATCH] fix: separate logger from dashboard output Logger writes to stderr so it doesn't corrupt the dashboard on stdout. Dashboard tracks its own line count and uses cursor-up instead of home so log messages appear cleanly before/after instead of interleaved. --- GOAL.md | 7 ------- celrs/log_write.c | 2 +- tools/telemetry.c | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 17 deletions(-) delete mode 100644 GOAL.md diff --git a/GOAL.md b/GOAL.md deleted file mode 100644 index d45142c..0000000 --- a/GOAL.md +++ /dev/null @@ -1,7 +0,0 @@ -Implement all TODOs in the codebase. - -write test first follow @AGENTS.md, commit when implemented one at a time and it passes. - -git push when implemented. - -You need to able to run telemetry on COM14 and start receiving data from TX module. diff --git a/celrs/log_write.c b/celrs/log_write.c index 1a7a0a6..112f1a1 100644 --- a/celrs/log_write.c +++ b/celrs/log_write.c @@ -2,5 +2,5 @@ #include void cel_log_write(char const* msg) { - printf("%s\n", msg); + fprintf(stderr, "%s\n", msg); } diff --git a/tools/telemetry.c b/tools/telemetry.c index 72bb262..83e8be8 100644 --- a/tools/telemetry.c +++ b/tools/telemetry.c @@ -57,7 +57,7 @@ static void sleep_ms(int ms) { } /* --------------------------------------------------------------------------- */ -/* ANSI helpers */ +/* ANSI helpers — all go to stdout so dashboard owns it */ /* --------------------------------------------------------------------------- */ static void ansi_reset(void) { printf("\033[0m"); } @@ -67,7 +67,12 @@ static void ansi_yellow(void) { printf("\033[33m"); } static void ansi_bold(void) { printf("\033[1m"); } static void ansi_dim(void) { printf("\033[2m"); } static void ansi_clear_line(void) { printf("\033[2K"); } -static void ansi_home(void) { printf("\033[H"); } + +static void ansi_cursor_up(int n) { + char buf[16]; + snprintf(buf, sizeof(buf), "\033[%dA", n); + printf("%s", buf); +} /* --------------------------------------------------------------------------- */ /* Status helpers */ @@ -223,17 +228,21 @@ static void rssi_color(double dbm) { } /* --------------------------------------------------------------------------- */ -/* Dashboard render */ +/* Dashboard render — tracks line count for in-place redraw */ /* --------------------------------------------------------------------------- */ static void render_dashboard(dashboard_t const* d, char const* port, int baud, - double elapsed) { + double elapsed, int* lines) { double now = (double)time(NULL); status_t status = compute_status(now, d->link_t, d->fc_t); - ansi_home(); - ansi_clear_line(); + /* Return to top of dashboard if already drawn */ + if (*lines > 0) { + ansi_cursor_up(*lines); + } + + int n = 0; /* Title */ ansi_bold(); @@ -241,10 +250,12 @@ static void render_dashboard(dashboard_t const* d, ansi_reset(); printf(" %s @ %d baud up %.0fs\n", port, baud, elapsed); + n++; - /* Status line */ + /* Status */ print_status_label(status); printf("\n"); + n++; /* LINK */ ansi_bold(); printf(" LINK "); ansi_reset(); @@ -267,6 +278,7 @@ static void render_dashboard(dashboard_t const* d, ansi_dim(); printf("waiting..."); ansi_reset(); } printf("\n"); + n++; /* BATT */ ansi_bold(); printf(" BATT "); ansi_reset(); @@ -280,6 +292,7 @@ static void render_dashboard(dashboard_t const* d, ansi_dim(); printf("waiting..."); ansi_reset(); } printf("\n"); + n++; /* IMU */ ansi_bold(); printf(" IMU "); ansi_reset(); @@ -293,6 +306,7 @@ static void render_dashboard(dashboard_t const* d, ansi_dim(); printf("waiting..."); ansi_reset(); } printf("\n"); + n++; /* MODE */ ansi_bold(); printf(" MODE "); ansi_reset(); @@ -303,13 +317,16 @@ static void render_dashboard(dashboard_t const* d, ansi_dim(); printf("waiting..."); ansi_reset(); } printf("\n"); + n++; /* Footer */ ansi_dim(); printf(" rx=%d ignored=%d", d->rx_frames, d->unknown); ansi_reset(); printf("\n"); + n++; + *lines = n; fflush(stdout); } @@ -401,7 +418,7 @@ int main(int argc, char const* argv[]) { /* Verify module responds to CRSF ping */ if (verify_connection(port) != 0) { - cel_log_warn("Continuing anyway - telemetry may not arrive"); + cel_log_warn("Continuing anyway — telemetry may not arrive"); } /* Create CRSF stream for incremental parsing */ @@ -425,6 +442,7 @@ int main(int argc, char const* argv[]) { uint8_t read_buf[256]; time_t t_start = time(NULL); int rc_count = 0; + int d_lines = 0; /* dashboard line count for cursor tracking */ while (s_running) { /* Read available data */ @@ -454,12 +472,16 @@ int main(int argc, char const* argv[]) { /* Redraw dashboard every 100 ms */ if (rc_count % 5 == 0) { double elapsed = difftime(time(NULL), t_start); - render_dashboard(&dash, port_path, actual_baud, elapsed); + render_dashboard(&dash, port_path, actual_baud, elapsed, &d_lines); } sleep_ms(20); } + /* Move cursor past dashboard before shutdown message */ + if (d_lines > 0) { + printf("\n"); + } cel_log_info("Shutting down..."); cel_crsf_stream_destroy(stream); cel_serial_close(port);