Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers message.cpp Source File

message.cpp

00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
00002 
00003 This program is free software; you can redistribute it and/or modify
00004 it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation; either version 2 of the License, or
00006 (at your option) any later version.
00007 
00008 This program is distributed in the hope that it will be useful,
00009 but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License
00014 along with this program; if not, write to the Free Software
00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 
00017 Contact information
00018 -------------------
00019 
00020 Circuits At Home, LTD
00021 Web      :  http://www.circuitsathome.com
00022 e-mail   :  support@circuitsathome.com
00023  */
00024 
00025 #include "Usb.h"
00026 // 0x80 is the default (i.e. trace) to turn off set this global to something lower.
00027 // this allows for 126 other debugging levels.
00028 // TO-DO: Allow assignment to a different serial port by software
00029 int UsbDEBUGlvl = 0x80;
00030 
00031 void E_Notifyc(char c, int lvl) {
00032         if(UsbDEBUGlvl < lvl) return;
00033 #if defined(ARDUINO) && ARDUINO >=100
00034         USB_HOST_SERIAL.print(c);
00035 #else
00036         printf("%c", c);
00037 #endif
00038         //USB_HOST_SERIAL.flush();
00039 }
00040 
00041 void E_Notify(char const * msg, int lvl) {
00042         if(UsbDEBUGlvl < lvl) return;
00043         if(!msg) return;
00044         char c;
00045 
00046         while((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl);
00047 }
00048 
00049 void E_NotifyStr(char const * msg, int lvl) {
00050         if(UsbDEBUGlvl < lvl) return;
00051         if(!msg) return;
00052         char c;
00053 
00054         while((c = *msg++)) E_Notifyc(c, lvl);
00055 }
00056 
00057 void E_Notify(uint8_t b, int lvl) {
00058         if(UsbDEBUGlvl < lvl) return;
00059 #if defined(ARDUINO) && ARDUINO >=100
00060         USB_HOST_SERIAL.print(b);
00061 #else
00062         printf("%d", b);
00063 #endif
00064         //USB_HOST_SERIAL.flush();
00065 }
00066 
00067 void E_Notify(double d, int lvl) {
00068         if(UsbDEBUGlvl < lvl) return;
00069         printf("%d", d);
00070         //USB_HOST_SERIAL.flush();
00071 }
00072 
00073 #ifdef DEBUG_USB_HOST
00074 
00075 void NotifyFailGetDevDescr(void) {
00076         Notify(PSTR("\r\ngetDevDescr "), 0x80);
00077 }
00078 
00079 void NotifyFailSetDevTblEntry(void) {
00080         Notify(PSTR("\r\nsetDevTblEn "), 0x80);
00081 }
00082 
00083 void NotifyFailGetConfDescr(void) {
00084         Notify(PSTR("\r\ngetConf "), 0x80);
00085 }
00086 
00087 void NotifyFailSetConfDescr(void) {
00088         Notify(PSTR("\r\nsetConf "), 0x80);
00089 }
00090 
00091 void NotifyFailGetDevDescr(uint8_t reason) {
00092         NotifyFailGetDevDescr();
00093         NotifyFail(reason);
00094 }
00095 
00096 void NotifyFailSetDevTblEntry(uint8_t reason) {
00097         NotifyFailSetDevTblEntry();
00098         NotifyFail(reason);
00099 
00100 }
00101 
00102 void NotifyFailGetConfDescr(uint8_t reason) {
00103         NotifyFailGetConfDescr();
00104         NotifyFail(reason);
00105 }
00106 
00107 void NotifyFailSetConfDescr(uint8_t reason) {
00108         NotifyFailSetConfDescr();
00109         NotifyFail(reason);
00110 }
00111 
00112 void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
00113         Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
00114         D_PrintHex<uint16_t > (VID, 0x80);
00115         Notify(PSTR(" PID: "), 0x80);
00116         D_PrintHex<uint16_t > (PID, 0x80);
00117 }
00118 
00119 void NotifyFail(uint8_t rcode) {
00120         D_PrintHex<uint8_t > (rcode, 0x80);
00121         Notify(PSTR("\r\n"), 0x80);
00122 }
00123 #endif