Skip to content

Commit

Permalink
Merge pull request #19 from rakslice/ctrl_c_without_poll
Browse files Browse the repository at this point in the history
count ctrl-c presses immediately
  • Loading branch information
Spritetm authored Jul 8, 2024
2 parents 3ca98b2 + 6460fd9 commit ab49adc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ static void uart_disable_console_raw_mode() {

int char_from_signal=-1;

static void ctrl_c_inc();

static void uart_sig_hdl(int sig) {
if (sig==SIGINT) char_from_signal=0x03;
if (sig==SIGINT) {
ctrl_c_inc();
char_from_signal=0x03;
}
if (sig==SIGQUIT) char_from_signal=0x1C;
if (sig==SIGSTOP) char_from_signal=0x1a;
}
Expand All @@ -71,6 +76,16 @@ static void uart_set_console_raw_mode() {

static int ctrl_c_pressed_times=0;

static void ctrl_c_inc() {
#ifndef __EMSCRIPTEN__
ctrl_c_pressed_times++;
#endif
if (ctrl_c_pressed_times==3) {
UART_LOG_WARNING("Ctrl-C pressed three times. Bye!\n");
exit(0);
}
}

static int uart_poll_for_console_character() {
char c;
fd_set input;
Expand All @@ -85,15 +100,6 @@ static int uart_poll_for_console_character() {
if (char_from_signal!=-1) {
int r=char_from_signal;
char_from_signal=-1;
if (r==0x03) { //ctrl-c
#ifndef __EMSCRIPTEN__
ctrl_c_pressed_times++;
#endif
if (ctrl_c_pressed_times==3) {
UART_LOG_WARNING("Ctrl-C pressed three times. Bye!\n");
exit(0);
}
}
return r;
}

Expand Down

0 comments on commit ab49adc

Please sign in to comment.