]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/con-utils.c
6 #include "background.h"
9 uint_fast8_t tstc(void)
15 int my_getchar(uint_fast8_t waitforchar
)
22 } while ((c
< 0) && waitforchar
);
28 /* test if ctrl-c was pressed */
30 static uint_fast8_t ctrlc_disabled
; /* see disable_ctrl() */
31 static uint_fast8_t ctrlc_was_pressed
;
33 uint_fast8_t ctrlc(void)
35 if (!ctrlc_disabled
) {
36 switch (serial_getc()) {
37 case 0x03: /* ^C - Control C */
38 ctrlc_was_pressed
= 1;
47 /* Reads user's confirmation.
48 Returns 1 if user's input is "y", "Y", "yes" or "YES"
50 uint_fast8_t confirm_yesno(void)
59 while (i
< sizeof(str_input
)) {
60 str_input
[i
] = my_getchar(1);
61 putchar(str_input
[i
]);
62 if (str_input
[i
] == '\r')
67 if (strncmp(str_input
, "y\r", 2) == 0 ||
68 strncmp(str_input
, "Y\r", 2) == 0 ||
69 strncmp(str_input
, "yes\r", 4) == 0 ||
70 strncmp(str_input
, "YES\r", 4) == 0)
75 /* pass 1 to disable ctrlc() checking, 0 to enable.
76 * returns previous state
78 uint_fast8_t disable_ctrlc(uint_fast8_t disable
)
80 uint_fast8_t prev
= ctrlc_disabled
; /* save previous state */
82 ctrlc_disabled
= disable
;
86 uint_fast8_t had_ctrlc (void)
88 return ctrlc_was_pressed
;
91 void clear_ctrlc(void)
93 ctrlc_was_pressed
= 0;