simpletext library  v0.85
Compact variations of put/get write/read and print/scan for smaller program sizes
Data Structures | Macros | Typedefs | Functions
simpletext.h File Reference
#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)
 
void simpleterm_close (void)
 
terminalsimpleterm_pointer (void)
 
int getBin (void)
 
int getChar (void)
 
int getDec (void)
 
float getFloat (void)
 
int getHex (void)
 
char * getStr (char *buffer, int max)
 
void putBin (int value)
 
void putChar (char c)
 
void putDec (int value)
 
void putFloat (float value)
 
void putHex (int value)
 
int putln (const char *str)
 
int putLine (const char *str)
 
int putStr (const char *str)
 
int readBin (text_t *device)
 
int readChar (text_t *device)
 
int readDec (text_t *device)
 
float readFloat (text_t *device)
 
int readHex (text_t *device)
 
char * readStr (text_t *device, char *buffer, int max)
 
void writeBin (text_t *device, int value)
 
void writeBinDigits (text_t *device, int value, int digits)
 
void writeChar (text_t *device, char c)
 
void writeDec (text_t *device, int value)
 
void writeDecDigits (text_t *device, int value, int width)
 
void writeFloat (text_t *device, float value)
 
void writeHex (text_t *device, int value)
 
void writeHexDigits (text_t *device, int value, int digits)
 
void writeFloatPrecision (text_t *device, float value, int width, int precision)
 
int writeLine (text_t *device, char *str)
 
int writeStr (text_t *device, char *str)
 
int writeStrDigits (text_t *device, char *str, int width)
 
int print (const char *format,...)
 
int scan (const char *fmt,...)
 
int dprint (text_t *device, const char *format,...)
 
int dscan (text_t *device, const char *fmt,...)
 
int sprint (char *buffer, const char *format,...)
 
int sscan (const char *buffer, const char *fmt,...)
 
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 _doscanf (const char *str, const char *fmt, va_list args)
 
int _dosprnt (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

Author
Steve Denson
Version
0.85

Simple Terminal Library API definition.

This library is provided with the following in mind:

Typedef Documentation

typedef text_t terminal

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

Function Documentation

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

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

Parameters
deviceis where to put the formatted output.
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 dscan ( text_t device,
const char *  fmt,
  ... 
)

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

Parameters
deviceis where to get the formatted input.
formatis a C printf comparable format string.
...is the arguments where output will go and must be pointers. returns the number of bytes placed into the buffer.
int getBin ( void  )

Get a binary number from the debug port.

Returns
number received.
int getChar ( void  )

Get a char from the debug port.

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

Get a decimal number from the debug port.

Returns
number received.
float getFloat ( void  )

Get a floating point number from the debug port.

Returns
number received.
int getHex ( void  )

Get a hexadecimal number from the debug port.

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

Get a string of chars from the debug port.

Parameters
bufferis a previously declared array of char big enough to hold the input string plus 2 null terminators.
maxis the maximum size to read and should be less or equal buffer size.
Returns
string received.
int print ( const char *  format,
  ... 
)

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

Parameters
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.
void putBin ( int  value)

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

Parameters
valueis number to print.
digitsis number of characters to print.
void putChar ( char  c)

Send a char on the debug port.

Parameters
cis the char to send.
void putDec ( int  value)

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

Parameters
valueis number to print.
void putFloat ( float  value)

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

Parameters
valueis number to print.
void putHex ( int  value)

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

Parameters
valueis number to print.
digitsis number of characters to print.
int putLine ( const char *  str)

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

Parameters
stris the null terminated string to send.
int putln ( const char *  str)

Send a string + new line on the transmit debug port.

Parameters
stris the null terminated string to send.
int putStr ( const char *  str)

Send a string on the transmit debug port.

Parameters
stris the null terminated string to send.
int readBin ( text_t device)

Get a binary number from the receive device.

Parameters
deviceis a previously open/started terminal device.
Returns
number received.
int readChar ( text_t device)

Get a char from the receive device.

Parameters
deviceis a previously open/started terminal device.
Returns
character received as an integer.
int readDec ( text_t device)

Get a decimal number from the receive device.

Parameters
deviceis a previously open/started terminal device.
Returns
number received.
float readFloat ( text_t device)

Get a floating point number from the receive device.

Parameters
deviceis a previously open/started terminal device.
Returns
number received.
int readHex ( text_t device)

Get a hexadecimal number from the receive device.

Parameters
deviceis a previously open/started terminal device.
Returns
number received.
char* readStr ( text_t device,
char *  buffer,
int  max 
)

Get a string of chars from the receive device.

Parameters
deviceis a previously open/started terminal device.
bufferis a previously declared array of char big enough to hold the input string.
maxis the maximum size to read and should be less or equal buffer size.
Returns
string received.
int scan ( const char *  fmt,
  ... 
)

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

Parameters
formatis a C printf comparable format string.
...is the arguments where output will go and must be pointers. returns the number of bytes placed into the buffer.
void simpleterm_close ( void  )

This function is provided if a different default driver is to be used. The function should be called before opening another driver.

terminal* simpleterm_open ( void  )

This function is opened by default when the library is used. The port by default transmits on P30 and receives on P31 at 115200 bps. The port is a simple serial driver and does not buffer bytes.

Users do not have to call this unless the termial has been closed.

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

This returns the default debug port device.

Get the SimpleTerm default text_t pointer

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

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

Parameters
bufferis where to put the formatted output.
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 sscan ( const char *  buffer,
const char *  fmt,
  ... 
)

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

Parameters
bufferis where to put the formatted output.
formatis a C printf comparable format string.
...is the arguments where output will go and must be pointers. returns the number of bytes placed into the buffer.
void writeBin ( text_t device,
int  value 
)

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

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
void writeBinDigits ( text_t device,
int  value,
int  digits 
)

Print a string representation of a binary number to output

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
digitsis number of characters to print.
void writeChar ( text_t device,
char  c 
)

Send a char on the transmit device.

Parameters
deviceis a previously open/started terminal device.
cis the char to send.
void writeDec ( text_t device,
int  value 
)

Print a string representation of a decimal number to output

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
void writeDecDigits ( text_t device,
int  value,
int  width 
)

Print a string representation of a decimal number to output

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
widthis number of characters to print padded by spaces.
void writeFloat ( text_t device,
float  value 
)

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

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
void writeFloatPrecision ( text_t device,
float  value,
int  width,
int  precision 
)

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

Parameters
deviceis a previously open/started terminal device.
widthis number of characters to print.
precisionis number of decimal point digits to print.
valueis number to print.
void writeHex ( text_t device,
int  value 
)

Print a string representation of a hexadecimal number to output

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
void writeHexDigits ( text_t device,
int  value,
int  digits 
)

Print a string representation of a hexadecimal number to output

Parameters
deviceis a previously open/started terminal device.
valueis number to print.
digitsis number of hexadecimal characters to print.
int writeLine ( text_t device,
char *  str 
)

Send a string + new line on the transmit device.

Parameters
deviceis a previously open/started terminal device.
stris the null terminated string to send.
int writeStr ( text_t device,
char *  str 
)

Send a string on the transmit device.

Parameters
deviceis a previously open/started terminal device.
stris the null terminated string to send.
int writeStrDigits ( text_t device,
char *  str,
int  width 
)

Send a string on the transmit device.

Parameters
deviceis a previously open/started terminal device.
stris the null terminated string to send.
widthis number of characters to print padded by spaces.