]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/con-utils.c
5ee1ff1585fbbdd10c50973ebec374c97ac69db2
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)
67 if (!ctrlc_disabled
) {
68 switch (serial_getc()) {
69 case 0x03: /* ^C - Control C */
70 ctrlc_was_pressed
= 1;
79 /* Reads user's confirmation.
80 Returns 1 if user's input is "y", "Y", "yes" or "YES"
82 uint_fast8_t confirm_yesno(void)
91 while (i
< sizeof(str_input
)) {
92 str_input
[i
] = my_getchar(1);
93 putchar(str_input
[i
]);
94 if (str_input
[i
] == '\r')
99 if (strncmp(str_input
, "y\r", 2) == 0 ||
100 strncmp(str_input
, "Y\r", 2) == 0 ||
101 strncmp(str_input
, "yes\r", 4) == 0 ||
102 strncmp(str_input
, "YES\r", 4) == 0)
107 /* pass 1 to disable ctrlc() checking, 0 to enable.
108 * returns previous state
110 uint_fast8_t disable_ctrlc(uint_fast8_t disable
)
112 uint_fast8_t prev
= ctrlc_disabled
; /* save previous state */
114 ctrlc_disabled
= disable
;
118 uint_fast8_t had_ctrlc (void)
120 return ctrlc_was_pressed
;
123 void clear_ctrlc(void)
125 ctrlc_was_pressed
= 0;