add CTRL+C handler
This commit is contained in:
parent
9750dc3438
commit
9326e6e09a
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user