simpletext library v0.85 Compact variations of put/get write/read and print/scan for smaller program sizes

- Main Page
- Data Structures
- Files

- File List
- Globals

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
terminal * | simpleterm_open (void)
void | simpleterm_close (void)
terminal * | simpleterm_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

Copyright
  Copyright (C) 2013, Parallax Inc. See end of file for terms of use.

Simple Terminal Library API definition.

This library is provided with the following in mind:

- Designed for minimum size with generic IO devices.
- Designed for any character IO device using rxChar/txChar functions.
- Contains 2 built-in device drivers FdSerial and SimpleSerial.
- Supports get/print decimal, binary, float, hex, char, and string.
- Supports print format values to buffer comparable to sprintf (printBuffFormat).
- Supports scan format values from buffer comparable to sscanf (scanBuffFormat).

## 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

  device | is where to put the formatted output.
  format | is 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

  device | is where to get the formatted input.
  format | is 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

  buffer | is a previously declared array of char big enough to hold the input string plus 2 null terminators.
  max | is 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

  format | is 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

  value | is number to print.
  digits | is number of characters to print.

void putChar | ( | char | c) |  |

Send a char on the debug port.

Parameters

  c | is the char to send.

void putDec | ( | int | value) |  |

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

Parameters

  value | is number to print.

void putFloat | ( | float | value) |  |

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

Parameters

  value | is number to print.

void putHex | ( | int | value) |  |

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

Parameters

  value | is number to print.
  digits | is 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

  str | is the null terminated string to send.

int putln | ( | const char * | str) |  |

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

Parameters

  str | is the null terminated string to send.

int putStr | ( | const char * | str) |  |

Send a string on the transmit debug port.

Parameters

  str | is the null terminated string to send.

int readBin | ( | text_t * | device) |  |

Get a binary number from the receive device.

Parameters

  device | is a previously open/started terminal device.

Returns
  number received.

int readChar | ( | text_t * | device) |  |

Get a char from the receive device.

Parameters

  device | is 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

  device | is a previously open/started terminal device.

Returns
  number received.

float readFloat | ( | text_t * | device) |  |

Get a floating point number from the receive device.

Parameters

  device | is a previously open/started terminal device.

Returns
  number received.

int readHex | ( | text_t * | device) |  |

Get a hexadecimal number from the receive device.

Parameters

  device | is 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

  device | is a previously open/started terminal device.
  buffer | is a previously declared array of char big enough to hold the input string.
  max | is 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

  format | is 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

  buffer | is where to put the formatted output.
  format | is 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

  buffer | is where to put the formatted output.
  format | is 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

  device | is a previously open/started terminal device.
  value | is number to print.

void writeBinDigits | ( | text_t * | device,
|  | int | value,
|  | int | digits
| ) |  |

Print a string representation of a binary number to output

Parameters

  device | is a previously open/started terminal device.
  value | is number to print.
  digits | is number of characters to print.

void writeChar | ( | text_t * | device,
|  | char | c
| ) |  |

Send a char on the transmit device.

Parameters

  device | is a previously open/started terminal device.
  c | is the char to send.

void writeDec | ( | text_t * | device,
|  | int | value
| ) |  |

Print a string representation of a decimal number to output

Parameters

  device | is a previously open/started terminal device.
  value | is number to print.

void writeDecDigits | ( | text_t * | device,
|  | int | value,
|  | int | width
| ) |  |

Print a string representation of a decimal number to output

Parameters

  device | is a previously open/started terminal device.
  value | is number to print.
  width | is 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

  device | is a previously open/started terminal device.
  value | is 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

  device | is a previously open/started terminal device.
  width | is number of characters to print.
  precision | is number of decimal point digits to print.
  value | is number to print.

void writeHex | ( | text_t * | device,
|  | int | value
| ) |  |

Print a string representation of a hexadecimal number to output

Parameters

  device | is a previously open/started terminal device.
  value | is number to print.

void writeHexDigits | ( | text_t * | device,
|  | int | value,
|  | int | digits
| ) |  |

Print a string representation of a hexadecimal number to output

Parameters

  device | is a previously open/started terminal device.
  value | is number to print.
  digits | is number of hexadecimal characters to print.

int writeLine | ( | text_t * | device,
|  | char * | str
| ) |  |

Send a string + new line on the transmit device.

Parameters

  device | is a previously open/started terminal device.
  str | is the null terminated string to send.

int writeStr | ( | text_t * | device,
|  | char * | str
| ) |  |

Send a string on the transmit device.

Parameters

  device | is a previously open/started terminal device.
  str | is the null terminated string to send.

int writeStrDigits | ( | text_t * | device,
|  | char * | str,
|  | int | width
| ) |  |

Send a string on the transmit device.

Parameters

  device | is a previously open/started terminal device.
  str | is the null terminated string to send.
  width | is number of characters to print padded by spaces.