printf-utils: Added function printf_and_wait
This commit is contained in:
1 parent
f79b653523
commit
32f2e53304
3 files changed
+36
-3
No files matched your search
+1
-3
@@ -721,9 +721,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if ( usb_dev->flash_device->protocol != FLASH_COLD ) {
|
if ( usb_dev->flash_device->protocol != FLASH_COLD ) {
|
||||||
usb_close_device(usb_dev);
|
usb_close_device(usb_dev);
|
||||||
printf("Unplug USB cable, turn device off, press ENTER and plug USB cable again\n");
|
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
|
||||||
fflush(stdin);
|
|
||||||
getchar();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "printf-utils.h"
|
#include "printf-utils.h"
|
||||||
|
|
||||||
@@ -57,3 +59,35 @@ void printf_progressbar(unsigned long long part, unsigned long long total) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printf_and_wait(const char * format, ...) {
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
char c;
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(0, &rfds);
|
||||||
|
|
||||||
|
while ( select(1, &rfds, NULL, NULL, &tv) == 1 )
|
||||||
|
read(0, &c, 1);
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
vprintf(format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(0, &rfds);
|
||||||
|
|
||||||
|
while ( select(1, &rfds, NULL, NULL, NULL) == 1 ) {
|
||||||
|
read(0, &c, 1);
|
||||||
|
if ( c == '\n' )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,5 +29,6 @@ extern int printf_prev;
|
|||||||
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
|
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
void printf_progressbar(unsigned long long part, unsigned long long total);
|
void printf_progressbar(unsigned long long part, unsigned long long total);
|
||||||
|
void printf_and_wait(const char * format, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user