00001 /*! \file WaspUSB.h 00002 \brief Library for managing the USB interface 00003 Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L. 00004 http://www.libelium.com 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 2.1 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 Version: 0.1 00020 00021 Design: David Gascón 00022 00023 Implementation: David Cuartielles, Alberto Bielsa 00024 00025 */ 00026 00027 /*! \def WaspUSB_h 00028 \brief The library flag 00029 00030 */ 00031 #ifndef WaspUSB_h 00032 #define WaspUSB_h 00033 00034 00035 /****************************************************************************** 00036 * Includes 00037 ******************************************************************************/ 00038 00039 #include <inttypes.h> 00040 00041 00042 /****************************************************************************** 00043 * Definitions & Declarations 00044 ******************************************************************************/ 00045 00046 /*! \def DEC 00047 \brief The base to print numbers. Decimal Base in this case 00048 00049 */ 00050 /*! \def HEX 00051 \brief The base to print numbers. Hexadecimal Base in this case 00052 00053 */ 00054 /*! \def OCT 00055 \brief The base to print numbers. Octal Base in this case 00056 00057 */ 00058 /*! \def BIN 00059 \brief The base to print numbers. Binary Base in this case 00060 00061 */ 00062 /*! \def BYTE 00063 \brief The base to print numbers. Byte Base in this case 00064 00065 */ 00066 #define DEC 10 00067 #define HEX 16 00068 #define OCT 8 00069 #define BIN 2 00070 #define BYTE 0 00071 00072 /*! \def USB_RATE 00073 \brief USB Baud Rate 00074 00075 */ 00076 #define USB_RATE 38400 00077 00078 00079 /****************************************************************************** 00080 * Class 00081 ******************************************************************************/ 00082 00083 //! WaspUSB Class 00084 /*! 00085 WaspUSB Class defines all the variables and functions used for managing the USB interface 00086 */ 00087 class WaspUSB 00088 { 00089 private: 00090 00091 //! Variable : specifies the UART where the USB is connected 00092 /*! 00093 */ 00094 uint8_t _uart; 00095 00096 //! It prints a number in the specified base 00097 /*! 00098 \param unsigned long n : the number to print 00099 \param uint8_t base : the base for printing the number 00100 \return void 00101 */ 00102 void printNumber(unsigned long n, uint8_t base); 00103 00104 //! It prints a 'float' number 00105 /*! 00106 \param double number : the number to print 00107 \param uint8_t digits : the number of non-integer part digits 00108 \return void 00109 */ 00110 void printFloat(double number, uint8_t digits); 00111 public: 00112 00113 //! class constructor 00114 /*! 00115 It initializes some variables 00116 \param void 00117 \return void 00118 */ 00119 WaspUSB(); 00120 00121 //! It opens UART to be able to communicate with the FTDI conversor 00122 /*! 00123 It gets the baud rate from 'USB_RATE' 00124 \param void 00125 \return void 00126 */ 00127 void begin(); 00128 00129 //! It closes the previously opened UART 00130 /*! 00131 \param void 00132 \return void 00133 */ 00134 void close(); 00135 00136 //! It checks if there is available data waiting to be read 00137 /*! 00138 \param void 00139 \return '1' if there is available data, '0' otherwise 00140 */ 00141 uint8_t available(); 00142 00143 //! It reads a byte from the UART 00144 /*! 00145 \param void 00146 \return the read byte or '-1' if no data is available 00147 */ 00148 int read(); 00149 00150 //! It clears the UART buffer 00151 /*! 00152 \param void 00153 \return void 00154 */ 00155 void flush(); 00156 00157 //! It prints a character 00158 /*! 00159 \param char c : the character to print 00160 \return void 00161 */ 00162 void print(char c); 00163 00164 //! It prints a string 00165 /*! 00166 \param const char[] c : the string to print 00167 \return void 00168 */ 00169 void print(const char[]); 00170 00171 //! It prints an unsigned 8-bit integer 00172 /*! 00173 \param uint8_t b : the number to print 00174 \return void 00175 */ 00176 void print(uint8_t b); 00177 00178 //! It prints an integer 00179 /*! 00180 \param int n : the number to print 00181 \return void 00182 */ 00183 void print(int n); 00184 00185 //! It prints an unsigned integer 00186 /*! 00187 \param unsigned int n : the number to print 00188 \return void 00189 */ 00190 void print(unsigned int n); 00191 00192 //! It prints a long integer 00193 /*! 00194 \param long n : the number to print 00195 \return void 00196 */ 00197 void print(long n); 00198 00199 //! It prints an unsigned long integer 00200 /*! 00201 \param unsigned long n : the number to print 00202 \return void 00203 */ 00204 void print(unsigned long n); 00205 00206 //! It prints a long number in the specified base 00207 /*! 00208 \param long n : the number to print 00209 \param int base : the base for printing the number 00210 \return void 00211 */ 00212 void print(long n, int base); 00213 00214 //! It prints a double number 00215 /*! 00216 \param double n : the number to print 00217 \return void 00218 */ 00219 void print(double n); 00220 00221 //! It prints a 64-bit number 00222 /*! 00223 \param uint64_t n : the number to print 00224 \return void 00225 */ 00226 void print(uint64_t n); 00227 00228 //! It prints an EOL and a carriage return 00229 /*! 00230 \param void 00231 \return void 00232 */ 00233 void println(); 00234 00235 //! It prints a character adding an EOL and a carriage return 00236 /*! 00237 \param char c : the character to print 00238 \return void 00239 */ 00240 void println(char c); 00241 00242 //! It prints a string adding an EOL and a carriage return 00243 /*! 00244 \param const char[] c : the string to print 00245 \return void 00246 */ 00247 void println(const char[]); 00248 00249 //! It prints an unsigned 8-bit integer adding an EOL and a carriage return 00250 /*! 00251 \param uint8_t b : the number to print 00252 \return void 00253 */ 00254 void println(uint8_t b); 00255 00256 //! It prints an integer adding an EOL and a carriage return 00257 /*! 00258 \param int n : the number to print 00259 \return void 00260 */ 00261 void println(int n); 00262 00263 //! It prints a long integer adding an EOL and a carriage return 00264 /*! 00265 \param long n : the number to print 00266 \return void 00267 */ 00268 void println(long n); 00269 00270 //! It prints an unsigned long integer adding an EOL and a carriage return 00271 /*! 00272 \param unsigned long n : the number to print 00273 \return void 00274 */ 00275 void println(unsigned long n); 00276 00277 //! It prints a long number in the specified base adding an EOL and a carriage return 00278 /*! 00279 \param long n : the number to print 00280 \param int base : the base for printing the number 00281 \return void 00282 */ 00283 void println(long n, int base); 00284 00285 //! It prints a double number adding an EOL and a carriage return 00286 /*! 00287 \param double n : the number to print 00288 \return void 00289 */ 00290 void println(double n); 00291 00292 //! It prints a 64-bit number adding an EOL and a carriage return 00293 /*! 00294 \param uint64_t n : the number to print 00295 \return void 00296 */ 00297 void println(uint64_t n); 00298 }; 00299 00300 extern WaspUSB USB; 00301 00302 #endif 00303
1.5.6