add CTRL+C handler

This commit is contained in:
Alexander Popov 2023-07-30 00:52:44 +03:00
parent 9750dc3438
commit 9326e6e09a
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
1 changed files with 9 additions and 1 deletions

View File

@ -2,9 +2,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
/* Helper function for error handling. */
int check(enum sp_return result);
void handle_sigint(int sig);
bool INTERRUPT = false;
int main(int argc, char **argv) {
struct sp_port *serial_port;
@ -59,9 +63,11 @@ int main(int argc, char **argv) {
check(sp_set_flowcontrol(serial_port, SP_FLOWCONTROL_NONE));
puts("Connected.");
signal(SIGINT, handle_sigint);
/* Reading lines from serial port. */
bool reading = true;
while (reading) {
while (reading && !INTERRUPT) {
int pos = 0;
/* Character-by-character reading. */
@ -119,3 +125,5 @@ int check(enum sp_return result) {
return result;
}
}
void handle_sigint(int sig) { INTERRUPT = true; }