2 * This file is part of the sigrok project.
4 * Copyright (C) 2011 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "sigrok-cli.h"
33 static HANDLE stdin_handle
;
34 static DWORD stdin_mode
;
36 static struct termios term_orig
;
39 static int received_anykey(int fd
, int revents
, void *cb_data
)
41 /* Avoid compiler warnings. */
51 /* Turn off buffering on stdin. */
55 stdin_handle
= GetStdHandle(STD_INPUT_HANDLE
);
57 if (!GetConsoleMode(stdin_handle
, &stdin_mode
)) {
58 /* TODO: Error handling. */
61 SetConsoleMode(stdin_handle
, 0);
65 tcgetattr(STDIN_FILENO
, &term
);
66 memcpy(&term_orig
, &term
, sizeof(struct termios
));
67 term
.c_lflag
&= ~(ECHO
| ICANON
| ISIG
);
68 tcsetattr(STDIN_FILENO
, TCSADRAIN
, &term
);
71 sr_session_source_add(STDIN_FILENO
, G_IO_IN
, -1, received_anykey
, NULL
);
73 g_message("Press any key to stop acquisition.");
76 /* Restore stdin attributes. */
77 void clear_anykey(void)
80 SetConsoleMode(stdin_handle
, stdin_mode
);
82 tcflush(STDIN_FILENO
, TCIFLUSH
);
83 tcsetattr(STDIN_FILENO
, TCSANOW
, &term_orig
);