USB Host Shield 2.0
message.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 
17 Contact information
18 -------------------
19 
20 Circuits At Home, LTD
21 Web : http://www.circuitsathome.com
22 e-mail : support@circuitsathome.com
23  */
24 
25 #include "Usb.h"
26 // 0x80 is the default (i.e. trace) to turn off set this global to something lower.
27 // this allows for 126 other debugging levels.
28 // TO-DO: Allow assignment to a different serial port by software
29 int UsbDEBUGlvl = 0x80;
30 
31 void E_Notifyc(char c, int lvl) {
32  if(UsbDEBUGlvl < lvl) return;
33 #if defined(ARDUINO) && ARDUINO >=100
34  USB_HOST_SERIAL.print(c);
35 #else
36  USB_HOST_SERIAL.print(c, BYTE);
37 #endif
38  //USB_HOST_SERIAL.flush();
39 }
40 
41 void E_Notify(char const * msg, int lvl) {
42  if(UsbDEBUGlvl < lvl) return;
43  if(!msg) return;
44  char c;
45 
46  while((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl);
47 }
48 
49 void E_NotifyStr(char const * msg, int lvl) {
50  if(UsbDEBUGlvl < lvl) return;
51  if(!msg) return;
52  char c;
53 
54  while((c = *msg++)) E_Notifyc(c, lvl);
55 }
56 
57 void E_Notify(uint8_t b, int lvl) {
58  if(UsbDEBUGlvl < lvl) return;
59 #if defined(ARDUINO) && ARDUINO >=100
60  USB_HOST_SERIAL.print(b);
61 #else
62  USB_HOST_SERIAL.print(b, DEC);
63 #endif
64  //USB_HOST_SERIAL.flush();
65 }
66 
67 void E_Notify(double d, int lvl) {
68  if(UsbDEBUGlvl < lvl) return;
69  USB_HOST_SERIAL.print(d);
70  //USB_HOST_SERIAL.flush();
71 }
72 
73 #ifdef DEBUG_USB_HOST
74 
75 void NotifyFailGetDevDescr(void) {
76  Notify(PSTR("\r\ngetDevDescr "), 0x80);
77 }
78 
79 void NotifyFailSetDevTblEntry(void) {
80  Notify(PSTR("\r\nsetDevTblEn "), 0x80);
81 }
82 
83 void NotifyFailGetConfDescr(void) {
84  Notify(PSTR("\r\ngetConf "), 0x80);
85 }
86 
87 void NotifyFailSetConfDescr(void) {
88  Notify(PSTR("\r\nsetConf "), 0x80);
89 }
90 
91 void NotifyFailGetDevDescr(uint8_t reason) {
93  NotifyFail(reason);
94 }
95 
96 void NotifyFailSetDevTblEntry(uint8_t reason) {
98  NotifyFail(reason);
99 
100 }
101 
102 void NotifyFailGetConfDescr(uint8_t reason) {
104  NotifyFail(reason);
105 }
106 
107 void NotifyFailSetConfDescr(uint8_t reason) {
109  NotifyFail(reason);
110 }
111 
112 void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
113  Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
114  D_PrintHex<uint16_t > (VID, 0x80);
115  Notify(PSTR(" PID: "), 0x80);
116  D_PrintHex<uint16_t > (PID, 0x80);
117 }
118 
119 void NotifyFail(uint8_t rcode) {
120  D_PrintHex<uint8_t > (rcode, 0x80);
121  Notify(PSTR("\r\n"), 0x80);
122 }
123 #endif
int UsbDEBUGlvl
Definition: message.cpp:29
void E_NotifyStr(char const *msg, int lvl)
Definition: message.cpp:49
void E_Notify(char const *msg, int lvl)
Definition: message.cpp:41
void E_Notifyc(char c, int lvl)
Definition: message.cpp:31
#define NotifyFailSetConfDescr(...)
Definition: message.h:60
#define NotifyFailUnknownDevice(...)
Definition: message.h:61
#define NotifyFail(...)
Definition: message.h:62
#define Notify(...)
Definition: message.h:51
#define NotifyFailGetConfDescr(...)
Definition: message.h:59
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:58
#define NotifyFailGetDevDescr(...)
Definition: message.h:57
#define USB_HOST_SERIAL
Definition: settings.h:49
#define pgm_read_byte(addr)
#define PSTR(str)