]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/con-utils.c
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0+
11 #include "background.h"
12 #include "con-utils.h"
14 uint_fast8_t tstc(void)
20 int my_getchar(uint_fast8_t waitforchar
)
27 } while ((c
< 0) && waitforchar
);
33 /* test if ctrl-c was pressed */
35 static uint_fast8_t ctrlc_disabled
; /* see disable_ctrl() */
36 static uint_fast8_t ctrlc_was_pressed
;
38 uint_fast8_t ctrlc(void)
40 if (!ctrlc_disabled
) {
41 switch (serial_getc()) {
42 case 0x03: /* ^C - Control C */
43 ctrlc_was_pressed
= 1;
52 /* Reads user's confirmation.
53 Returns 1 if user's input is "y", "Y", "yes" or "YES"
55 uint_fast8_t confirm_yesno(void)
64 while (i
< sizeof(str_input
)) {
65 str_input
[i
] = my_getchar(1);
66 putchar(str_input
[i
]);
67 if (str_input
[i
] == '\r')
72 if (strncmp(str_input
, "y\r", 2) == 0 ||
73 strncmp(str_input
, "Y\r", 2) == 0 ||
74 strncmp(str_input
, "yes\r", 4) == 0 ||
75 strncmp(str_input
, "YES\r", 4) == 0)
80 /* pass 1 to disable ctrlc() checking, 0 to enable.
81 * returns previous state
83 uint_fast8_t disable_ctrlc(uint_fast8_t disable
)
85 uint_fast8_t prev
= ctrlc_disabled
; /* save previous state */
87 ctrlc_disabled
= disable
;
91 uint_fast8_t had_ctrlc (void)
93 return ctrlc_was_pressed
;
96 void clear_ctrlc(void)
98 ctrlc_was_pressed
= 0;