WaspUSB Class Reference

WaspUSB Class. More...

#include <WaspUSB.h>


Public Member Functions

 WaspUSB ()
 class constructor
void begin ()
 It opens UART to be able to communicate with the FTDI conversor.
void close ()
 It closes the previously opened UART.
uint8_t available ()
 It checks if there is available data waiting to be read.
int read ()
 It reads a byte from the UART.
void flush ()
 It clears the UART buffer.
void print (char c)
 It prints a character.
void print (const char[])
 It prints a string.
void print (uint8_t b)
 It prints an unsigned 8-bit integer.
void print (int n)
 It prints an integer.
void print (unsigned int n)
 It prints an unsigned integer.
void print (long n)
 It prints a long integer.
void print (unsigned long n)
 It prints an unsigned long integer.
void print (long n, int base)
 It prints a long number in the specified base.
void print (double n)
 It prints a double number.
void print (uint64_t n)
 It prints a 64-bit number.
void println ()
 It prints an EOL and a carriage return.
void println (char c)
 It prints a character adding an EOL and a carriage return.
void println (const char[])
 It prints a string adding an EOL and a carriage return.
void println (uint8_t b)
 It prints an unsigned 8-bit integer adding an EOL and a carriage return.
void println (int n)
 It prints an integer adding an EOL and a carriage return.
void println (long n)
 It prints a long integer adding an EOL and a carriage return.
void println (unsigned long n)
 It prints an unsigned long integer adding an EOL and a carriage return.
void println (long n, int base)
 It prints a long number in the specified base adding an EOL and a carriage return.
void println (double n)
 It prints a double number adding an EOL and a carriage return.
void println (uint64_t n)
 It prints a 64-bit number adding an EOL and a carriage return.

Private Member Functions

void printNumber (unsigned long n, uint8_t base)
 It prints a number in the specified base.
void printFloat (double number, uint8_t digits)
 It prints a 'float' number.

Private Attributes

uint8_t _uart
 Variable : specifies the UART where the USB is connected.


Detailed Description

WaspUSB Class.

WaspUSB Class defines all the variables and functions used for managing the USB interface

Definition at line 87 of file WaspUSB.h.


Constructor & Destructor Documentation

WaspUSB::WaspUSB (  ) 

class constructor

It initializes some variables

Parameters:
void 
Returns:
void

Definition at line 31 of file WaspUSB.cpp.

References _uart.

00032 {
00033     _uart = 0;
00034 }


Member Function Documentation

void WaspUSB::printNumber ( unsigned long  n,
uint8_t  base 
) [private]

It prints a number in the specified base.

Parameters:
unsigned long n : the number to print
uint8_t base : the base for printing the number
Returns:
void

Definition at line 184 of file WaspUSB.cpp.

References _uart, and printIntegerInBase().

Referenced by print().

00185 {
00186   printIntegerInBase(n, base,  _uart);
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspUSB::printFloat ( double  number,
uint8_t  digits 
) [private]

It prints a 'float' number.

Parameters:
double number : the number to print
uint8_t digits : the number of non-integer part digits
Returns:
void

Definition at line 189 of file WaspUSB.cpp.

References print().

Referenced by print().

00190 {
00191   // Handle negative numbers
00192   if (number < 0.0)
00193   {
00194      print('-');
00195      number = -number;
00196   }
00197 
00198   // Round correctly so that print(1.999, 2) prints as "2.00"
00199   double rounding = 0.5;
00200   for (uint8_t i=0; i<digits; ++i)
00201     rounding /= 10.0;
00202   
00203   number += rounding;
00204 
00205   // Extract the integer part of the number and print it
00206   unsigned long int_part = (unsigned long)number;
00207   double remainder = number - (double)int_part;
00208   print(int_part);
00209 
00210   // Print the decimal point, but only if there are digits beyond
00211   if (digits > 0)
00212     print("."); 
00213 
00214   // Extract digits from the remainder one at a time
00215   while (digits-- > 0)
00216   {
00217     remainder *= 10.0;
00218     int toPrint = int(remainder);
00219     print(toPrint);
00220     remainder -= toPrint; 
00221   }
00222 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspUSB::begin ( void   ) 

It opens UART to be able to communicate with the FTDI conversor.

It gets the baud rate from 'USB_RATE'

Parameters:
void 
Returns:
void

Definition at line 38 of file WaspUSB.cpp.

References _uart, beginSerial(), and USB_RATE.

00039 {
00040   beginSerial(USB_RATE, _uart);
00041 }

Here is the call graph for this function:

void WaspUSB::close ( void   ) 

It closes the previously opened UART.

Parameters:
void 
Returns:
void

Definition at line 43 of file WaspUSB.cpp.

References _uart, and closeSerial().

00044 {
00045   closeSerial(_uart);
00046 }

Here is the call graph for this function:

uint8_t WaspUSB::available (  ) 

It checks if there is available data waiting to be read.

Parameters:
void 
Returns:
'1' if there is available data, '0' otherwise

Definition at line 48 of file WaspUSB.cpp.

References _uart, and serialAvailable().

00049 {
00050   return serialAvailable( _uart);
00051 }

Here is the call graph for this function:

int WaspUSB::read (  ) 

It reads a byte from the UART.

Parameters:
void 
Returns:
the read byte or '-1' if no data is available

Definition at line 53 of file WaspUSB.cpp.

References _uart, and serialRead().

00054 {
00055   return serialRead( _uart);
00056 }

Here is the call graph for this function:

void WaspUSB::flush (  ) 

It clears the UART buffer.

Parameters:
void 
Returns:
void

Definition at line 58 of file WaspUSB.cpp.

References _uart, and serialFlush().

00059 {
00060   serialFlush( _uart);
00061 }

Here is the call graph for this function:

void WaspUSB::print ( char  c  ) 

It prints a character.

Parameters:
char c : the character to print
Returns:
void

Definition at line 63 of file WaspUSB.cpp.

References _uart, and printByte().

Referenced by print(), printFloat(), and println().

00064 {
00065   printByte(c,  _uart);
00066 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspUSB::print ( const char  c[]  ) 

It prints a string.

Parameters:
const char[] c : the string to print
Returns:
void

Definition at line 68 of file WaspUSB.cpp.

References _uart, and printString().

00069 {
00070   printString(c,  _uart);
00071 }

Here is the call graph for this function:

void WaspUSB::print ( uint8_t  b  ) 

It prints an unsigned 8-bit integer.

Parameters:
uint8_t b : the number to print
Returns:
void

Definition at line 73 of file WaspUSB.cpp.

References _uart, and printByte().

00074 {
00075   printByte(b,  _uart);
00076 }

Here is the call graph for this function:

void WaspUSB::print ( int  n  ) 

It prints an integer.

Parameters:
int n : the number to print
Returns:
void

Definition at line 78 of file WaspUSB.cpp.

References print().

00079 {
00080   print((long) n);
00081 }

Here is the call graph for this function:

void WaspUSB::print ( unsigned int  n  ) 

It prints an unsigned integer.

Parameters:
unsigned int n : the number to print
Returns:
void

Definition at line 83 of file WaspUSB.cpp.

References print().

00084 {
00085   print((unsigned long) n);
00086 }

Here is the call graph for this function:

void WaspUSB::print ( long  n  ) 

It prints a long integer.

Parameters:
long n : the number to print
Returns:
void

Definition at line 88 of file WaspUSB.cpp.

References print(), and printNumber().

00089 {
00090   if (n < 0) {
00091     print('-');
00092     n = -n;
00093   }
00094   printNumber(n, 10);
00095 }

Here is the call graph for this function:

void WaspUSB::print ( unsigned long  n  ) 

It prints an unsigned long integer.

Parameters:
unsigned long n : the number to print
Returns:
void

Definition at line 97 of file WaspUSB.cpp.

References printNumber().

00098 {
00099   printNumber(n, 10);
00100 }

Here is the call graph for this function:

void WaspUSB::print ( long  n,
int  base 
)

It prints a long number in the specified base.

Parameters:
long n : the number to print
int base : the base for printing the number
Returns:
void

Definition at line 102 of file WaspUSB.cpp.

References print(), and printNumber().

00103 {
00104   if (base == 0)
00105     print((char) n);
00106   else if (base == 10)
00107     print(n);
00108   else
00109     printNumber(n, base);
00110 }

Here is the call graph for this function:

void WaspUSB::print ( double  n  ) 

It prints a double number.

Parameters:
double n : the number to print
Returns:
void

Definition at line 112 of file WaspUSB.cpp.

References printFloat().

00113 {
00114   printFloat(n, 10);
00115 }

Here is the call graph for this function:

void WaspUSB::print ( uint64_t  n  ) 

It prints a 64-bit number.

Parameters:
uint64_t n : the number to print
Returns:
void

Definition at line 117 of file WaspUSB.cpp.

References printInteger().

00118 {
00119         printInteger(n,0);
00120 }

Here is the call graph for this function:

void WaspUSB::println (  ) 

It prints an EOL and a carriage return.

Parameters:
void 
Returns:
void

Definition at line 122 of file WaspUSB.cpp.

References print().

Referenced by println().

00123 {
00124   print('\r');
00125   print('\n');  
00126 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspUSB::println ( char  c  ) 

It prints a character adding an EOL and a carriage return.

Parameters:
char c : the character to print
Returns:
void

Definition at line 128 of file WaspUSB.cpp.

References print(), and println().

00129 {
00130   print(c);
00131   println();  
00132 }

Here is the call graph for this function:

void WaspUSB::println ( const char  c[]  ) 

It prints a string adding an EOL and a carriage return.

Parameters:
const char[] c : the string to print
Returns:
void

Definition at line 134 of file WaspUSB.cpp.

References print(), and println().

00135 {
00136   print(c);
00137   println();
00138 }

Here is the call graph for this function:

void WaspUSB::println ( uint8_t  b  ) 

It prints an unsigned 8-bit integer adding an EOL and a carriage return.

Parameters:
uint8_t b : the number to print
Returns:
void

Definition at line 140 of file WaspUSB.cpp.

References print(), and println().

00141 {
00142   print(b);
00143   println();
00144 }

Here is the call graph for this function:

void WaspUSB::println ( int  n  ) 

It prints an integer adding an EOL and a carriage return.

Parameters:
int n : the number to print
Returns:
void

Definition at line 146 of file WaspUSB.cpp.

References print(), and println().

00147 {
00148   print(n);
00149   println();
00150 }

Here is the call graph for this function:

void WaspUSB::println ( long  n  ) 

It prints a long integer adding an EOL and a carriage return.

Parameters:
long n : the number to print
Returns:
void

Definition at line 152 of file WaspUSB.cpp.

References print(), and println().

00153 {
00154   print(n);
00155   println();  
00156 }

Here is the call graph for this function:

void WaspUSB::println ( unsigned long  n  ) 

It prints an unsigned long integer adding an EOL and a carriage return.

Parameters:
unsigned long n : the number to print
Returns:
void

Definition at line 158 of file WaspUSB.cpp.

References print(), and println().

00159 {
00160   print(n);
00161   println();  
00162 }

Here is the call graph for this function:

void WaspUSB::println ( long  n,
int  base 
)

It prints a long number in the specified base adding an EOL and a carriage return.

Parameters:
long n : the number to print
int base : the base for printing the number
Returns:
void

Definition at line 164 of file WaspUSB.cpp.

References print(), and println().

00165 {
00166   print(n, base);
00167   println();
00168 }

Here is the call graph for this function:

void WaspUSB::println ( double  n  ) 

It prints a double number adding an EOL and a carriage return.

Parameters:
double n : the number to print
Returns:
void

Definition at line 170 of file WaspUSB.cpp.

References print(), and println().

00171 {
00172   print(n);
00173   println();
00174 }

Here is the call graph for this function:

void WaspUSB::println ( uint64_t  n  ) 

It prints a 64-bit number adding an EOL and a carriage return.

Parameters:
uint64_t n : the number to print
Returns:
void

Definition at line 176 of file WaspUSB.cpp.

References printInteger(), and println().

00177 {
00178         printInteger(n,0);
00179         println();
00180 }

Here is the call graph for this function:


Field Documentation

uint8_t WaspUSB::_uart [private]

Variable : specifies the UART where the USB is connected.

Definition at line 94 of file WaspUSB.h.

Referenced by available(), begin(), close(), flush(), print(), printNumber(), read(), and WaspUSB().


The documentation for this class was generated from the following files:

Generated on Tue Jul 20 09:31:04 2010 for WaspmoteAPI by  doxygen 1.5.6