]>
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+
13 #include "background.h"
14 #include "con-utils.h"
16 uint_fast8_t tstc(void)
22 int my_getchar(uint_fast8_t waitforchar
)
29 } while ((c
< 0) && waitforchar
);
31 #ifdef CONFIG_SYS_FBOOTSIG
35 static const FLASH
unsigned char bootsig
[] = {CONFIG_SYS_FBOOTSIG
};
40 if (bootsig
[pb
] == 0) {
42 wdt_enable(WDTO_15MS
);
49 if (bootsig
[pb
] == uc
)
60 /* test if ctrl-c was pressed */
62 static uint_fast8_t ctrlc_disabled
; /* see disable_ctrl() */
63 static uint_fast8_t ctrlc_was_pressed
;
65 uint_fast8_t ctrlc(void)
68 if (!ctrlc_disabled
) {
69 switch (serial_getc()) {
70 case 0x03: /* ^C - Control C */
71 ctrlc_was_pressed
= 1;
80 /* Reads user's confirmation.
81 Returns 1 if user's input is "y", "Y", "yes" or "YES"
83 uint_fast8_t confirm_yesno(void)
92 while (i
< sizeof(str_input
)) {
93 str_input
[i
] = my_getchar(1);
94 putchar(str_input
[i
]);
95 if (str_input
[i
] == '\r')
100 if (strncmp(str_input
, "y\r", 2) == 0 ||
101 strncmp(str_input
, "Y\r", 2) == 0 ||
102 strncmp(str_input
, "yes\r", 4) == 0 ||
103 strncmp(str_input
, "YES\r", 4) == 0)
108 /* pass 1 to disable ctrlc() checking, 0 to enable.
109 * returns previous state
111 uint_fast8_t disable_ctrlc(uint_fast8_t disable
)
113 uint_fast8_t prev
= ctrlc_disabled
; /* save previous state */
115 ctrlc_disabled
= disable
;
119 uint_fast8_t had_ctrlc (void)
121 return ctrlc_was_pressed
;
124 void clear_ctrlc(void)
126 ctrlc_was_pressed
= 0;