#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. | |
WaspUSB Class defines all the variables and functions used for managing the USB interface
Definition at line 87 of file WaspUSB.h.
| WaspUSB::WaspUSB | ( | ) |
class constructor
It initializes some variables
| void |
Definition at line 31 of file WaspUSB.cpp.
References _uart.
00032 { 00033 _uart = 0; 00034 }
| void WaspUSB::printNumber | ( | unsigned long | n, | |
| uint8_t | base | |||
| ) | [private] |
It prints a number in the specified base.
| unsigned | long n : the number to print | |
| uint8_t | base : the base for printing the number |
Definition at line 184 of file WaspUSB.cpp.
References _uart, and printIntegerInBase().
Referenced by print().
00185 { 00186 printIntegerInBase(n, base, _uart); 00187 }


| void WaspUSB::printFloat | ( | double | number, | |
| uint8_t | digits | |||
| ) | [private] |
It prints a 'float' number.
| double | number : the number to print | |
| uint8_t | digits : the number of non-integer part digits |
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 }


| void WaspUSB::begin | ( | void | ) |
It opens UART to be able to communicate with the FTDI conversor.
It gets the baud rate from 'USB_RATE'
| void |
Definition at line 38 of file WaspUSB.cpp.
References _uart, beginSerial(), and USB_RATE.
00039 { 00040 beginSerial(USB_RATE, _uart); 00041 }

| void WaspUSB::close | ( | void | ) |
It closes the previously opened UART.
| void |
Definition at line 43 of file WaspUSB.cpp.
References _uart, and closeSerial().
00044 { 00045 closeSerial(_uart); 00046 }

| uint8_t WaspUSB::available | ( | ) |
It checks if there is available data waiting to be read.
| void |
Definition at line 48 of file WaspUSB.cpp.
References _uart, and serialAvailable().
00049 { 00050 return serialAvailable( _uart); 00051 }

| int WaspUSB::read | ( | ) |
It reads a byte from the UART.
| void |
Definition at line 53 of file WaspUSB.cpp.
References _uart, and serialRead().
00054 { 00055 return serialRead( _uart); 00056 }

| void WaspUSB::flush | ( | ) |
It clears the UART buffer.
| void |
Definition at line 58 of file WaspUSB.cpp.
References _uart, and serialFlush().
00059 { 00060 serialFlush( _uart); 00061 }

| void WaspUSB::print | ( | char | c | ) |
It prints a character.
| char | c : the character to print |
Definition at line 63 of file WaspUSB.cpp.
References _uart, and printByte().
Referenced by print(), printFloat(), and println().


| void WaspUSB::print | ( | const char | c[] | ) |
It prints a string.
| const | char[] c : the string to print |
Definition at line 68 of file WaspUSB.cpp.
References _uart, and printString().
00069 { 00070 printString(c, _uart); 00071 }

| void WaspUSB::print | ( | uint8_t | b | ) |
It prints an unsigned 8-bit integer.
| uint8_t | b : the number to print |
Definition at line 73 of file WaspUSB.cpp.
References _uart, and printByte().

| void WaspUSB::print | ( | int | n | ) |
It prints an integer.
| int | n : the number to print |
Definition at line 78 of file WaspUSB.cpp.
References print().
00079 { 00080 print((long) n); 00081 }

| void WaspUSB::print | ( | unsigned int | n | ) |
It prints an unsigned integer.
| unsigned | int n : the number to print |
Definition at line 83 of file WaspUSB.cpp.
References print().
00084 { 00085 print((unsigned long) n); 00086 }

| void WaspUSB::print | ( | long | n | ) |
It prints a long integer.
| long | n : the number to print |
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 }

| void WaspUSB::print | ( | unsigned long | n | ) |
It prints an unsigned long integer.
| unsigned | long n : the number to print |
Definition at line 97 of file WaspUSB.cpp.
References printNumber().
00098 { 00099 printNumber(n, 10); 00100 }

| void WaspUSB::print | ( | long | n, | |
| int | base | |||
| ) |
It prints a long number in the specified base.
| long | n : the number to print | |
| int | base : the base for printing the number |
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 }

| void WaspUSB::print | ( | double | n | ) |
It prints a double number.
| double | n : the number to print |
Definition at line 112 of file WaspUSB.cpp.
References printFloat().
00113 { 00114 printFloat(n, 10); 00115 }

| void WaspUSB::print | ( | uint64_t | n | ) |
It prints a 64-bit number.
| uint64_t | n : the number to print |
Definition at line 117 of file WaspUSB.cpp.
References printInteger().
00118 { 00119 printInteger(n,0); 00120 }

| void WaspUSB::println | ( | ) |
| void WaspUSB::println | ( | char | c | ) |
| void WaspUSB::println | ( | const char | c[] | ) |
| void WaspUSB::println | ( | uint8_t | b | ) |
| void WaspUSB::println | ( | int | n | ) |
| void WaspUSB::println | ( | long | n | ) |
| void WaspUSB::println | ( | unsigned long | n | ) |
It prints an unsigned long integer adding an EOL and a carriage return.
| unsigned | long n : the number to print |
Definition at line 158 of file WaspUSB.cpp.
References print(), and println().

| void WaspUSB::println | ( | long | n, | |
| int | base | |||
| ) |
It prints a long number in the specified base adding an EOL and a carriage return.
| long | n : the number to print | |
| int | base : the base for printing the number |
Definition at line 164 of file WaspUSB.cpp.
References print(), and println().

| void WaspUSB::println | ( | double | n | ) |
| void WaspUSB::println | ( | uint64_t | n | ) |
It prints a 64-bit number adding an EOL and a carriage return.
| uint64_t | n : the number to print |
Definition at line 176 of file WaspUSB.cpp.
References printInteger(), and println().
00177 { 00178 printInteger(n,0); 00179 println(); 00180 }

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().
1.5.6