Cleanup hex mode code

This commit is contained in:
Martin Lund 2022-08-06 17:12:16 +02:00
parent 75aa066bf8
commit 72eb682267
2 changed files with 6 additions and 11 deletions

View file

@ -244,6 +244,7 @@ void options_print()
option.dsr_pulse_duration, option.dsr_pulse_duration,
option.dcd_pulse_duration, option.dcd_pulse_duration,
option.ri_pulse_duration); option.ri_pulse_duration);
tio_printf(" Hexadecimal mode: %s", option.hex_mode ? "enabled" : "disabled");
if (option.map[0] != 0) if (option.map[0] != 0)
tio_printf(" Map flags: %s", option.map); tio_printf(" Map flags: %s", option.map);
if (option.log) if (option.log)

View file

@ -83,9 +83,6 @@
#define KEY_V 0x76 #define KEY_V 0x76
#define KEY_Z 0x7a #define KEY_Z 0x7a
#define NORMAL 0
#define HEX 1
enum line_mode_t enum line_mode_t
{ {
LINE_OFF, LINE_OFF,
@ -112,7 +109,6 @@ bool interactive_mode = true;
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old; static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
static unsigned long rx_total = 0, tx_total = 0; static unsigned long rx_total = 0, tx_total = 0;
static bool connected = false; static bool connected = false;
static bool print_mode = NORMAL;
static bool standard_baudrate = true; static bool standard_baudrate = true;
static void (*print)(char c); static void (*print)(char c);
static int fd; static int fd;
@ -469,16 +465,16 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
case KEY_H: case KEY_H:
/* Toggle hexadecimal printing mode */ /* Toggle hexadecimal printing mode */
if (print_mode == NORMAL) if (!option.hex_mode)
{ {
print = print_hex; print = print_hex;
print_mode = HEX; option.hex_mode = true;
tio_printf("Switched to hexadecimal mode"); tio_printf("Switched to hexadecimal mode");
} }
else else
{ {
print = print_normal; print = print_normal;
print_mode = NORMAL; option.hex_mode = false;
tio_printf("Switched to normal mode"); tio_printf("Switched to normal mode");
} }
break; break;
@ -988,7 +984,7 @@ void forward_to_tty(int fd, char output_char)
} }
else else
{ {
if (print_mode == HEX) if (option.hex_mode)
{ {
output_hex(output_char); output_hex(output_char);
} }
@ -1060,12 +1056,10 @@ int tty_connect(void)
if (option.hex_mode) if (option.hex_mode)
{ {
print = print_hex; print = print_hex;
print_mode = HEX;
} }
else else
{ {
print = print_normal; print = print_normal;
print_mode = NORMAL;
} }
/* Save current port settings */ /* Save current port settings */
@ -1228,7 +1222,7 @@ int tty_connect(void)
/* Save previous key */ /* Save previous key */
previous_char = input_char; previous_char = input_char;
if ((print_mode == HEX) && (forward)) if ((option.hex_mode) && (forward))
{ {
if (!is_valid_hex(input_char)) if (!is_valid_hex(input_char))
{ {