Use the tried and true FullDuplexSerial driver to communicate asynchronously with a user. Formatting is done via PropWare's standard PropWare::Printer and PropWare::Scanner classes, unlike the original FullDuplexSerial.spin object.
cmake_minimum_required(VERSION 3.12)
project(FullDuplexSerial_Demo)
create_simple_executable(${PROJECT_NAME}
FullDuplexSerial_Demo.cpp)
static void runScannerDemo (Printer &queuePrinter, Scanner &queueScanner);
static bool isAnswerNo (char const userInput[]);
Scanner scanner(
serial, &printer);
runScannerDemo(printer, scanner);
while (1);
}
void runScannerDemo (Printer &queuePrinter, Scanner &queueScanner) {
char userInput[64];
char name[64];
unsigned int age;
queuePrinter << "Hello! I'd like to teach you how to use PropWare to read from the terminal!\n";
do {
queuePrinter << "First, what's your name?\n>>> ";
queueScanner >> name;
queuePrinter << "And how old are you?\n>>> ";
queueScanner >> age;
queuePrinter << "Is your name " << name << " and are you " << age << " years old?\n>>> ";
queueScanner.input_prompt("", "Please enter either 'yes' or 'no' (y/n)\n>>> ", userInput, sizeof(userInput),
} while (isAnswerNo(userInput));
queuePrinter << "Hello, " << name << "!\n";
}
bool isAnswerNo (char const userInput[]) {
return 0 == strcmp("n", userInput) || 0 == strcmp("no", userInput);
}
Structure that contains data used by simple text device libraries.
text_t serial
Makes declarations like serial lcd to stand in for text_t lcd. Spelling is choice of Parallax educati...