]>
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_yes(void)
85 uint_fast8_t checkch
, ch
;
87 checkch
= ch
= my_getchar(1);
95 return (checkch
== 'y');
99 uint_fast8_t confirm_yesno(void)
105 while (serial_getc() < 0)
108 while (i
< sizeof(str_input
)) {
109 str_input
[i
] = my_getchar(1);
110 putchar(str_input
[i
]);
111 if (str_input
[i
] == '\r')
116 if (strncmp(str_input
, "y\r", 2) == 0 ||
117 strncmp(str_input
, "Y\r", 2) == 0 ||
118 strncmp(str_input
, "yes\r", 4) == 0 ||
119 strncmp(str_input
, "YES\r", 4) == 0)
125 /* pass 1 to disable ctrlc() checking, 0 to enable.
126 * returns previous state
128 uint_fast8_t disable_ctrlc(uint_fast8_t disable
)
130 uint_fast8_t prev
= ctrlc_disabled
; /* save previous state */
132 ctrlc_disabled
= disable
;
136 uint_fast8_t had_ctrlc (void)
138 return ctrlc_was_pressed
;
141 void clear_ctrlc(void)
143 ctrlc_was_pressed
= 0;