PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
FullDuplexSerial_Demo.cpp

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)
find_package(PropWare REQUIRED)
project(FullDuplexSerial_Demo)
create_simple_executable(${PROJECT_NAME}
FullDuplexSerial_Demo.cpp)
static void runScannerDemo (Printer &queuePrinter, Scanner &queueScanner);
static bool isAnswerNo (char const userInput[]);
int main () {
FullDuplexSerial serial;
serial.start();
Printer printer(serial);
Scanner scanner(serial, &printer);
// This should look very familiar - it is the same code as Examples/PropWare_Scanner/Scanner_Demo.cpp
runScannerDemo(printer, scanner);
while (1);
}
void runScannerDemo (Printer &queuePrinter, Scanner &queueScanner) {
// A nice big buffer that can hold up to 63 characters from the user (the
// 64th is used by the null-terminator)
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);
}
printer.h
PropWare::Scanner
Interface for all classes capable of scanning.
Definition: scanner.h:43
YES_NO_COMP
const PropWare::YesNoComparator YES_NO_COMP
Global instance for shared use by PropWare applications.
Definition: comparator.cpp:29
main
int main(void)
Definition: GraphicsTest.c:20
scanner.h
text_struct
Structure that contains data used by simple text device libraries.
Definition: simpletext.h:81
PropWare::FullDuplexSerial
Converted to C++ using spin2cpp and then modified to become a PrintCapable object in PropWare's arsen...
Definition: fullduplexserial.h:42
PropWare::Printer
Container class that has formatting methods for human-readable output. This class can be constructed ...
Definition: printer.h:76
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33
serial
text_t serial
Makes declarations like serial lcd to stand in for text_t lcd. Spelling is choice of Parallax educati...
Definition: serial.h:68
fullduplexserial.h