|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Project and Test harness for library simpletext
cmake_minimum_required(VERSION 3.12)
project(SimpleText_Demo)
create_simple_executable(${PROJECT_NAME} SimpleText_Demo.c)
#include "serial.h"
#define MORETESTING
{
int n;
char buffer[80];
char sval[80];
int buflen = 80;
int xval = 0;
int ival = 0x55;
float fval = 355/113.0;
float fval2 = 1.4;
float e = 2.71828184590;
char bigtext[] = "abcdefghijklmnopqrstuvwxyz";
#ifdef DIV0_NAN_TEST
float fproblem;
float f;
for(f = 5.0; f > -5.0; f -= 1.0) {
fproblem = 1.0 / f;
print(
"f = %02.2f, fproblem = %02.2f\n", f, fproblem);
}
for(f = 5.0; f > -5.0; f -= 1.0) {
fproblem = 1.0 / -f;
}
for(f = 5.0; f > -5.0; f -= 1.0) {
fproblem = atan(0.0/f);
print(
"f = %02.2f, fproblem = %02.2f\n", f, fproblem);
}
for(f = 5.0; f > -5.0; f -= 1.0) {
fproblem = atan(0.0/-f);
}
#endif
#ifdef MORETESTING
#if 1
putStr(
"\nEnter scan float string : ");
scan(
"%f %s", &fval, sval);
print(
"%f %s\n", fval, sval);
putStr(
"\nEnter sscan float string: ");
sscan(buffer,
"%f %s", &fval, sval);
sprint(buffer,
"%f %s", fval, sval);
#endif
sprint(buffer,
"%2d %4d %6d %8d %10d %15d", 2, 4, 6, 8, 10, 15);
sprint(buffer,
"%2x %4x %6x %8x %10x %15x", 2, 4, 6, 8, 10, 15);
sprint(buffer,
"%2b %4b %6b %8b %10b %15b", 2, 4, 6, 8, 10, 15);
sprint(buffer,
"%2.0f %4.1f %6.2f %8.3f %10.4f %15.6f\n", e, e, e, e, e, e);
for(n = 0; n < 1; n++) {
float f;
putStr(
"\nEnter two floating point numbers");
if(!n)
else
sscan(buffer,
"%f %f", &f, &fval2);
}
putStr(
"\nEnter a floating point number: ");
putStr(
"\nClose default console.\n");
writeStr(text,
"SimpleSerial Started.\n");
sprint(buffer,
"Hello, world! Again!\n");
#if 1
writeStr(text,
"\nEnter dscan float string: ");
dscan(text,
"%f %s", &fval, sval);
dprint(text,
"%f %s\n", fval, sval);
#endif
fval = 355/113.0;
writeStr(text,
"\nEnter a decimal number: ");
writeStr(text,
"\nEnter a hexadecimal number: ");
writeStr(text,
"\nEnter a binary number: ");
writeStr(text,
"\nEnter a floating point number: ");
writeStr(text,
"\nEnter values as: decimal hex float float string\n");
sscan(buffer,
"%d %x %f %f %s", &ival, &xval, &fval, &fval2, sval);
sprint(buffer,
"%s %d %x %f %f\n", sval, ival, xval, fval, fval2);
#endif
return 0;
}
void writeDecLen(text_t *device, int value, int width)
Print string representation of a decimal number to output device with a fixed number of digits.
void writeHexLen(text_t *device, int value, int digits)
Print string representation of a hexadecimal number to output device with a fixed number of digits.
int putln(const char *str)
Print string + new line on the transmit debug port.
void writeBinLen(text_t *device, int value, int digits)
Print string representation of a binary number to output with a fixed number of digits.
terminal * simpleterm_pointer(void)
Get default device pointer to SimpleIDE Terminal.
int putStrLen(char *str, int width)
Send a string with a certain number of characters.
int writeLine(text_t *device, char *str)
Send a string + new line to the device.
int int dscan(text_t *device, const char *fmt,...) __attribute__((format(printf
Convert formatted device input to the "..." args. The input is limited to 256 bytes.
void putFloat(float value)
Print string representation of a 32 bit floating point number to the debug port.
int dprint(text_t *device, const char *format,...) __attribute__((format(printf
Print format "..." args to the device The output is limited to 256 bytes.
int putLine(const char *str)
Print string + new line on the transmit debug port. This is an alias of putln.
void putDec(int value)
Print string representation of a decimal number to the debug port.
char * getStr(char *buffer, int max)
Get string of chars from the debug port.
void serial_close(serial *device)
Close serial connection.
void writeDec(text_t *device, int value)
Print string representation of a decimal number to output.
char * readStr(text_t *device, char *buffer, int max)
Get string of chars from the device.
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
void writeFloatPrecision(text_t *device, float value, int width, int precision)
Print string representation of a 32 bit floating point number to device with a certain number of deci...
int readDec(text_t *device)
Get decimal number from the device.
void simpleterm_close(void)
Closes the SimpleIDE Terminal connection in one cog so that it can be opened in another cog with simp...
float getFloat(void)
Get floating point number from the debug port.
void writeFloat(text_t *device, float value)
Print string representation of a 32 bit floating point number to device.
int readChar(text_t *device)
Get char from the device.
void writeHex(text_t *device, int value)
Print string representation of a hexadecimal number to output device.
void writeChar(text_t *device, char c)
Send a character to the device.
void putChar(char c)
Print a char to the debug port.
int int scan(const char *fmt,...) __attribute__((format(printf
Convert formatted simple terminal input to the "..." args. The input is limited to 256 bytes.
Structure that contains data used by simple text device libraries.
float readFloat(text_t *device)
Get floating point number from the device.
serial * serial_open(int rxpin, int txpin, int mode, int baudrate)
Open a simple (half duplex) serial connection.
int int int sprint(char *buffer, const char *format,...) __attribute__((format(printf
Print format "..." args to the output buffer. The output buffer must be big enough for the output.
int writeStr(text_t *device, char *str)
Send a string to the device.
void writeBin(text_t *device, int value)
Print string representation of a binary number to the receive device.
Generic definitions and functions for the Parallax Propeller.
int putStr(const char *str)
Print string to the debug port.
int readHex(text_t *device)
Get hexadecimal number from the device.
int writeStrLen(text_t *device, char *str, int width)
Send a string to the device.
int int int int sscan(const char *buffer, const char *fmt,...) __attribute__((format(printf
Convert formatted buffer to the "..." args.
int readBin(text_t *device)
Get binary number from the device.