]>
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+
12 #include "background.h"
13 #include "con-utils.h"
15 uint_fast8_t tstc(void)
21 int my_getchar(uint_fast8_t waitforchar
)
28 } while ((c
< 0) && waitforchar
);
30 #ifdef CONFIG_SYS_FBOOTSIG
34 static const FLASH
unsigned char bootsig
[] = {CONFIG_SYS_FBOOTSIG
};
39 if (bootsig
[pb
] == 0) {
41 wdt_enable(WDTO_15MS
);
48 if (bootsig
[pb
] == uc
)
59 /* test if ctrl-c was pressed */
61 static uint_fast8_t ctrlc_disabled
; /* see disable_ctrl() */
62 static uint_fast8_t ctrlc_was_pressed
;
64 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;