diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2016-11-28 09:16:48 +0100 |
---|---|---|
committer | Andreas Eversberg <andreas@eversberg.eu> | 2016-11-29 07:49:21 +0100 |
commit | d52d0242bf6a622334fb61a6ca0db3b264ca45b8 (patch) | |
tree | 53a69efd62d05615c6fe6c683568716c8219edcd /src | |
parent | 938fb74baef7a53b0092271ad6ac61a376cc2d8f (diff) |
Output enhancements
* no more flicker on wave form display while scrolling
* dialing console gets cleared/overwritten correctly
* fixes on stderr output
Diffstat (limited to 'src')
-rw-r--r-- | src/amps/main.c | 6 | ||||
-rw-r--r-- | src/anetz/main.c | 2 | ||||
-rw-r--r-- | src/bnetz/main.c | 4 | ||||
-rw-r--r-- | src/cnetz/main.c | 4 | ||||
-rw-r--r-- | src/common/call.c | 4 | ||||
-rw-r--r-- | src/common/debug.c | 3 | ||||
-rw-r--r-- | src/common/display_wave.c | 52 | ||||
-rw-r--r-- | src/common/display_wave.h | 5 | ||||
-rw-r--r-- | src/common/main_common.c | 7 | ||||
-rw-r--r-- | src/nmt/main.c | 4 |
10 files changed, 71 insertions, 20 deletions
diff --git a/src/amps/main.c b/src/amps/main.c index 85c6523..50c3ecd 100644 --- a/src/amps/main.c +++ b/src/amps/main.c @@ -261,18 +261,18 @@ int main(int argc, char *argv[]) if (num_kanal == 1 && num_sounddev == 0) num_sounddev = 1; /* use defualt */ if (num_kanal != num_sounddev) { - fprintf(stdout, "You need to specify as many sound devices as you have channels.\n"); + fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } if (num_kanal == 1 && num_chan_type == 0) num_chan_type = 1; /* use defualt */ if (num_kanal != num_chan_type) { - fprintf(stdout, "You need to specify as many channel types as you have channels.\n"); + fprintf(stderr, "You need to specify as many channel types as you have channels.\n"); exit(0); } if (bis && latency > 5) { - fprintf(stdout, "If you use BUSY/IDLE bit, you need to lower the round-trip delay to 5 ms (--latenc 5).\n"); + fprintf(stderr, "If you use BUSY/IDLE bit, you need to lower the round-trip delay to 5 ms (--latenc 5).\n"); exit(0); } diff --git a/src/anetz/main.c b/src/anetz/main.c index d4ea13f..ad186d0 100644 --- a/src/anetz/main.c +++ b/src/anetz/main.c @@ -142,7 +142,7 @@ int main(int argc, char *argv[]) if (num_kanal == 1 && num_sounddev == 0) num_sounddev = 1; /* use defualt */ if (num_kanal != num_sounddev) { - fprintf(stdout, "You need to specify as many sound devices as you have channels.\n"); + fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } diff --git a/src/bnetz/main.c b/src/bnetz/main.c index 4c5f98b..ad2c3c4 100644 --- a/src/bnetz/main.c +++ b/src/bnetz/main.c @@ -155,13 +155,13 @@ int main(int argc, char *argv[]) if (num_kanal == 1 && num_sounddev == 0) num_sounddev = 1; /* use defualt */ if (num_kanal != num_sounddev) { - fprintf(stdout, "You need to specify as many sound devices as you have channels.\n"); + fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } if (num_kanal == 1 && num_pilot == 0) num_pilot = 1; /* use defualt */ if (num_kanal != num_pilot) { - fprintf(stdout, "You need to specify as many pilot tone settings as you have channels.\n"); + fprintf(stderr, "You need to specify as many pilot tone settings as you have channels.\n"); exit(0); } diff --git a/src/cnetz/main.c b/src/cnetz/main.c index 0a3a6a5..5c020fc 100644 --- a/src/cnetz/main.c +++ b/src/cnetz/main.c @@ -219,13 +219,13 @@ int main(int argc, char *argv[]) if (num_kanal == 1 && num_sounddev == 0) num_sounddev = 1; /* use defualt */ if (num_kanal != num_sounddev) { - fprintf(stdout, "You need to specify as many sound devices as you have channels.\n"); + fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } if (num_kanal == 1 && num_chan_type == 0) num_chan_type = 1; /* use defualt */ if (num_kanal != num_chan_type) { - fprintf(stdout, "You need to specify as many channel types as you have channels.\n"); + fprintf(stderr, "You need to specify as many channel types as you have channels.\n"); exit(0); } diff --git a/src/common/call.c b/src/common/call.c index 478cfd9..6fa4907 100644 --- a/src/common/call.c +++ b/src/common/call.c @@ -582,10 +582,13 @@ dial_after_hangup: sprintf(console_text, "call disconnected: %s (enter h=hangup)\r", cause_name(call.disc_cause)); break; } + clear_console_text(); console_len = strlen(console_text); memset(console_clear, ' ', console_len - 1); console_clear[console_len - 1] = '\r'; + printf("\033[1;37m"); fwrite(console_text, console_len, 1, stdout); + printf("\033[0;39m"); fflush(stdout); } @@ -596,6 +599,7 @@ void clear_console_text(void) fwrite(console_clear, console_len, 1, stdout); // note: fflused by user of this function + console_len = 0; } diff --git a/src/common/debug.c b/src/common/debug.c index b49e056..3b5bfa3 100644 --- a/src/common/debug.c +++ b/src/common/debug.c @@ -24,6 +24,7 @@ #include <stdint.h> #include <errno.h> #include "debug.h" +#include "display_wave.h" #include "call.h" const char *debug_level[] = { @@ -89,7 +90,9 @@ void _printdebug(const char *file, const char __attribute__((unused)) *function, clear_console_text(); // printf("%s%s:%d %s() %s: %s\033[0;39m", debug_cat[cat].color, file, line, function, debug_level[level], buffer); + display_limit_scroll(1); printf("%s%s:%d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer); + display_limit_scroll(0); fflush(stdout); } diff --git a/src/common/display_wave.c b/src/common/display_wave.c index 87d7a31..6c87f39 100644 --- a/src/common/display_wave.c +++ b/src/common/display_wave.c @@ -20,17 +20,35 @@ #include <stdio.h> #include <stdint.h> #include <string.h> +#include <sys/ioctl.h> #include "sender.h" #define DISPLAY_INTERVAL 0.04 -#define WIDTH 80 #define HEIGHT 11 static int num_sender = 0; -static char screen[HEIGHT][WIDTH+1]; +static char screen[HEIGHT][MAX_DISPLAY_WIDTH]; static int wave_on = 0; +static void get_win_size(int *w, int *h) +{ + struct winsize win; + int rc; + + rc = ioctl(0, TIOCGWINSZ, &win); + if (rc) { + *w = 80; + *h = 25; + return; + } + + *h = win.ws_row; + *w = win.ws_col; + if (*w > MAX_DISPLAY_WIDTH - 1) + *w = MAX_DISPLAY_WIDTH - 1; +} + void display_wave_init(sender_t *sender, int samplerate) { dispwav_t *disp = &sender->dispwav; @@ -43,6 +61,9 @@ void display_wave_init(sender_t *sender, int samplerate) void display_wave_on(int on) { int i, j; + int w, h; + + get_win_size(&w, &h); if (on < 0) wave_on = 1 - wave_on; @@ -53,13 +74,27 @@ void display_wave_on(int on) printf("\0337\033[H"); for (i = 0; i < num_sender; i++) { for (j = 0; j < HEIGHT; j++) { - screen[j][WIDTH] = '\0'; + screen[j][w] = '\0'; puts(screen[j]); } } printf("\0338"); fflush(stdout); } +void display_limit_scroll(int on) +{ + int w, h; + + if (!wave_on) + return; + + get_win_size(&w, &h); + + printf("\0337"); + printf("\033[%d;%dr", (on) ? num_sender * HEIGHT + 1 : 1, h); + printf("\0338"); +} + /* * draw wave form: * @@ -84,10 +119,13 @@ void display_wave(sender_t *sender, int16_t *samples, int length) int color = 9; /* default color */ int center_line; char center_char; + int width, h; if (!wave_on) return; + get_win_size(&width, &h); + /* at what line we draw our zero-line and what character we use */ center_line = (HEIGHT - 1) >> 1; center_char = (HEIGHT & 1) ? '-' : '_'; @@ -97,15 +135,15 @@ void display_wave(sender_t *sender, int16_t *samples, int length) buffer = disp->buffer; for (i = 0; i < length; i++) { - if (pos >= WIDTH) { + if (pos >= width) { if (++pos == max) pos = 0; continue; } buffer[pos++] = samples[i]; - if (pos == WIDTH) { + if (pos == width) { memset(&screen, ' ', sizeof(screen)); - for (j = 0; j < WIDTH; j++) { + for (j = 0; j < width; j++) { /* 32767 - buffer[j] never reaches 65536, so * the result is below HEIGHT * 2 - 1 */ @@ -118,7 +156,7 @@ void display_wave(sender_t *sender, int16_t *samples, int length) for (j = 0; j < disp->offset; j++) puts(""); for (j = 0; j < HEIGHT; j++) { - for (k = 0; k < WIDTH; k++) { + for (k = 0; k < width; k++) { if (j == center_line && screen[j][k] == ' ') { /* blue 0-line */ if (color != 4) { diff --git a/src/common/display_wave.h b/src/common/display_wave.h index ccf8c5f..57a489a 100644 --- a/src/common/display_wave.h +++ b/src/common/display_wave.h @@ -1,13 +1,16 @@ +#define MAX_DISPLAY_WIDTH 1024 + typedef struct sender sender_t; typedef struct display_wave { int interval_pos; int interval_max; int offset; - int16_t buffer[256]; + int16_t buffer[MAX_DISPLAY_WIDTH]; } dispwav_t; void display_wave_init(sender_t *sender, int samplerate); void display_wave_on(int on); +void display_limit_scroll(int on); void display_wave(sender_t *sender, int16_t *samples, int length); diff --git a/src/common/main_common.c b/src/common/main_common.c index e92f7ce..c14ab28 100644 --- a/src/common/main_common.c +++ b/src/common/main_common.c @@ -289,7 +289,8 @@ void sighandler(int sigset) if (sigset == SIGPIPE) return; - fprintf(stderr, "\nSignal received: %d\n", sigset); + clear_console_text(); + printf("Signal received: %d\n", sigset); quit = 1; } @@ -374,7 +375,8 @@ next_char: switch (c) { case 3: /* quit */ - fprintf(stderr, "\nCTRL+c received, quitting!\n"); + clear_console_text(); + printf("CTRL+c received, quitting!\n"); *quit = 1; goto next_char; case 'w': @@ -397,6 +399,7 @@ next_char: usleep(interval * 1000); } + /* get rid of last entry */ clear_console_text(); /* reset terminal */ diff --git a/src/nmt/main.c b/src/nmt/main.c index 2151fa2..256d464 100644 --- a/src/nmt/main.c +++ b/src/nmt/main.c @@ -283,13 +283,13 @@ int main(int argc, char *argv[]) if (num_kanal == 1 && num_sounddev == 0) num_sounddev = 1; /* use defualt */ if (num_kanal != num_sounddev) { - fprintf(stdout, "You need to specify as many sound devices as you have channels.\n"); + fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } if (num_kanal == 1 && num_chan_type == 0) num_chan_type = 1; /* use defualt */ if (num_kanal != num_chan_type) { - fprintf(stdout, "You need to specify as many channel types as you have channels.\n"); + fprintf(stderr, "You need to specify as many channel types as you have channels.\n"); exit(0); } |