33 static const size_t BUFFER_SIZE = 256;
35 static void runScannerDemo (
Printer &queuePrinter,
Scanner &queueScanner);
37 static bool isAnswerNo (
char const userInput[]);
52 char transmitBuffer[BUFFER_SIZE];
55 transmitMailbox.queue = &transmitQueue;
56 extern unsigned int _load_start_buffereduarttx_cog[];
57 cognew(_load_start_buffereduarttx_cog, &transmitMailbox.queue);
58 Printer queuePrinter(transmitQueue);
60 char receiveBuffer[BUFFER_SIZE];
63 receiveMailbox.queue = &receiveQueue;
64 extern unsigned int _load_start_buffereduartrx_cog[];
65 cognew(_load_start_buffereduartrx_cog, &receiveMailbox.queue);
66 Scanner queueScanner(receiveQueue, &queuePrinter);
69 runScannerDemo(queuePrinter, queueScanner);
74 void runScannerDemo (
Printer &queuePrinter,
Scanner &queueScanner) {
81 queuePrinter <<
"Hello! I'd like to teach you how to use PropWare to read from the terminal!\n";
84 queuePrinter <<
"First, what's your name?\n>>> ";
87 queuePrinter <<
"And how old are you?\n>>> ";
90 queuePrinter <<
"Is your name " << name <<
" and are you " << age <<
" years old?\n>>> ";
91 queueScanner.
input_prompt(
"",
"Please enter either 'yes' or 'no' (y/n)\n>>> ", userInput,
sizeof(userInput),
93 }
while (isAnswerNo(userInput));
95 queuePrinter <<
"Hello, " << name <<
"!\n";
98 bool isAnswerNo (
char const userInput[]) {
99 return 0 == strcmp(
"n", userInput) || 0 == strcmp(
"no", userInput);