simpletext library  v0.98
Compact variations of put/get write/read and print/scan for smaller program sizes
Data Structures | Macros | Typedefs | Functions
simpletext.h File Reference

This library provides a collection of functions for communicating with text devices such as SimpleIDE Terminal, serial peripheral devices, and even VGA displays. More...

#include <propeller.h>
#include "serial.h"
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  text_struct

Macros

#define TERM_NAME_LEN   20
#define TERM_COG_LEN   7
#define getStopCOGID(id)   ((id)-(1))
#define setStopCOGID(id)   ((id)+(1))

Typedefs

typedef struct text_struct text_t
typedef text_t terminal

Functions

terminalsimpleterm_open (void)
 Reopens the SimpleIDE Terminal connection if it was closed previously. The SimpleIDE Terminal connection transmits on P30 and receives on P31 at 115200 bps. The port is a simple serial driver running in the same cog, and does not buffer bytes.
void simpleterm_close (void)
 Closes the SimpleIDE Terminal connection in one cog so that it can be opened in another cog with simpleterm_open, fdserial_open(30, 31, 0, 115200), or some other driver.
terminalsimpleterm_pointer (void)
 Get default device pointer to SimpleIDE Terminal.
int getBin (void)
 Get binary number from the debug port.
int getChar (void)
 Get char from the debug port.
int getDec (void)
 Get decimal number from the debug port.
float getFloat (void)
 Get floating point number from the debug port.
int getHex (void)
 Get hexadecimal number from the debug port.
char * getStr (char *buffer, int max)
 Get string of chars from the debug port.
void putBin (int value)
 Print string representation of a binary number to the debug port.
void putBinDigits (int value, int digits)
 Print string representation of a binary number to debug port with a fixed number of digits.
void putChar (char c)
 Print a char to the debug port.
void putDec (int value)
 Print string representation of a decimal number to the debug port.
void putDecDigits (int value, int width)
 Print string representation of a decimal number to the debug port.
void putFloat (float value)
 Print string representation of a 32 bit floating point number to the debug port.
void putHex (int value)
 Print string representation of a hexadecimal number to the debug port.
void putHexDigits (int value, int digits)
 Print string representation of a hexadecimal number to the debug port with a fixed number of digits.
void putFloatPrecision (float value, int width, int precision)
 Print string representation of a 32 bit floating point number to the debug port with a fixed number of digits.
int putln (const char *str)
 Print string + new line on the transmit debug port.
int putLine (const char *str)
 Print string + new line on the transmit debug port. This is an alias of putln.
int putStr (const char *str)
 Print string to the debug port.
int putStrDigits (char *str, int width)
 Send a string on the transmit device.
int readBin (text_t *device)
 Get binary number from the receive device.
int readChar (text_t *device)
 Get char from the receive device.
int readDec (text_t *device)
 Get decimal number from the receive device.
float readFloat (text_t *device)
 Get floating point number from the receive device.
int readHex (text_t *device)
 Get hexadecimal number from the receive device.
char * readStr (text_t *device, char *buffer, int max)
 Get string of chars from the receive device.
void writeBin (text_t *device, int value)
 Print string representation of a binary number to the receive device.
void writeBinDigits (text_t *device, int value, int digits)
 Print string representation of a binary number to output with a fixed number of digits.
void writeChar (text_t *device, char c)
 Send char on the transmit device.
void writeDec (text_t *device, int value)
 Print string representation of a decimal number to output.
void writeDecDigits (text_t *device, int value, int width)
 Print string representation of a decimal number to output device with a fixed number of digits.
void writeFloat (text_t *device, float value)
 Print string representation of a 32 bit floating point number to device.
void writeHex (text_t *device, int value)
 Print string representation of a hexadecimal number to output device.
void writeHexDigits (text_t *device, int value, int digits)
 Print string representation of a hexadecimal number to output device with a fixed number of digits.
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 decimal point digits.
int writeLine (text_t *device, char *str)
 Send a string + new line on the transmit device.
int writeStr (text_t *device, char *str)
 Send a string on the transmit device.
int writeStrDigits (text_t *device, char *str, int width)
 Send a string on the transmit 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.
int int printi (const char *format,...) __attribute__((format(printf
 Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.
int int int scan (const char *fmt,...) __attribute__((format(printf
 Convert formatted simple terminal input to the "..." args. The input is limited to 256 bytes.
int int int int scani (const char *fmt,...) __attribute__((format(printf
 Convert formatted simple terminal input to the "..." args. This version does not provide floating point conversions. The input is limited to 256 bytes.
int int int int 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 int int int int int dprinti (text_t *device, const char *format,...) __attribute__((format(printf
 Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.
int int int int int 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.
int int int int int int int int dscani (text_t *device, const char *fmt,...) __attribute__((format(printf
 Convert formatted device input to the "..." args. This version does not provide floating point conversions. The input is limited to 256 bytes.
int int int int int int 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 int int int int int int
int int int 
sprinti (char *buffer, const char *format,...) __attribute__((format(printf
 Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.
int int int int int int int
int int int int 
sscan (const char *buffer, const char *fmt,...) __attribute__((format(printf
 Convert formatted buffer to the "..." args.
int int int int int int int
int int int int int 
sscani (const char *buffer, const char *fmt,...) __attribute__((format(printf
 Convert formatted buffer to the "..." args. This version does not provide floating point conversions.
int int int int int int int
int int int int int int 
printNumber (text_t *p, unsigned long u, int base, int width, int fill_char)
char * _safe_gets (text_t *term, char *origBuf, int count)
const char * _scanf_getf (const char *str, float *dst)
const char * _scanf_getl (const char *str, int *dst, int base, unsigned width, int isSigned)
int SPUTC (int c, char *buf)
int SPUTS (char *s, char *obuf)
int SPUTL (unsigned long u, int base, int width, int fill_char, char *obuf)
int _doscanf (const char *str, const char *fmt, va_list args)
int _intscanf (const char *str, const char *fmt, va_list args)
int _dosprnt (const char *fmt, va_list args, char *obuf)
int _intsprnt (const char *fmt, va_list args, char *obuf)
char * float2string (float f, char *s, int width, int precision)
float string2float (char *s, char **end)

Detailed Description

This library provides a collection of functions for communicating with text devices such as SimpleIDE Terminal, serial peripheral devices, and even VGA displays.

Author
Steve Denson

Features:

Version
0.98 Digits versions of put/get and write/read added for transmitting and receiving values with fixed numbers of digits. Floating point output functions updated to handle nan (not a number) and +/- inf (infinity). printi, dprinti, scani, dscani, sprinti, sscani functions added for supporting non-floating point with less program space.

Typedef Documentation

typedef text_t terminal

By default the terminal will use simple serial for input/output It can be overloaded.

Function Documentation

int int int int int dprint ( text_t device,
const char *  format,
  ... 
)

Print format "..." args to the device The output is limited to 256 bytes.

Note
See print for format specifiers.
Parameters
devicePreviously open/started terminal device.
formatC printf comparable format string.
...Arguments to use with the format string.
Returns
Number of bytes placed into the buffer.
int int int int int int dprinti ( text_t device,
const char *  format,
  ... 
)

Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.

Note
See print for format specifiers except f.
Parameters
devicePreviously open/started terminal device.
formatC printf comparable format string.
...Arguments to use with the format string.
Returns
Number of bytes placed into the buffer.
int int int int int int int dscan ( text_t device,
const char *  fmt,
  ... 
)

Convert formatted device input to the "..." args. The input is limited to 256 bytes.

Note
See scan for format specifiers.
Parameters
devicePreviously open/started terminal device.
*fmtC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
int int int int int int int int dscani ( text_t device,
const char *  fmt,
  ... 
)

Convert formatted device input to the "..." args. This version does not provide floating point conversions. The input is limited to 256 bytes.

Note
See scan for format specifiers.
Parameters
devicePreviously open/started terminal device.
*fmtC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
int getBin ( void  )

Get binary number from the debug port.

Returns
Value received.
int getChar ( void  )

Get char from the debug port.

Returns
Character received as an integer.
int getDec ( void  )

Get decimal number from the debug port.

Returns
Value received.
float getFloat ( void  )

Get floating point number from the debug port.

Returns
Value received.
int getHex ( void  )

Get hexadecimal number from the debug port.

Returns
Value received.
char* getStr ( char *  buffer,
int  max 
)

Get string of chars from the debug port.

Parameters
*bufferarray of chars with enough elements to hold the input string plus 2 null terminators.
maxMaximum size to read and should be less or equal buffer size.
Returns
Pointer to string received.
int print ( const char *  format,
  ... 
)

Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.

Format specifiers for print dprint, and sprint:

%% Prints % sign to the output.

b Prints binary representation of the int parameter. Note that b is not an ANSI standard format specifier.

c Prints char representation of the int parameter.

d Prints decimal integer representation of the int parameter.

f Prints floating point representation of the float parameter.

s Prints string representation of the char* parameter.

u Prints unsigned integer representation of the int parameter.

x Prints hexadecimal integer representation of the int parameter.

Width and precision n.p cause n digits of the integer to print, and p digits of the decimal to print.

Parameters
formatC printf comparable format string.
...Arguments to use with the format string.
Returns
Number of bytes placed into the buffer.
int int printi ( const char *  format,
  ... 
)

Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.

Note
See print for format specifiers except f.
Parameters
formatC printf comparable format string.
...Arguments to use with the format string.
Returns
Number of bytes placed into the buffer.
void putBin ( int  value)

Print string representation of a binary number to the debug port.

Parameters
valueNumber to print.
void putBinDigits ( int  value,
int  digits 
)

Print string representation of a binary number to debug port with a fixed number of digits.

Parameters
valueNumber to print.
digitsNumber of characters to print.
void putChar ( char  c)

Print a char to the debug port.

Parameters
cChar to send.
void putDec ( int  value)

Print string representation of a decimal number to the debug port.

Parameters
valueNumber to print.
void putDecDigits ( int  value,
int  width 
)

Print string representation of a decimal number to the debug port.

Parameters
valueNumber to print.
widthNumber of characters to print padded by zeroes.
void putFloat ( float  value)

Print string representation of a 32 bit floating point number to the debug port.

Parameters
valueNumber to print.
void putFloatPrecision ( float  value,
int  width,
int  precision 
)

Print string representation of a 32 bit floating point number to the debug port with a fixed number of digits.

Parameters
valueNumber to print.
widthNumber of characters to print.
precisionNumber of decimal point digits to print.
void putHex ( int  value)

Print string representation of a hexadecimal number to the debug port.

Parameters
valueNumber to print.
void putHexDigits ( int  value,
int  digits 
)

Print string representation of a hexadecimal number to the debug port with a fixed number of digits.

Parameters
valueNumber to print.
digitsNumber of hexadecimal characters to print padded by zeroes.
int putLine ( const char *  str)

Print string + new line on the transmit debug port. This is an alias of putln.

Parameters
*strNull terminated string to send.
int putln ( const char *  str)

Print string + new line on the transmit debug port.

Parameters
*strNull terminated string to send.
int putStr ( const char *  str)

Print string to the debug port.

Parameters
*strNull terminated string to send.
int putStrDigits ( char *  str,
int  width 
)

Send a string on the transmit device.

Parameters
strNull terminated string to send.
widthNumber of characters to print padded by spaces.
int readBin ( text_t device)

Get binary number from the receive device.

Parameters
*devicePreviously open/started terminal device.
Returns
Number received.
int readChar ( text_t device)

Get char from the receive device.

Parameters
*devicePreviously open/started terminal device.
Returns
character received as an int value.
int readDec ( text_t device)

Get decimal number from the receive device.

Parameters
*devicePreviously open/started terminal device.
Returns
Number received.
float readFloat ( text_t device)

Get floating point number from the receive device.

Parameters
*devicePreviously open/started terminal device.
Returns
Number received.
int readHex ( text_t device)

Get hexadecimal number from the receive device.

Parameters
*devicePreviously open/started terminal device.
Returns
Number received.
char* readStr ( text_t device,
char *  buffer,
int  max 
)

Get string of chars from the receive device.

Parameters
*devicePreviously open/started terminal device.
bufferChar array with enough elements to hold the input string.
maxMaximum size to read and should be less or equal buffer size.
Returns
string received.
int int int scan ( const char *  fmt,
  ... 
)

Convert formatted simple terminal input to the "..." args. The input is limited to 256 bytes.

Format specifiers for scan, dscan, and sscan:

  • %% Scan % sign to the input.
  • b Scans binary representation to the int parameter. Note that b is not an ANSI standard format specifier.
  • c Scans char representation to the int parameter.
  • d Scans integer representation to the int parameter.
  • f Scans floating point representation to the float parameter.
  • s Scans string representation to the char* parameter.
  • u Scans unsigned integer representation to the int parameter.
  • x Scans hexadecimal integer representation to the int parameter.

Width and precision n.p cause n digits to the integer to print, and p digits to the decimal to print.

Parameters
*fmtC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
int int int int scani ( const char *  fmt,
  ... 
)

Convert formatted simple terminal input to the "..." args. This version does not provide floating point conversions. The input is limited to 256 bytes.

Note
See scan for format specifiers.
Parameters
*fmtC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
terminal* simpleterm_open ( void  )

Reopens the SimpleIDE Terminal connection if it was closed previously. The SimpleIDE Terminal connection transmits on P30 and receives on P31 at 115200 bps. The port is a simple serial driver running in the same cog, and does not buffer bytes.

Returns
0 if port is already open, else returns term pointer.
terminal* simpleterm_pointer ( void  )

Get default device pointer to SimpleIDE Terminal.

Returns
terminal* Pointer to SimpleIDE Terminal device.

Get the SimpleTerm default text_t pointer

int int int int int int int int int sprint ( char *  buffer,
const char *  format,
  ... 
)

Print format "..." args to the output buffer. The output buffer must be big enough for the output.

Note
See print for format specifiers.
Parameters
bufferPointer to memory where formatted output can be stored.
*formatis a C printf comparable format string.
...is the arguments to use with the format string.
Returns
the number of bytes placed into the buffer.
int int int int int int int int int int sprinti ( char *  buffer,
const char *  format,
  ... 
)

Print integer and char only format "..." args to the default simple terminal device. This version does not support floating point. The output is limited to 256 bytes.

Note
See print for format specifiers except f.
Parameters
bufferPointer to memory where formatted output can be stored.
*formatC printf comparable format string.
...Arguments to use with the format string.
Returns
Number of bytes placed into the buffer.
int int int int int int int int int int int sscan ( const char *  buffer,
const char *  fmt,
  ... 
)

Convert formatted buffer to the "..." args.

Note
See scan for format specifiers.
Parameters
*bufferPointer to memory where formatted output can be stored.
*fmtC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
int int int int int int int int int int int int sscani ( const char *  buffer,
const char *  fmt,
  ... 
)

Convert formatted buffer to the "..." args. This version does not provide floating point conversions.

Note
See scan for format specifiers.
Parameters
bufferPointer to memory where formatted output can be stored.
formatC printf comparable format string.
...Arguments where output will go and must be pointers.
Returns
Number of bytes placed into the buffer.
void writeBin ( text_t device,
int  value 
)

Print string representation of a binary number to the receive device.

Parameters
*devicePreviously open/started terminal device.
valueNumber to print.
void writeBinDigits ( text_t device,
int  value,
int  digits 
)

Print string representation of a binary number to output with a fixed number of digits.

Parameters
*devicePreviously open/started terminal device.
valueNumber to print.
digitsNumber of characters to print.
void writeChar ( text_t device,
char  c 
)

Send char on the transmit device.

Parameters
devicePreviously open/started terminal device.
cChar to send.
void writeDec ( text_t device,
int  value 
)

Print string representation of a decimal number to output.

Parameters
devicePreviously open/started terminal device.
valueNumber to print.
void writeDecDigits ( text_t device,
int  value,
int  width 
)

Print string representation of a decimal number to output device with a fixed number of digits.

Parameters
devicePreviously open/started terminal device.
valueNumber to print.
widthNumber of characters to print padded by spaces.
void writeFloat ( text_t device,
float  value 
)

Print string representation of a 32 bit floating point number to device.

Parameters
devicePreviously open/started terminal device.
valueNumber to print.
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 decimal point digits.

Parameters
devicePreviously open/started terminal device.
widthNumber of characters to print.
precisionNumber of decimal point digits to print.
valueNumber to print.
void writeHex ( text_t device,
int  value 
)

Print string representation of a hexadecimal number to output device.

Parameters
devicePreviously open/started terminal device.
valueNumber to print.
void writeHexDigits ( text_t device,
int  value,
int  digits 
)

Print string representation of a hexadecimal number to output device with a fixed number of digits.

Parameters
devicePreviously open/started terminal device.
valueNumber to print.
digitsNumber of hexadecimal characters to print.
int writeLine ( text_t device,
char *  str 
)

Send a string + new line on the transmit device.

Parameters
devicePreviously open/started terminal device.
strNull terminated string to send.
int writeStr ( text_t device,
char *  str 
)

Send a string on the transmit device.

Parameters
devicePreviously open/started terminal device.
strNull terminated string to send.
int writeStrDigits ( text_t device,
char *  str,
int  width 
)

Send a string on the transmit device.

Parameters
devicepreviously open/started terminal device.
strNull terminated string to send.
widthNumber of characters to print padded by spaces.